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