11
12
#include "options.h"
13
14
static int display_char(int what);
14
static int display_string(enum tof type, struct process *proc, int arg_num);
15
static int display_stringN(int arg2, enum tof type, struct process *proc,
17
static int display_unknown(enum tof type, struct process *proc, int arg_num);
15
static int display_string(enum tof type, struct process *proc,
16
void* addr, size_t maxlen);
17
static int display_value(enum tof type, struct process *proc,
18
long value, arg_type_info *info,
19
void *st, arg_type_info* st_info);
20
static int display_unknown(enum tof type, struct process *proc, long value);
18
21
static int display_format(enum tof type, struct process *proc, int arg_num);
21
display_arg(enum tof type, struct process *proc, int arg_num, enum arg_type at)
23
static int string_maxlength = INT_MAX;
24
static int array_maxlength = INT_MAX;
26
static long get_length(enum tof type, struct process *proc, int len_spec,
27
void *st, arg_type_info* st_info)
34
if (type == LT_TOF_STRUCT) {
35
umovelong (proc, st + st_info->u.struct_info.offset[-len_spec-1],
36
&len, st_info->u.struct_info.fields[-len_spec-1]);
40
info.type = ARGTYPE_INT;
41
return gimme_arg(type, proc, -len_spec-1, &info);
44
static int display_ptrto(enum tof type, struct process *proc, long item,
46
void *st, arg_type_info* st_info)
49
temp.type = ARGTYPE_POINTER;
50
temp.u.ptr_info.info = info;
51
return display_value(type, proc, item, &temp, st, st_info);
55
* addr - A pointer to the first element of the array
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.
62
static int display_arrayptr(enum tof type, struct process *proc,
63
void *addr, arg_type_info * info,
64
void *st, arg_type_info* st_info)
71
return fprintf(output, "NULL");
73
array_len = get_length(type, proc, info->u.array_info.len_spec,
75
len += fprintf(output, "[ ");
76
for (i = 0; i < opt_A && i < array_maxlength && i < array_len; i++) {
77
arg_type_info *elt_type = info->u.array_info.elt_type;
78
size_t elt_size = info->u.array_info.elt_size;
80
len += fprintf(output, ", ");
82
len += fprintf(output, "%p=", addr);
84
display_ptrto(type, proc, (long) addr, elt_type, st, st_info);
88
len += fprintf(output, "...");
89
len += fprintf(output, " ]");
93
/* addr - A pointer to the beginning of the memory region occupied by
94
* the struct (aka a pointer to the struct)
96
static int display_structptr(enum tof type, struct process *proc,
97
void *addr, arg_type_info * info)
100
arg_type_info *field;
104
return fprintf(output, "NULL");
106
len += fprintf(output, "{ ");
107
for (i = 0; (field = info->u.struct_info.fields[i]) != NULL; i++) {
109
len += fprintf(output, ", ");
112
fprintf(output, "%p=",
113
addr + info->u.struct_info.offset[i]);
115
display_ptrto(LT_TOF_STRUCT, proc,
116
(long) addr + info->u.struct_info.offset[i],
119
len += fprintf(output, " }");
124
static int display_pointer(enum tof type, struct process *proc, long value,
125
arg_type_info * info,
126
void *st, arg_type_info* st_info)
129
arg_type_info *inner = info->u.ptr_info.info;
131
if (inner->type == ARGTYPE_ARRAY) {
132
return display_arrayptr(type, proc, (void*) value, inner,
134
} else if (inner->type == ARGTYPE_STRUCT) {
135
return display_structptr(type, proc, (void *) value, inner);
138
return fprintf(output, "NULL");
139
else if (umovelong (proc, (void *) value, &pointed_to,
140
info->u.ptr_info.info) < 0)
141
return fprintf(output, "?");
143
return display_value(type, proc, pointed_to, inner,
148
static int display_enum(enum tof type, struct process *proc,
149
arg_type_info* info, long value)
152
for (ii = 0; ii < info->u.enum_info.entries; ++ii) {
153
if (info->u.enum_info.values[ii] == value)
154
return fprintf(output, "%s", info->u.enum_info.keys[ii]);
157
return display_unknown(type, proc, value);
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
165
st - if the current value is a struct member, the address of the struct
166
st_info - type of the above struct
168
Those last two parameters are used for structs containing arrays or
169
strings whose length is given by another structure element.
171
int display_value(enum tof type, struct process *proc,
172
long value, arg_type_info *info,
173
void *st, arg_type_info* st_info)
177
switch (info->type) {
27
178
case ARGTYPE_VOID:
30
return fprintf(output, "%d",
31
(int)gimme_arg(type, proc, arg_num));
181
return fprintf(output, "%d", (int) value);
32
182
case ARGTYPE_UINT:
33
return fprintf(output, "%u",
34
(unsigned)gimme_arg(type, proc, arg_num));
183
return fprintf(output, "%u", (unsigned) value);
35
184
case ARGTYPE_LONG:
36
185
if (proc->mask_32bit)
37
return fprintf(output, "%d",
38
(int)gimme_arg(type, proc, arg_num));
39
return fprintf(output, "%ld", gimme_arg(type, proc, arg_num));
186
return fprintf(output, "%d", (int) value);
188
return fprintf(output, "%ld", value);
40
189
case ARGTYPE_ULONG:
41
190
if (proc->mask_32bit)
42
return fprintf(output, "%u",
43
(unsigned)gimme_arg(type, proc,
45
return fprintf(output, "%lu",
46
(unsigned long)gimme_arg(type, proc, arg_num));
191
return fprintf(output, "%u", (unsigned) value);
193
return fprintf(output, "%lu", (unsigned long) value);
47
194
case ARGTYPE_OCTAL:
48
return fprintf(output, "0%o",
49
(unsigned)gimme_arg(type, proc, arg_num));
195
return fprintf(output, "0%o", (unsigned) value);
50
196
case ARGTYPE_CHAR:
51
197
tmp = fprintf(output, "'");
52
tmp += display_char((int)gimme_arg(type, proc, arg_num));
198
tmp += display_char(value == -1 ? value : (char) value);
53
199
tmp += fprintf(output, "'");
202
return fprintf(output, "%hd", (short) value);
204
return fprintf(output, "%hu", (unsigned short) value);
205
case ARGTYPE_FLOAT: {
206
union { long l; float f; double d; } cvt;
208
return fprintf(output, "%f", cvt.f);
210
case ARGTYPE_DOUBLE: {
211
union { long l; float f; double d; } cvt;
213
return fprintf(output, "%lf", cvt.d);
55
215
case ARGTYPE_ADDR:
56
arg = gimme_arg(type, proc, arg_num);
58
217
return fprintf(output, "NULL");
60
return fprintf(output, "%p", (void *)arg);
219
return fprintf(output, "0x%08lx", value);
62
220
case ARGTYPE_FORMAT:
63
return display_format(type, proc, arg_num);
221
fprintf(stderr, "Should never encounter a format anywhere but at the top level (for now?)\n");
64
223
case ARGTYPE_STRING:
65
return display_string(type, proc, arg_num);
67
return display_stringN(0, type, proc, arg_num);
69
return display_stringN(1, type, proc, arg_num);
71
return display_stringN(2, type, proc, arg_num);
73
return display_stringN(3, type, proc, arg_num);
75
return display_stringN(4, type, proc, arg_num);
77
return display_stringN(5, type, proc, arg_num);
224
return display_string(type, proc, (void*) value,
226
case ARGTYPE_STRING_N:
227
return display_string(type, proc, (void*) value,
228
get_length(type, proc,
229
info->u.string_n_info.size_spec, st, st_info));
231
return fprintf(output, "<array without address>");
233
return display_enum(type, proc, info, value);
235
return fprintf(output, "<struct without address>");
236
case ARGTYPE_POINTER:
237
return display_pointer(type, proc, value, info,
78
239
case ARGTYPE_UNKNOWN:
80
return display_unknown(type, proc, arg_num);
82
return fprintf(output, "?");
241
return display_unknown(type, proc, value);
245
int display_arg(enum tof type, struct process *proc, int arg_num, arg_type_info * info)
249
if (info->type == ARGTYPE_VOID) {
251
} else if (info->type == ARGTYPE_FORMAT) {
252
return display_format(type, proc, arg_num);
254
arg = gimme_arg(type, proc, arg_num, info);
255
return display_value(type, proc, arg, info, NULL, NULL);
85
259
static int display_char(int what)