Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
DISCONTINUED:openSUSE:11.1:Update
ltrace
ltrace.trunk-r58.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ltrace.trunk-r58.patch of Package ltrace
------------------------------------------------------------------------ r58 | ianw-guest | 2006-08-07 02:50:42 +0000 (Mon, 07 Aug 2006) | 2 lines Changed paths: M /ltrace/trunk/ChangeLog M /ltrace/trunk/display_args.c M /ltrace/trunk/etc/ltrace.conf M /ltrace/trunk/ltrace.h M /ltrace/trunk/read_config_file.c M /ltrace/trunk/sysdeps/README M /ltrace/trunk/sysdeps/linux-gnu/trace.c pointer parameters ------------------------------------------------------------------------ --- ChangeLog | 7 ++ display_args.c | 132 +++++++++++++++++++++++++++------------------- etc/ltrace.conf | 3 - ltrace.h | 7 ++ read_config_file.c | 18 +++++- sysdeps/README | 1 sysdeps/linux-gnu/trace.c | 18 ++++++ 7 files changed, 129 insertions(+), 57 deletions(-) Index: read_config_file.c =================================================================== --- read_config_file.c.orig +++ read_config_file.c @@ -47,6 +47,7 @@ static arg_type_info arg_type_singletons { ARGTYPE_STRING }, { ARGTYPE_STRING_N }, { ARGTYPE_IGNORE }, + { ARGTYPE_POINTER }, { ARGTYPE_UNKNOWN } }; @@ -64,7 +65,7 @@ static arg_type_info *str2type(char **st while (tmp->name) { if (!strncmp(*str, tmp->name, strlen(tmp->name)) - && index(" ,()#;012345[", *(*str + strlen(tmp->name)))) { + && index(" ,()#*;012345[", *(*str + strlen(tmp->name)))) { *str += strlen(tmp->name); return lookup_singleton(tmp->pt); } @@ -169,7 +170,7 @@ static int parse_argnum(char **str) return n * multiplier; } -static arg_type_info *parse_type(char **str) +static arg_type_info *parse_nonpointer_type(char **str) { arg_type_info *simple; arg_type_info *info; @@ -220,6 +221,19 @@ static arg_type_info *parse_type(char ** } } +static arg_type_info *parse_type(char **str) +{ + arg_type_info *info = parse_nonpointer_type(str); + while (**str == '*') { + arg_type_info *outer = malloc(sizeof(*info)); + outer->type = ARGTYPE_POINTER; + outer->u.ptr_info.info = info; + (*str)++; + info = outer; + } + return info; +} + static struct function *process_line(char *buf) { struct function fun; Index: display_args.c =================================================================== --- display_args.c.orig +++ display_args.c @@ -2,6 +2,7 @@ #include "config.h" #endif +#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -12,9 +13,10 @@ static int display_char(int what); static int display_string(enum tof type, struct process *proc, - int arg_num, arg_type_info *info, - size_t maxlen); -static int display_unknown(enum tof type, struct process *proc, int arg_num); + void* addr, size_t maxlen); +static int display_value(enum tof type, struct process *proc, + long value, arg_type_info *info); +static int display_unknown(enum tof type, struct process *proc, long value); static int display_format(enum tof type, struct process *proc, int arg_num); static int string_maxlength = INT_MAX; @@ -26,12 +28,30 @@ static long get_length(enum tof type, st return gimme_arg(type, proc, -len_spec - 1); } -int -display_arg(enum tof type, struct process *proc, - int arg_num, arg_type_info *info) +static int display_pointer(enum tof type, struct process *proc, long value, + arg_type_info * info) +{ + long pointed_to; + arg_type_info *inner = info->u.ptr_info.info; + + if (value == 0) + return fprintf(output, "NULL"); + else if (umovelong(proc, (void *) value, &pointed_to) < 0) + return fprintf(output, "?"); + else + return display_value(type, proc, pointed_to, inner); +} + +/* Args: + type - syscall or shared library function or memory + proc - information about the traced process + value - the value to display + info - the description of the type to display +*/ +int display_value(enum tof type, struct process *proc, + long value, arg_type_info *info) { int tmp; - long arg; switch (info->type) { case ARGTYPE_VOID: @@ -39,52 +59,62 @@ display_arg(enum tof type, struct proces case ARGTYPE_IGNORE: return 0; /* Empty gap between commas */ case ARGTYPE_INT: - return fprintf(output, "%d", - (int)gimme_arg(type, proc, arg_num)); + return fprintf(output, "%d", (int) value); case ARGTYPE_UINT: - return fprintf(output, "%u", - (unsigned)gimme_arg(type, proc, arg_num)); + return fprintf(output, "%u", (unsigned) value); case ARGTYPE_LONG: if (proc->mask_32bit) - return fprintf(output, "%d", - (int)gimme_arg(type, proc, arg_num)); - return fprintf(output, "%ld", gimme_arg(type, proc, arg_num)); + return fprintf(output, "%d", (int) value); + else + return fprintf(output, "%ld", value); case ARGTYPE_ULONG: if (proc->mask_32bit) - return fprintf(output, "%u", - (unsigned)gimme_arg(type, proc, - arg_num)); - return fprintf(output, "%lu", - (unsigned long)gimme_arg(type, proc, arg_num)); + return fprintf(output, "%u", (unsigned) value); + else + return fprintf(output, "%lu", (unsigned long) value); case ARGTYPE_OCTAL: - return fprintf(output, "0%o", - (unsigned)gimme_arg(type, proc, arg_num)); + return fprintf(output, "0%o", (unsigned) value); case ARGTYPE_CHAR: tmp = fprintf(output, "'"); - tmp += display_char((int)gimme_arg(type, proc, arg_num)); + tmp += display_char(value == -1 ? value : (char) value); tmp += fprintf(output, "'"); return tmp; case ARGTYPE_ADDR: - arg = gimme_arg(type, proc, arg_num); - if (!arg) { + if (!value) return fprintf(output, "NULL"); - } else { - return fprintf(output, "%p", (void *)arg); - } + else + return fprintf(output, "0x%08lx", value); case ARGTYPE_FORMAT: - return display_format(type, proc, arg_num); + fprintf(stderr, "Should never encounter a format anywhere but at the top level (for now?)\n"); + exit(1); case ARGTYPE_STRING: - return display_string(type, proc, arg_num, info, + return display_string(type, proc, (void*) value, string_maxlength); case ARGTYPE_STRING_N: - return display_string(type, proc, arg_num, info, + return display_string(type, proc, (void*) value, get_length(type, proc, info->u.string_n_info.size_spec)); - case ARGTYPE_UNKNOWN: + case ARGTYPE_POINTER: + return display_pointer(type, proc, value, info); + case ARGTYPE_UNKNOWN: default: - return display_unknown(type, proc, arg_num); + return display_unknown(type, proc, value); } - return fprintf(output, "?"); +} + +int display_arg(enum tof type, struct process *proc, int arg_num, + arg_type_info * info) +{ + long arg; + + if (info->type == ARGTYPE_VOID) { + return 0; + } else if (info->type == ARGTYPE_FORMAT) { + return display_format(type, proc, arg_num); + } else { + arg = gimme_arg(type, proc, arg_num); + return display_value(type, proc, arg, info); + } } static int display_char(int what) @@ -103,25 +133,23 @@ static int display_char(int what) case '\\': return fprintf(output, "\\\\"); default: - if ((what < 32) || (what > 126)) { - return fprintf(output, "\\%03o", (unsigned char)what); - } else { + if (isprint(what)) { return fprintf(output, "%c", what); + } else { + return fprintf(output, "\\%03o", (unsigned char)what); } } } #define MIN(a,b) (((a)<(b)) ? (a) : (b)) -static int display_string(enum tof type, struct process *proc, - int arg_num, arg_type_info *info, size_t maxlength) +static int display_string(enum tof type, struct process *proc, void *addr, + size_t maxlength) { - void *addr; unsigned char *str1; int i; int len = 0; - addr = (void *)gimme_arg(type, proc, arg_num); if (!addr) { return fprintf(output, "NULL"); } @@ -147,21 +175,17 @@ static int display_string(enum tof type, return len; } -static int display_unknown(enum tof type, struct process *proc, int arg_num) +static int display_unknown(enum tof type, struct process *proc, long value) { - long tmp; - - tmp = gimme_arg(type, proc, arg_num); - if (proc->mask_32bit) { - if ((int)tmp < 1000000 && (int)tmp > -1000000) - return fprintf(output, "%d", (int)tmp); + if ((int)value < 1000000 && (int)value > -1000000) + return fprintf(output, "%d", (int)value); else - return fprintf(output, "%p", (void *)tmp); - } else if (tmp < 1000000 && tmp > -1000000) { - return fprintf(output, "%ld", tmp); + return fprintf(output, "%p", (void *)value); + } else if (value < 1000000 && value > -1000000) { + return fprintf(output, "%ld", value); } else { - return fprintf(output, "%p", (void *)tmp); + return fprintf(output, "%p", (void *)value); } } @@ -285,12 +309,12 @@ static int display_format(enum tof type, len += fprintf(output, "'"); break; } else if (c == 's') { - arg_type_info *info = - lookup_singleton(ARGTYPE_STRING); len += fprintf(output, ", "); len += display_string(type, proc, - ++arg_num, info, + (void *)gimme_arg(type, + proc, + ++arg_num), string_maxlength); break; } else if (c == 'p' || c == 'n') { Index: ChangeLog =================================================================== --- ChangeLog.orig +++ ChangeLog @@ -1,3 +1,10 @@ +2006-08-07 Steve Fink <sphink@gmail.com> + + * display_args.c, etc/ltrace.conf, ltrace.h, read_config_file.c, + sysdeps/README, sysdeps/linux-gnu-trace.c : switch to passing + around values rather than argument numbers that need to be fetched + (needed for pointer params) + 2006-08-07 Steve Fink <sphink@gmail.com> * display_args.c, etc/ltrace.conf, ltrace.h, read_config_file.c: Index: sysdeps/linux-gnu/trace.c =================================================================== --- sysdeps/linux-gnu/trace.c.orig +++ sysdeps/linux-gnu/trace.c @@ -151,6 +151,24 @@ void continue_after_breakpoint(struct pr } } +/* Read a single long from the process's memory address 'addr' */ +int umovelong(struct process *proc, void *addr, long *result) +{ + long pointed_to; + + errno = 0; + pointed_to = ptrace(PTRACE_PEEKTEXT, proc->pid, addr, 0); + if (pointed_to == -1 && errno) + return -errno; + + *result = pointed_to; + return 0; +} + +/* Read a series of bytes starting at the process's memory address + 'addr' and continuing until a NUL ('\0') is seen or 'len' bytes + have been read. +*/ int umovestr(struct process *proc, void *addr, int len, void *laddr) { union { Index: sysdeps/README =================================================================== --- sysdeps/README.orig +++ sysdeps/README @@ -24,6 +24,7 @@ void * get_stack_pointer(pid_t pid); void * get_return_addr(pid_t pid, void * stack_pointer); long gimme_arg(enum tof type, struct process * proc, int arg_num); int umovestr(struct process * proc, void * addr, int len, void * laddr); +int umovelong(struct process * proc, void * addr, long * result); char * pid2name(pid_t pid); void trace_me(void); int trace_pid(pid_t pid); Index: ltrace.h =================================================================== --- ltrace.h.orig +++ ltrace.h @@ -43,6 +43,7 @@ enum arg_type { ARGTYPE_STRING, /* NUL-terminated string */ ARGTYPE_STRING_N, /* String of known maxlen */ ARGTYPE_IGNORE, /* Leave parameter blank */ + ARGTYPE_POINTER, /* Pointer to some other type */ ARGTYPE_COUNT /* number of ARGTYPE_* values */ }; @@ -53,6 +54,11 @@ typedef struct arg_type_info_t { struct { int size_spec; } string_n_info; + + // ARGTYPE_POINTER + struct { + struct arg_type_info_t *info; + } ptr_info; } u; } arg_type_info; @@ -206,6 +212,7 @@ extern void continue_enabling_breakpoint extern long gimme_arg(enum tof type, struct process *proc, int arg_num); extern void save_register_args(enum tof type, struct process *proc); extern int umovestr(struct process *proc, void *addr, int len, void *laddr); +extern int umovelong(struct process *proc, void *addr, long *result); extern int ffcheck(void *maddr); extern void *sym2addr(struct process *, struct library_symbol *); Index: etc/ltrace.conf =================================================================== --- etc/ltrace.conf.orig +++ etc/ltrace.conf @@ -23,6 +23,7 @@ ; string[arg0] == (char *) [same as string[retval]] ; string[N] == (char *) [N>0] [show only up to N bytes] ; ignore == (any) [ignore arg, output blank] +; type* == (type *) [pointer to any other type] ; Backwards-compatibility: ; string0 == (char *) [same as string[retval]] @@ -77,7 +78,7 @@ int open64(string,int,octal); ; WARNING int fnmatch(string, string, int); ; getopt.h -int getopt_long(int,addr,string,addr,addr); +int getopt_long(int,addr,string,addr,int*); int getopt_long_only(int,addr,string,addr,addr); ; grp.h
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor