From c5c744a3b5a6e0d1f4826fabb31ffab2ec0170f3 Mon Sep 17 00:00:00 2001 From: Juan Cespedes Date: Thu, 23 Jul 2009 18:22:58 +0200 Subject: Clarified debug levels (try --debug=help) --- README | 4 +++- TODO | 1 - debug.h | 6 +++--- ltrace.1 | 16 ++++++++++----- options.c | 69 +++++++++++++++++++++++++++++++++++++++++++++------------------ 5 files changed, 67 insertions(+), 29 deletions(-) diff --git a/README b/README index ee42257..ab1a2e5 100644 --- a/README +++ b/README @@ -23,6 +23,8 @@ ltrace has been developed mainly by Juan Cespedes , but he has received many contributions from other people. The following people have contributed significantly to this project: +* César Sánchez +* Santiago Romero * Pat Beirne (ARM port) * Roman Hodek (m68k port) * Morten Eriksen (misc fixes) @@ -58,7 +60,7 @@ Using software breakpoints, just like gdb. It works with ELF based Linux systems running on i386, m68k, S/390, ARM, PowerPC, PowerPC64, IA64, AMD64, SPARC and Alpha processors. -It is part of at least Debian GNU/Linux, RedHat, SuSE and Mandrake. +It is part of at least Debian GNU/Linux, RedHat, SuSE, Mandrake... 5. Bugs ------- diff --git a/TODO b/TODO index 062ffbe..a25fe0f 100644 --- a/TODO +++ b/TODO @@ -34,5 +34,4 @@ * Get rid of GNU's autoconf stuff * List source dependencies in Makefile * Create different ltrace processes to trace different children -* debug: change "-d" option to be something like "-d elf,events", or "-d breakpoints" * After a clone(), syscalls may be seen as sysrets in s390 (see trace.c:syscall_p()) diff --git a/debug.h b/debug.h index 6b30e6a..653da84 100644 --- a/debug.h +++ b/debug.h @@ -3,9 +3,9 @@ /* debug levels: */ enum { - DEBUG_EVENT = 0x10, - DEBUG_PROCESS = 0x20, - DEBUG_FUNCTION = 0x40 + DEBUG_EVENT = 010, + DEBUG_PROCESS = 020, + DEBUG_FUNCTION = 040 }; void debug_(int level, const char *file, int line, diff --git a/ltrace.1 b/ltrace.1 index 7c56397..358d6aa 100644 --- a/ltrace.1 +++ b/ltrace.1 @@ -6,7 +6,7 @@ ltrace \- A library call tracer .SH SYNOPSIS .B ltrace -.I "[-CfhiLrStttV] [-a column] [-A maxelts] [-d level] [-e expr] [-l filename] [-n nr] [-o filename] [-p pid] ... [-s strsize] [-u username] [-X extern] [-x extern] ... [--align=column] [--debug=level] [--demangle] [--help] [--indent=nr] [--library=filename] [--output=filename] [--version] [command [arg ...]]" +.I "[-CfhiLrStttV] [-a column] [-A maxelts] [-D level] [-e expr] [-l filename] [-n nr] [-o filename] [-p pid] ... [-s strsize] [-u username] [-X extern] [-x extern] ... [--align=column] [--debug=level] [--demangle] [--help] [--indent=nr] [--library=filename] [--output=filename] [--version] [command [arg ...]]" .SH DESCRIPTION .B ltrace @@ -36,7 +36,7 @@ Decode (demangle) low-level symbol names into user-level names. Besides removing any initial underscore prefix used by the system, this makes C++ function names readable. .TP -.I \-d, \-\-debug level +.I \-D, \-\-debug level Show debugging output of .B ltrace itself. @@ -44,13 +44,19 @@ itself. must be a sum of some of the following numbers: .RS .TP -.B 0x10 +.B 01 +DEBUG_GENERAL. Shows helpful progress information +.TP +.B 010 DEBUG_EVENT. Shows every event received by a traced program .TP -.B 0x20 +.B 020 DEBUG_PROCESS. Shows every action .B ltrace -carries upon a traced program +carries upon a traced process +.TP +.B 040 +DEBUG_FUNCTION. Shows every entry to internal functions .RE .TP .I \-e expr diff --git a/options.c b/options.c index 34c7ae2..fe2bb4c 100644 --- a/options.c +++ b/options.c @@ -67,6 +67,16 @@ struct opt_F_t *opt_F = NULL; /* alternate configuration file(s) */ char *PLTs_initialized_by_here = PLT_REINITALISATION_BP; #endif +static void +err_usage(void) { +#if HAVE_GETOPT_LONG + fprintf(stderr, "Try `%s --help' for more information\n", progname); +#else + fprintf(stderr, "Try `%s -h' for more information\n", progname); +#endif + exit(1); +} + static void usage(void) { #if !(HAVE_GETOPT || HAVE_GETOPT_LONG) @@ -90,9 +100,14 @@ usage(void) { # endif # endif # if HAVE_GETOPT_LONG - " -d, --debug=LEVEL print debugging info.\n" + " -D, --debug=LEVEL enable debugging (see -Dh or --debug=help).\n" +# else + " -d LEVEL enable debugging (see -Dh).\n" +# endif +# if HAVE_GETOPT_LONG + " -Dh, --debug=help show help on debugging.\n" # else - " -d LEVEL print debugging info.\n" + " -Dh show help on debugging.\n" # endif " -e expr modify which events to trace.\n" " -f trace children (fork() and clone()).\n" @@ -144,6 +159,22 @@ usage(void) { #endif } +static void +usage_debug(void) { + fprintf(stdout, "%s debugging option, --debug= or -D:\n", progname); + fprintf(stdout, + "\n" + " number ref. in source description\n" + " 1 general Generally helpful progress information\n" + " 10 event Shows every event received by a traced process\n" + " 20 process Shows actions carried upon a traced processes\n" + " 40 function Shows every entry to internal functions\n" + "\n" + "Debugging options are mixed using bitwise-or.\n" + "Note that the meanings and values are subject to change.\n" + ); +} + static char * search_for_command(char *filename) { static char pathname[PATH_MAX]; @@ -207,12 +238,13 @@ process_options(int argc, char **argv) { #if HAVE_GETOPT || HAVE_GETOPT_LONG while (1) { int c; + char *p; #if HAVE_GETOPT_LONG int option_index = 0; static struct option long_options[] = { {"align", 1, 0, 'a'}, {"config", 1, 0, 'F'}, - {"debug", 1, 0, 'd'}, + {"debug", 1, 0, 'D'}, # ifdef USE_DEMANGLE {"demangle", 0, 0, 'C'}, #endif @@ -227,14 +259,14 @@ process_options(int argc, char **argv) { # ifdef USE_DEMANGLE "C" # endif - "a:A:d:e:F:l:n:o:p:s:u:x:X:", long_options, + "a:A:D:e:F:l:n:o:p:s:u:x:X:", long_options, &option_index); #else c = getopt(argc, argv, "+cfhiLrStTV" # ifdef USE_DEMANGLE "C" # endif - "a:A:d:e:F:l:n:o:p:s:u:x:X:"); + "a:A:D:e:F:l:n:o:p:s:u:x:X:"); #endif if (c == -1) { break; @@ -254,8 +286,16 @@ process_options(int argc, char **argv) { options.demangle++; break; #endif - case 'd': - options.debug = strtoul(optarg,NULL,0); + case 'D': + if (optarg[0]=='h') { + usage_debug(); + exit(0); + } + options.debug = strtoul(optarg,&p,8); + if (*p) { + fprintf(stderr, "%s: --debug requires an octal argument\n", progname); + err_usage(); + } break; case 'e': { @@ -408,15 +448,7 @@ process_options(int argc, char **argv) { } default: -#if HAVE_GETOPT_LONG - fprintf(stderr, - "Try `%s --help' for more information\n", - progname); -#else - fprintf(stderr, "Try `%s -h' for more information\n", - progname); -#endif - exit(1); + err_usage(); } } argc -= optind; @@ -448,13 +480,12 @@ process_options(int argc, char **argv) { if (!opt_p && argc < 1) { fprintf(stderr, "%s: too few arguments\n", progname); - usage(); - exit(1); + err_usage(); } if (opt_r && opt_t) { fprintf(stderr, "%s: Incompatible options -r and -t\n", progname); - exit(1); + err_usage(); } if (argc > 0) { command = search_for_command(argv[0]); -- cgit v1.2.3