| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 1 | #include <ctype.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 4 | #include <string.h> |
| Juan Cespedes | 2c4a8cb | 1998-03-11 23:33:18 +0100 | [diff] [blame] | 5 | #include <limits.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 6 | |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 7 | #include "common.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 8 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 9 | static int display_char(int what); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 10 | static int display_string(enum tof type, Process *proc, |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 11 | void* addr, size_t maxlen); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 12 | static int display_value(enum tof type, Process *proc, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 13 | long value, arg_type_info *info, |
| 14 | void *st, arg_type_info* st_info); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 15 | static int display_unknown(enum tof type, Process *proc, long value); |
| 16 | static int display_format(enum tof type, Process *proc, int arg_num); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 17 | |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame^] | 18 | static size_t string_maxlength = INT_MAX; |
| 19 | static size_t array_maxlength = INT_MAX; |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 20 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 21 | static long |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 22 | get_length(enum tof type, Process *proc, int len_spec, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 23 | void *st, arg_type_info* st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 24 | long len; |
| 25 | arg_type_info info; |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 26 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 27 | if (len_spec > 0) |
| 28 | return len_spec; |
| 29 | if (type == LT_TOF_STRUCT) { |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 30 | umovelong (proc, st + st_info->u.struct_info.offset[-len_spec-1], |
| 31 | &len, st_info->u.struct_info.fields[-len_spec-1]); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 32 | return len; |
| 33 | } |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 34 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 35 | info.type = ARGTYPE_INT; |
| 36 | return gimme_arg(type, proc, -len_spec-1, &info); |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 39 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 40 | display_ptrto(enum tof type, Process *proc, long item, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 41 | arg_type_info * info, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 42 | void *st, arg_type_info* st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 43 | arg_type_info temp; |
| 44 | temp.type = ARGTYPE_POINTER; |
| 45 | temp.u.ptr_info.info = info; |
| 46 | return display_value(type, proc, item, &temp, st, st_info); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * addr - A pointer to the first element of the array |
| 51 | * |
| 52 | * The function name is used to indicate that we're not actually |
| 53 | * looking at an 'array', which is a contiguous region of memory |
| 54 | * containing a sequence of elements of some type; instead, we have a |
| 55 | * pointer to that region of memory. |
| 56 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 57 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 58 | display_arrayptr(enum tof type, Process *proc, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 59 | void *addr, arg_type_info * info, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 60 | void *st, arg_type_info* st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 61 | int len = 0; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame^] | 62 | size_t i; |
| 63 | size_t array_len; |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 64 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 65 | if (addr == NULL) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 66 | return fprintf(options.output, "NULL"); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 67 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 68 | array_len = get_length(type, proc, info->u.array_info.len_spec, |
| 69 | st, st_info); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 70 | len += fprintf(options.output, "[ "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 71 | for (i = 0; i < options.arraylen && i < array_maxlength && i < array_len; i++) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 72 | arg_type_info *elt_type = info->u.array_info.elt_type; |
| 73 | size_t elt_size = info->u.array_info.elt_size; |
| 74 | if (i != 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 75 | len += fprintf(options.output, ", "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 76 | if (options.debug) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 77 | len += fprintf(options.output, "%p=", addr); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 78 | len += |
| 79 | display_ptrto(type, proc, (long) addr, elt_type, st, st_info); |
| 80 | addr += elt_size; |
| 81 | } |
| 82 | if (i < array_len) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 83 | len += fprintf(options.output, "..."); |
| 84 | len += fprintf(options.output, " ]"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 85 | return len; |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 86 | } |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 87 | |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 88 | /* addr - A pointer to the beginning of the memory region occupied by |
| 89 | * the struct (aka a pointer to the struct) |
| 90 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 91 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 92 | display_structptr(enum tof type, Process *proc, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 93 | void *addr, arg_type_info * info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 94 | int i; |
| 95 | arg_type_info *field; |
| 96 | int len = 0; |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 97 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 98 | if (addr == NULL) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 99 | return fprintf(options.output, "NULL"); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 100 | |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 101 | len += fprintf(options.output, "{ "); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 102 | for (i = 0; (field = info->u.struct_info.fields[i]) != NULL; i++) { |
| 103 | if (i != 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 104 | len += fprintf(options.output, ", "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 105 | if (options.debug) |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 106 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 107 | fprintf(options.output, "%p=", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 108 | addr + info->u.struct_info.offset[i]); |
| 109 | len += |
| 110 | display_ptrto(LT_TOF_STRUCT, proc, |
| 111 | (long) addr + info->u.struct_info.offset[i], |
| 112 | field, addr, info); |
| 113 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 114 | len += fprintf(options.output, " }"); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 115 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 116 | return len; |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 119 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 120 | display_pointer(enum tof type, Process *proc, long value, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 121 | arg_type_info * info, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 122 | void *st, arg_type_info* st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 123 | long pointed_to; |
| 124 | arg_type_info *inner = info->u.ptr_info.info; |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 125 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 126 | if (inner->type == ARGTYPE_ARRAY) { |
| 127 | return display_arrayptr(type, proc, (void*) value, inner, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 128 | st, st_info); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 129 | } else if (inner->type == ARGTYPE_STRUCT) { |
| 130 | return display_structptr(type, proc, (void *) value, inner); |
| 131 | } else { |
| 132 | if (value == 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 133 | return fprintf(options.output, "NULL"); |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 134 | else if (umovelong (proc, (void *) value, &pointed_to, |
| 135 | info->u.ptr_info.info) < 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 136 | return fprintf(options.output, "?"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 137 | else |
| 138 | return display_value(type, proc, pointed_to, inner, |
| 139 | st, st_info); |
| 140 | } |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 143 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 144 | display_enum(enum tof type, Process *proc, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 145 | arg_type_info* info, long value) { |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame^] | 146 | size_t ii; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 147 | for (ii = 0; ii < info->u.enum_info.entries; ++ii) { |
| 148 | if (info->u.enum_info.values[ii] == value) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 149 | return fprintf(options.output, "%s", info->u.enum_info.keys[ii]); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 150 | } |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 151 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 152 | return display_unknown(type, proc, value); |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 155 | /* Args: |
| 156 | type - syscall or shared library function or memory |
| 157 | proc - information about the traced process |
| 158 | value - the value to display |
| 159 | info - the description of the type to display |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 160 | st - if the current value is a struct member, the address of the struct |
| 161 | st_info - type of the above struct |
| 162 | |
| 163 | Those last two parameters are used for structs containing arrays or |
| 164 | strings whose length is given by another structure element. |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 165 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 166 | int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 167 | display_value(enum tof type, Process *proc, |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 168 | long value, arg_type_info *info, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 169 | void *st, arg_type_info* st_info) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 170 | int tmp; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 171 | |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 172 | switch (info->type) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 173 | case ARGTYPE_VOID: |
| 174 | return 0; |
| 175 | case ARGTYPE_INT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 176 | return fprintf(options.output, "%d", (int) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 177 | case ARGTYPE_UINT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 178 | return fprintf(options.output, "%u", (unsigned) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 179 | case ARGTYPE_LONG: |
| 180 | if (proc->mask_32bit) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 181 | return fprintf(options.output, "%d", (int) value); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 182 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 183 | return fprintf(options.output, "%ld", value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 184 | case ARGTYPE_ULONG: |
| 185 | if (proc->mask_32bit) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 186 | return fprintf(options.output, "%u", (unsigned) value); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 187 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 188 | return fprintf(options.output, "%lu", (unsigned long) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 189 | case ARGTYPE_OCTAL: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 190 | return fprintf(options.output, "0%o", (unsigned) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 191 | case ARGTYPE_CHAR: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 192 | tmp = fprintf(options.output, "'"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 193 | tmp += display_char(value == -1 ? value : (char) value); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 194 | tmp += fprintf(options.output, "'"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 195 | return tmp; |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 196 | case ARGTYPE_SHORT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 197 | return fprintf(options.output, "%hd", (short) value); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 198 | case ARGTYPE_USHORT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 199 | return fprintf(options.output, "%hu", (unsigned short) value); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 200 | case ARGTYPE_FLOAT: { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 201 | union { long l; float f; double d; } cvt; |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 202 | cvt.l = value; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 203 | return fprintf(options.output, "%f", cvt.f); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 204 | } |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 205 | case ARGTYPE_DOUBLE: { |
| 206 | union { long l; float f; double d; } cvt; |
| 207 | cvt.l = value; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 208 | return fprintf(options.output, "%lf", cvt.d); |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 209 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 210 | case ARGTYPE_ADDR: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 211 | if (!value) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 212 | return fprintf(options.output, "NULL"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 213 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 214 | return fprintf(options.output, "0x%08lx", value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 215 | case ARGTYPE_FORMAT: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 216 | fprintf(stderr, "Should never encounter a format anywhere but at the top level (for now?)\n"); |
| 217 | exit(1); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 218 | case ARGTYPE_STRING: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 219 | return display_string(type, proc, (void*) value, |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 220 | string_maxlength); |
| 221 | case ARGTYPE_STRING_N: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 222 | return display_string(type, proc, (void*) value, |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 223 | get_length(type, proc, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 224 | info->u.string_n_info.size_spec, st, st_info)); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 225 | case ARGTYPE_ARRAY: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 226 | return fprintf(options.output, "<array without address>"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 227 | case ARGTYPE_ENUM: |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 228 | return display_enum(type, proc, info, value); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 229 | case ARGTYPE_STRUCT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 230 | return fprintf(options.output, "<struct without address>"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 231 | case ARGTYPE_POINTER: |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 232 | return display_pointer(type, proc, value, info, |
| 233 | st, st_info); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 234 | case ARGTYPE_UNKNOWN: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 235 | default: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 236 | return display_unknown(type, proc, value); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 237 | } |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 240 | int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 241 | display_arg(enum tof type, Process *proc, int arg_num, arg_type_info * info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 242 | long arg; |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 243 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 244 | if (info->type == ARGTYPE_VOID) { |
| 245 | return 0; |
| 246 | } else if (info->type == ARGTYPE_FORMAT) { |
| 247 | return display_format(type, proc, arg_num); |
| 248 | } else { |
| 249 | arg = gimme_arg(type, proc, arg_num, info); |
| 250 | return display_value(type, proc, arg, info, NULL, NULL); |
| 251 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 254 | static int |
| 255 | display_char(int what) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 256 | switch (what) { |
| 257 | case -1: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 258 | return fprintf(options.output, "EOF"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 259 | case '\r': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 260 | return fprintf(options.output, "\\r"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 261 | case '\n': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 262 | return fprintf(options.output, "\\n"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 263 | case '\t': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 264 | return fprintf(options.output, "\\t"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 265 | case '\b': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 266 | return fprintf(options.output, "\\b"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 267 | case '\\': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 268 | return fprintf(options.output, "\\\\"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 269 | default: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 270 | if (isprint(what)) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 271 | return fprintf(options.output, "%c", what); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 272 | } else { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 273 | return fprintf(options.output, "\\%03o", (unsigned char)what); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 274 | } |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| Juan Cespedes | 2c4a8cb | 1998-03-11 23:33:18 +0100 | [diff] [blame] | 278 | #define MIN(a,b) (((a)<(b)) ? (a) : (b)) |
| 279 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 280 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 281 | display_string(enum tof type, Process *proc, void *addr, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 282 | size_t maxlength) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 283 | unsigned char *str1; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame^] | 284 | size_t i; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 285 | int len = 0; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 286 | |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 287 | if (!addr) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 288 | return fprintf(options.output, "NULL"); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 291 | str1 = malloc(MIN(options.strlen, maxlength) + 3); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 292 | if (!str1) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 293 | return fprintf(options.output, "???"); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 294 | } |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 295 | umovestr(proc, addr, MIN(options.strlen, maxlength) + 1, str1); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 296 | len = fprintf(options.output, "\""); |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 297 | for (i = 0; i < MIN(options.strlen, maxlength); i++) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 298 | if (str1[i]) { |
| 299 | len += display_char(str1[i]); |
| 300 | } else { |
| 301 | break; |
| 302 | } |
| 303 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 304 | len += fprintf(options.output, "\""); |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 305 | if (str1[i] && (options.strlen <= maxlength)) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 306 | len += fprintf(options.output, "..."); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 307 | } |
| 308 | free(str1); |
| 309 | return len; |
| 310 | } |
| 311 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 312 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 313 | display_unknown(enum tof type, Process *proc, long value) { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 314 | if (proc->mask_32bit) { |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 315 | if ((int)value < 1000000 && (int)value > -1000000) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 316 | return fprintf(options.output, "%d", (int)value); |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 317 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 318 | return fprintf(options.output, "%p", (void *)value); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 319 | } else if (value < 1000000 && value > -1000000) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 320 | return fprintf(options.output, "%ld", value); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 321 | } else { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 322 | return fprintf(options.output, "%p", (void *)value); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 323 | } |
| 324 | } |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 325 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 326 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 327 | display_format(enum tof type, Process *proc, int arg_num) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 328 | void *addr; |
| 329 | unsigned char *str1; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 330 | int i; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame^] | 331 | size_t len = 0; |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 332 | arg_type_info info; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 333 | |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 334 | info.type = ARGTYPE_POINTER; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 335 | addr = (void *)gimme_arg(type, proc, arg_num, &info); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 336 | if (!addr) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 337 | return fprintf(options.output, "NULL"); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 340 | str1 = malloc(MIN(options.strlen, string_maxlength) + 3); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 341 | if (!str1) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 342 | return fprintf(options.output, "???"); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 343 | } |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 344 | umovestr(proc, addr, MIN(options.strlen, string_maxlength) + 1, str1); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 345 | len = fprintf(options.output, "\""); |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 346 | for (i = 0; len < MIN(options.strlen, string_maxlength) + 1; i++) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 347 | if (str1[i]) { |
| 348 | len += display_char(str1[i]); |
| 349 | } else { |
| 350 | break; |
| 351 | } |
| 352 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 353 | len += fprintf(options.output, "\""); |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 354 | if (str1[i] && (options.strlen <= string_maxlength)) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 355 | len += fprintf(options.output, "..."); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 356 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 357 | for (i = 0; str1[i]; i++) { |
| 358 | if (str1[i] == '%') { |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 359 | int is_long = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 360 | while (1) { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 361 | unsigned char c = str1[++i]; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 362 | if (c == '%') { |
| 363 | break; |
| 364 | } else if (!c) { |
| 365 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 366 | } else if (strchr("lzZtj", c)) { |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 367 | is_long++; |
| 368 | if (c == 'j') |
| 369 | is_long++; |
| Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame] | 370 | if (is_long > 1 |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 371 | && (sizeof(long) < sizeof(long long) |
| 372 | || proc->mask_32bit)) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 373 | len += fprintf(options.output, ", ..."); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 374 | str1[i + 1] = '\0'; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 375 | break; |
| 376 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 377 | } else if (c == 'd' || c == 'i') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 378 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 379 | if (!is_long || proc->mask_32bit) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 380 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 381 | fprintf(options.output, ", %d", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 382 | (int)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 383 | else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 384 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 385 | fprintf(options.output, ", %ld", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 386 | gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 387 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 388 | } else if (c == 'u') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 389 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 390 | if (!is_long || proc->mask_32bit) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 391 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 392 | fprintf(options.output, ", %u", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 393 | (int)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 394 | else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 395 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 396 | fprintf(options.output, ", %lu", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 397 | gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 398 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 399 | } else if (c == 'o') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 400 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 401 | if (!is_long || proc->mask_32bit) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 402 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 403 | fprintf(options.output, ", 0%o", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 404 | (int)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 405 | else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 406 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 407 | fprintf(options.output, ", 0%lo", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 408 | gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 409 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 410 | } else if (c == 'x' || c == 'X') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 411 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 412 | if (!is_long || proc->mask_32bit) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 413 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 414 | fprintf(options.output, ", %#x", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 415 | (int)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 416 | else |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 417 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 418 | fprintf(options.output, ", %#lx", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 419 | gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 420 | break; |
| 421 | } else if (strchr("eEfFgGaACS", c) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 422 | || (is_long |
| 423 | && (c == 'c' || c == 's'))) { |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 424 | len += fprintf(options.output, ", ..."); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 425 | str1[i + 1] = '\0'; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 426 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 427 | } else if (c == 'c') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 428 | info.type = ARGTYPE_LONG; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 429 | len += fprintf(options.output, ", '"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 430 | len += |
| 431 | display_char((int) |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 432 | gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 433 | len += fprintf(options.output, "'"); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 434 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 435 | } else if (c == 's') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 436 | info.type = ARGTYPE_POINTER; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 437 | len += fprintf(options.output, ", "); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 438 | len += |
| 439 | display_string(type, proc, |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 440 | (void *)gimme_arg(type, proc, ++arg_num, &info), |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 441 | string_maxlength); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 442 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 443 | } else if (c == 'p' || c == 'n') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 444 | info.type = ARGTYPE_POINTER; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 445 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 446 | fprintf(options.output, ", %p", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 447 | (void *)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 448 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 449 | } else if (c == '*') { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 450 | info.type = ARGTYPE_LONG; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 451 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 452 | fprintf(options.output, ", %d", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 453 | (int)gimme_arg(type, proc, ++arg_num, &info)); |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | free(str1); |
| 459 | return len; |
| 460 | } |