This patch adds the module and source file information to the each stack trace line. `-m' is for module file information and `-s' is for source file information. `-v' is for both and more.
This is based on private discussion with Jan Kratochvil <[email protected]>. In v2 patch, `-s' and `-m' options are introduced instead of using `-v' repeatedly as suggested by Mark Wielaard <[email protected]>. Signed-off-by: Masatake YAMATO <[email protected]> --- src/ChangeLog | 8 ++++++++ src/stack.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f899858..454d6dd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2013-12-16 Masatake YAMATO <[email protected]> + + * stack.c (show_module, show_source): New variables. + (parse_opt): set show_module if -m option is given. + set show_source if -s option is given. + (main): Added `-m', `-s', and `-v' to the help message. + (frame_callback): Print module and source file information. + 2013-11-25 Petr Machata <[email protected]> * elflint.c (valid_e_machine): Add EM_AARCH64. diff --git a/src/stack.c b/src/stack.c index f428ed0..ed684c6 100644 --- a/src/stack.c +++ b/src/stack.c @@ -37,6 +37,8 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; static bool verbose = false; +static bool show_module = false; +static bool show_source = false; static int frame_callback (Dwfl_Frame *state, void *arg) @@ -78,7 +80,26 @@ frame_callback (Dwfl_Frame *state, void *arg) printf ("#%-2u 0x%0*" PRIx64, (*framenop)++, width, (uint64_t) pc); if (verbose) printf ("%4s", ! isactivation ? "- 1" : ""); - printf (" %s\n", symname); + printf (" %s", symname); + if (show_module) + { + const char* fname; + + fname = dwfl_module_info(mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + printf (" - %s", fname? fname: "?"); + } + if (show_source) + { + Dwfl_Line * lineobj; + int line, col; + const char* sname; + + lineobj = dwfl_module_getsrc(mod, pc_adjusted); + line = col = -1; + sname = lineobj? (dwfl_lineinfo(lineobj, NULL, &line, &col, NULL, NULL)?: "?"): "?"; + printf(" (%s:%d:%d)", sname, line, col); + } + printf ("\n"); return DWARF_CB_OK; } @@ -117,8 +138,16 @@ parse_opt (int key, char *arg __attribute__ ((unused)), state->child_inputs[0] = state->input; break; + case 'm': + show_module = true; + break; + + case 's': + show_source = true; + break; + case 'v': - verbose = true; + verbose = show_source = show_module = true; break; default: @@ -140,7 +169,10 @@ main (int argc, char **argv) const struct argp_option options[] = { - { "verbose", 'v', NULL, 0, N_("Additionally show frames activation"), 0 }, + { "module", 'm', NULL, 0, N_("Additionally show module file information"), 0 }, + { "source", 's', NULL, 0, N_("Additionally show source file information"), 0 }, + { "verbose", 'v', NULL, 0, N_("Additionally show frames activation " + "including module and source file information"), 0 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -165,7 +197,7 @@ Only real user processes are supported, no kernel or process maps."), argp_parse (&argp, argc, argv, 0, &remaining, &dwfl); assert (dwfl != NULL); if (remaining != argc) - error (2, 0, "eu-stack [--debuginfo-path=<path>] {-p <process id>|" + error (2, 0, "eu-stack [-m] [-s] [-v] [--debuginfo-path=<path>] {-p <process id>|" "--core=<file> [--executable=<file>]|--help}"); /* dwfl_linux_proc_report has been already called from dwfl_standard_argp's -- 1.8.3.1
