From da9b953284966b8c52de43713ebb5b503756e468 Mon Sep 17 00:00:00 2001 From: Juan Cespedes Date: Tue, 7 Apr 2009 15:33:50 +0200 Subject: More fields to struct "options" (opt_c, opt_d, opt_A) --- debug.c | 2 +- display_args.c | 6 +++--- ltrace.c | 2 +- ltrace.h | 11 ++++++----- options.c | 26 +++++++++++++------------- options.h | 6 +++--- output.c | 6 +++--- process_event.c | 10 +++++----- sysdeps/linux-gnu/ppc/plt.c | 2 +- 9 files changed, 36 insertions(+), 35 deletions(-) diff --git a/debug.c b/debug.c index 4353edc..c31a9a9 100644 --- a/debug.c +++ b/debug.c @@ -11,7 +11,7 @@ debug_(int level, const char *file, int line, const char *func, char buf[1024]; va_list args; - if (opt_d < level) { + if (options.debug < level) { return; } va_start(args, fmt); diff --git a/display_args.c b/display_args.c index 6ffb859..aade610 100644 --- a/display_args.c +++ b/display_args.c @@ -73,12 +73,12 @@ display_arrayptr(enum tof type, struct process *proc, array_len = get_length(type, proc, info->u.array_info.len_spec, st, st_info); len += fprintf(options.output, "[ "); - for (i = 0; i < opt_A && i < array_maxlength && i < array_len; i++) { + for (i = 0; i < options.arraylen && i < array_maxlength && i < array_len; i++) { arg_type_info *elt_type = info->u.array_info.elt_type; size_t elt_size = info->u.array_info.elt_size; if (i != 0) len += fprintf(options.output, ", "); - if (opt_d) + if (options.debug) len += fprintf(options.output, "%p=", addr); len += display_ptrto(type, proc, (long) addr, elt_type, st, st_info); @@ -107,7 +107,7 @@ display_structptr(enum tof type, struct process *proc, for (i = 0; (field = info->u.struct_info.fields[i]) != NULL; i++) { if (i != 0) len += fprintf(options.output, ", "); - if (opt_d) + if (options.debug) len += fprintf(options.output, "%p=", addr + info->u.struct_info.offset[i]); diff --git a/ltrace.c b/ltrace.c index d35785f..d85f4f2 100644 --- a/ltrace.c +++ b/ltrace.c @@ -67,7 +67,7 @@ signal_exit(int sig) { static void normal_exit(void) { output_line(0, 0); - if (opt_c) { + if (options.summary) { show_summary(); } if (options.output) { diff --git a/ltrace.h b/ltrace.h index 2677ebf..acfbd4d 100644 --- a/ltrace.h +++ b/ltrace.h @@ -195,15 +195,16 @@ struct event { EVENT_ARCH_SYSCALL, EVENT_ARCH_SYSRET, EVENT_FORK, + EVENT_CLONE, /* Like FORK, but parent and child share memory */ EVENT_EXEC, EVENT_BREAKPOINT } thing; union { - int ret_val; /* _EV_EXIT */ - int signum; /* _EV_SIGNAL, _EV_EXIT_SIGNAL */ - int sysnum; /* _EV_SYSCALL, _EV_SYSRET */ - void *brk_addr; /* _EV_BREAKPOINT */ - int newpid; /* _EV_FORK */ + int ret_val; /* EVENT_EXIT */ + int signum; /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */ + int sysnum; /* EVENT_SYSCALL, EVENT_SYSRET */ + void *brk_addr; /* EVENT_BREAKPOINT */ + int newpid; /* EVENT_FORK, EVENT_CLONE */ } e_un; }; diff --git a/options.c b/options.c index 04e55a8..20c3c59 100644 --- a/options.c +++ b/options.c @@ -26,24 +26,24 @@ #define USER_CONFIG_FILE "~/.ltrace.conf" struct options_t options = { - .align = DEFAULT_ALIGN, /* alignment column for results */ - .user = NULL, /* username to run command as */ - .syscalls = 0, /* display syscalls */ - .libcalls = 1, /* display library calls */ + .align = DEFAULT_ALIGN, /* alignment column for results */ + .user = NULL, /* username to run command as */ + .syscalls = 0, /* display syscalls */ + .libcalls = 1, /* display library calls */ #ifdef USE_DEMANGLE - .demangle = 0, /* Demangle low-level symbol names */ + .demangle = 0, /* Demangle low-level symbol names */ #endif - .indent = 0, /* indent output according to program flow */ - .output = NULL, /* output to a specific file */ + .indent = 0, /* indent output according to program flow */ + .output = NULL, /* output to a specific file */ + .summary = 0; /* Report a summary on program exit */ + .debug = 0; /* debug */ + .arraylen = DEFAULT_ARRAYLEN; /* maximum # array elements to print */ }; #define MAX_LIBRARY 30 char *library[MAX_LIBRARY]; int library_num = 0; static char *progname; /* Program name (`ltrace') */ -int opt_A = DEFAULT_ARRAYLEN; /* maximum # array elements to print */ -int opt_c = 0; /* Report a summary on program exit */ -int opt_d = 0; /* debug */ int opt_i = 0; /* instruction pointer */ int opt_s = DEFAULT_STRLEN; /* maximum # of bytes printed in strings */ int opt_f = 0; /* trace child processes as they are created */ @@ -247,10 +247,10 @@ process_options(int argc, char **argv) { options.align = atoi(optarg); break; case 'A': - opt_A = atoi(optarg); + options.arraylen = atoi(optarg); break; case 'c': - opt_c++; + options.summary++; break; #ifdef USE_DEMANGLE case 'C': @@ -258,7 +258,7 @@ process_options(int argc, char **argv) { break; #endif case 'd': - opt_d++; + options.debug++; break; case 'e': { diff --git a/options.h b/options.h index c74cbbb..8fc3ade 100644 --- a/options.h +++ b/options.h @@ -13,12 +13,12 @@ struct options_t { int demangle; /* -C: demangle low-level names into user-level names */ int indent; /* -n: indent trace output according to program flow */ FILE *output; /* output to a specific file */ + int summary; /* count time, calls, and report a summary on program exit */ + int debug; /* debug */ + int arraylen; /* default maximum # of array elements printed */ }; extern struct options_t options; -extern int opt_A; /* default maximum # of array elements printed */ -extern int opt_c; /* count time, calls, and report a summary on program exit */ -extern int opt_d; /* debug */ extern int opt_i; /* instruction pointer */ extern int opt_s; /* default maximum # of bytes printed in strings */ extern int opt_f; /* trace child processes */ diff --git a/output.c b/output.c index 41ad9c6..2bb0de8 100644 --- a/output.c +++ b/output.c @@ -131,7 +131,7 @@ void output_line(struct process *proc, char *fmt, ...) { va_list args; - if (opt_c) { + if (options.summary) { return; } if (current_proc) { @@ -168,7 +168,7 @@ output_left(enum tof type, struct process *proc, char *function_name) { if (arg_unknown == NULL) arg_unknown = lookup_prototype(ARGTYPE_UNKNOWN); - if (opt_c) { + if (options.summary) { return; } if (current_proc) { @@ -225,7 +225,7 @@ output_right(enum tof type, struct process *proc, char *function_name) { if (arg_unknown == NULL) arg_unknown = lookup_prototype(ARGTYPE_UNKNOWN); - if (opt_c) { + if (options.summary) { struct opt_c_struct *st; if (!dict_opt_c) { dict_opt_c = diff --git a/process_event.c b/process_event.c index 269ab6b..db5d3bd 100644 --- a/process_event.c +++ b/process_event.c @@ -263,7 +263,7 @@ calc_time_spent(struct process *proc) { static void process_sysret(struct event *event) { - if (opt_T || opt_c) { + if (opt_T || options.summary) { calc_time_spent(event->proc); } if (fork_p(event->proc, event->e_un.sysnum)) { @@ -288,7 +288,7 @@ process_sysret(struct event *event) { static void process_arch_sysret(struct event *event) { - if (opt_T || opt_c) { + if (opt_T || options.summary) { calc_time_spent(event->proc); } callstack_pop(event->proc); @@ -392,7 +392,7 @@ process_breakpoint(struct event *event) { for (j = event->proc->callstack_depth - 1; j > i; j--) { callstack_pop(event->proc); } - if (opt_T || opt_c) { + if (opt_T || options.summary) { calc_time_spent(event->proc); } callstack_pop(event->proc); @@ -446,7 +446,7 @@ callstack_push_syscall(struct process *proc, int sysnum) { elem->return_addr = NULL; proc->callstack_depth++; - if (opt_T || opt_c) { + if (opt_T || options.summary) { struct timezone tz; gettimeofday(&elem->time_spent, &tz); } @@ -472,7 +472,7 @@ callstack_push_symfunc(struct process *proc, struct library_symbol *sym) { } proc->callstack_depth++; - if (opt_T || opt_c) { + if (opt_T || options.summary) { struct timezone tz; gettimeofday(&elem->time_spent, &tz); } diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c index d74caf5..e6b54d6 100644 --- a/sysdeps/linux-gnu/ppc/plt.c +++ b/sysdeps/linux-gnu/ppc/plt.c @@ -25,7 +25,7 @@ sym2addr(struct process *proc, struct library_symbol *sym) { return 0; } - if (opt_d >= 3) { + if (options.debug >= 3) { xinfdump(proc->pid, (void *)(((long)addr-32)&0xfffffff0), sizeof(void*)*8); } -- cgit v1.2.3