| 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" |
| Petr Machata | 366c2f4 | 2012-02-09 19:34:36 +0100 | [diff] [blame] | 8 | #include "proc.h" |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 9 | #include "type.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 10 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 11 | static int display_char(int what); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 12 | static int display_string(enum tof type, Process *proc, |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 13 | void* addr, size_t maxlen); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 14 | static int display_value(enum tof type, Process *proc, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 15 | long value, struct arg_type_info *info, |
| 16 | void *st, struct arg_type_info *st_info); |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 17 | static int display_unknown(enum tof type, Process *proc, long value); |
| 18 | static int display_format(enum tof type, Process *proc, int arg_num); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 19 | |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 20 | static size_t string_maxlength = INT_MAX; |
| 21 | static size_t array_maxlength = INT_MAX; |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 22 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 23 | static long |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 24 | get_length(enum tof type, Process *proc, int len_spec, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 25 | void *st, struct arg_type_info *st_info) |
| 26 | { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 27 | long len; |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 28 | struct arg_type_info info; |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 29 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 30 | if (len_spec > 0) |
| 31 | return len_spec; |
| 32 | if (type == LT_TOF_STRUCT) { |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 33 | umovelong(proc, st + st_info->u.struct_info.offset[-len_spec-1], |
| 34 | &len, st_info->u.struct_info.fields[-len_spec-1]); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 35 | return len; |
| 36 | } |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 37 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 38 | info.type = ARGTYPE_INT; |
| 39 | return gimme_arg(type, proc, -len_spec-1, &info); |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 42 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 43 | display_ptrto(enum tof type, Process *proc, long item, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 44 | struct arg_type_info * info, |
| 45 | void *st, struct arg_type_info *st_info) { |
| 46 | struct arg_type_info temp; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 47 | temp.type = ARGTYPE_POINTER; |
| 48 | temp.u.ptr_info.info = info; |
| 49 | return display_value(type, proc, item, &temp, st, st_info); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * addr - A pointer to the first element of the array |
| 54 | * |
| 55 | * The function name is used to indicate that we're not actually |
| 56 | * looking at an 'array', which is a contiguous region of memory |
| 57 | * containing a sequence of elements of some type; instead, we have a |
| 58 | * pointer to that region of memory. |
| 59 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 60 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 61 | display_arrayptr(enum tof type, Process *proc, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 62 | void *addr, struct arg_type_info * info, |
| 63 | void *st, struct arg_type_info *st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 64 | int len = 0; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 65 | size_t i; |
| 66 | size_t array_len; |
| 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 | if (addr == NULL) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 69 | return fprintf(options.output, "NULL"); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 70 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 71 | array_len = get_length(type, proc, info->u.array_info.len_spec, |
| 72 | st, st_info); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 73 | len += fprintf(options.output, "[ "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 74 | for (i = 0; i < options.arraylen && i < array_maxlength && i < array_len; i++) { |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 75 | struct arg_type_info *elt_type = info->u.array_info.elt_type; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 76 | size_t elt_size = info->u.array_info.elt_size; |
| 77 | if (i != 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 78 | len += fprintf(options.output, ", "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 79 | if (options.debug) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 80 | len += fprintf(options.output, "%p=", addr); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 81 | len += |
| 82 | display_ptrto(type, proc, (long) addr, elt_type, st, st_info); |
| 83 | addr += elt_size; |
| 84 | } |
| 85 | if (i < array_len) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 86 | len += fprintf(options.output, "..."); |
| 87 | len += fprintf(options.output, " ]"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 88 | return len; |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 89 | } |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 90 | |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 91 | /* addr - A pointer to the beginning of the memory region occupied by |
| 92 | * the struct (aka a pointer to the struct) |
| 93 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 94 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 95 | display_structptr(enum tof type, Process *proc, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 96 | void *addr, struct arg_type_info * info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 97 | int i; |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 98 | struct arg_type_info *field; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 99 | int len = 0; |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 100 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 101 | if (addr == NULL) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 102 | return fprintf(options.output, "NULL"); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 103 | |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 104 | len += fprintf(options.output, "{ "); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 105 | for (i = 0; (field = info->u.struct_info.fields[i]) != NULL; i++) { |
| 106 | if (i != 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 107 | len += fprintf(options.output, ", "); |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 108 | if (options.debug) |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 109 | len += |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 110 | fprintf(options.output, "%p=", |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 111 | addr + info->u.struct_info.offset[i]); |
| 112 | len += |
| 113 | display_ptrto(LT_TOF_STRUCT, proc, |
| 114 | (long) addr + info->u.struct_info.offset[i], |
| 115 | field, addr, info); |
| 116 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 117 | len += fprintf(options.output, " }"); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 118 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 119 | return len; |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 122 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 123 | display_pointer(enum tof type, Process *proc, long value, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 124 | struct arg_type_info * info, |
| 125 | void *st, struct arg_type_info *st_info) { |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 126 | long pointed_to; |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 127 | struct arg_type_info *inner = info->u.ptr_info.info; |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 128 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 129 | if (inner->type == ARGTYPE_ARRAY) { |
| 130 | return display_arrayptr(type, proc, (void*) value, inner, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 131 | st, st_info); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 132 | } else if (inner->type == ARGTYPE_STRUCT) { |
| 133 | return display_structptr(type, proc, (void *) value, inner); |
| 134 | } else { |
| 135 | if (value == 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 136 | return fprintf(options.output, "NULL"); |
| Luis Machado | 55c5feb | 2008-03-12 15:56:01 +0100 | [diff] [blame] | 137 | else if (umovelong (proc, (void *) value, &pointed_to, |
| 138 | info->u.ptr_info.info) < 0) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 139 | return fprintf(options.output, "?"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 140 | else |
| 141 | return display_value(type, proc, pointed_to, inner, |
| 142 | st, st_info); |
| 143 | } |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 146 | static int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 147 | display_enum(enum tof type, Process *proc, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 148 | struct arg_type_info *info, long value) { |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 149 | size_t ii; |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 150 | for (ii = 0; ii < info->u.enum_info.entries; ++ii) { |
| 151 | if (info->u.enum_info.values[ii] == value) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 152 | return fprintf(options.output, "%s", info->u.enum_info.keys[ii]); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 153 | } |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 154 | |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 155 | return display_unknown(type, proc, value); |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 158 | /* Args: |
| 159 | type - syscall or shared library function or memory |
| 160 | proc - information about the traced process |
| 161 | value - the value to display |
| 162 | info - the description of the type to display |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 163 | st - if the current value is a struct member, the address of the struct |
| 164 | st_info - type of the above struct |
| 165 | |
| 166 | Those last two parameters are used for structs containing arrays or |
| 167 | strings whose length is given by another structure element. |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 168 | */ |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 169 | int |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 170 | display_value(enum tof type, Process *proc, |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 171 | long value, struct arg_type_info *info, |
| 172 | void *st, struct arg_type_info *st_info) { |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 173 | int tmp; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 174 | |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 175 | switch (info->type) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 176 | case ARGTYPE_VOID: |
| 177 | return 0; |
| 178 | case ARGTYPE_INT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 179 | return fprintf(options.output, "%d", (int) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 180 | case ARGTYPE_UINT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 181 | return fprintf(options.output, "%u", (unsigned) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 182 | case ARGTYPE_LONG: |
| 183 | if (proc->mask_32bit) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 184 | return fprintf(options.output, "%d", (int) value); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 185 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 186 | return fprintf(options.output, "%ld", value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 187 | case ARGTYPE_ULONG: |
| 188 | if (proc->mask_32bit) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 189 | return fprintf(options.output, "%u", (unsigned) value); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 190 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 191 | return fprintf(options.output, "%lu", (unsigned long) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 192 | case ARGTYPE_OCTAL: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 193 | return fprintf(options.output, "0%o", (unsigned) value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 194 | case ARGTYPE_CHAR: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 195 | tmp = fprintf(options.output, "'"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 196 | tmp += display_char(value == -1 ? value : (char) value); |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 197 | tmp += fprintf(options.output, "'"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 198 | return tmp; |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 199 | case ARGTYPE_SHORT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 200 | return fprintf(options.output, "%hd", (short) value); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 201 | case ARGTYPE_USHORT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 202 | return fprintf(options.output, "%hu", (unsigned short) value); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 203 | case ARGTYPE_FLOAT: { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 204 | union { long l; float f; double d; } cvt; |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 205 | cvt.l = value; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 206 | return fprintf(options.output, "%f", cvt.f); |
| Steve Fink | 6fa27c3 | 2006-08-07 05:56:56 +0200 | [diff] [blame] | 207 | } |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 208 | case ARGTYPE_DOUBLE: { |
| 209 | union { long l; float f; double d; } cvt; |
| 210 | cvt.l = value; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 211 | return fprintf(options.output, "%lf", cvt.d); |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame] | 212 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 213 | case ARGTYPE_ADDR: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 214 | if (!value) |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 215 | return fprintf(options.output, "NULL"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 216 | else |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 217 | return fprintf(options.output, "0x%08lx", value); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 218 | case ARGTYPE_FORMAT: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 219 | fprintf(stderr, "Should never encounter a format anywhere but at the top level (for now?)\n"); |
| 220 | exit(1); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 221 | case ARGTYPE_STRING: |
| 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 | string_maxlength); |
| 224 | case ARGTYPE_STRING_N: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 225 | return display_string(type, proc, (void*) value, |
| Steve Fink | 6a48a6d | 2006-08-07 04:29:06 +0200 | [diff] [blame] | 226 | get_length(type, proc, |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 227 | info->u.string_n_info.size_spec, st, st_info)); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 228 | case ARGTYPE_ARRAY: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 229 | return fprintf(options.output, "<array without address>"); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 230 | case ARGTYPE_ENUM: |
| Steve Fink | 6a3e24d | 2006-08-07 05:53:19 +0200 | [diff] [blame] | 231 | return display_enum(type, proc, info, value); |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 232 | case ARGTYPE_STRUCT: |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 233 | return fprintf(options.output, "<struct without address>"); |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 234 | case ARGTYPE_POINTER: |
| Steve Fink | e4b3263 | 2006-08-07 06:10:08 +0200 | [diff] [blame] | 235 | return display_pointer(type, proc, value, info, |
| 236 | st, st_info); |
| Juan Cespedes | a413e5b | 2007-09-04 17:34:53 +0200 | [diff] [blame] | 237 | case ARGTYPE_UNKNOWN: |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 238 | default: |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 239 | return display_unknown(type, proc, value); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 240 | } |
| Steve Fink | 7bafff0 | 2006-08-07 04:50:42 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 243 | int |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 244 | display_arg(enum tof type, Process *proc, int arg_num, |
| 245 | struct arg_type_info * info) |
| 246 | { |
| 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 |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 286 | display_string(enum tof type, Process *proc, void *addr, |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 287 | size_t maxlength) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 288 | unsigned char *str1; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 289 | size_t 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 |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 318 | display_unknown(enum tof type, 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 |
| Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 332 | display_format(enum tof type, 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; |
| Zachary T Welch | ba6aca2 | 2010-12-08 18:55:09 -0800 | [diff] [blame] | 336 | size_t len = 0; |
| Petr Machata | 000e311 | 2012-01-03 17:03:39 +0100 | [diff] [blame^] | 337 | struct 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 | } |