From: Mark Wielaard Date: Sun, 22 Dec 2013 23:47:06 +0000 (+0100) Subject: stack: -b, --build-id shows module build-id, load address and pc offset. X-Git-Tag: elfutils-0.158~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=99fc3f7d948612c1769dc3378199f56209dbfa1d;p=thirdparty%2Felfutils.git stack: -b, --build-id shows module build-id, load address and pc offset. A convenient format for offline processing of the backtrace. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index d3d680782..4737d697e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2013-12-23 Mark Wielaard + + * stack.c (show_build_id): New static boolean. + (print_frames): Print module build-id, load address and pc offset + if show_build_id is true. + (parse_opt): Handle '-b'. + (main): Add -b to options. + 2013-12-22 Mark Wielaard * stack.c (maxframes): New static unsigned. Initialize to 64. diff --git a/src/stack.c b/src/stack.c index 188aa005a..362cc065b 100644 --- a/src/stack.c +++ b/src/stack.c @@ -38,6 +38,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; static bool show_activation = false; static bool show_module = false; +static bool show_build_id = false; static bool show_source = false; static bool show_one_tid = false; @@ -116,15 +117,31 @@ print_frames (struct frames *frames) if (symname != NULL) printf (" %s", symname); + const char* fname; + Dwarf_Addr start; + fname = dwfl_module_info(mod, NULL, &start, + NULL, NULL, NULL, NULL, NULL); if (show_module) { - const char* fname; - fname = dwfl_module_info(mod, - NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (fname != NULL) printf (" - %s", fname); } + if (show_build_id) + { + const unsigned char *id; + GElf_Addr id_vaddr; + int id_len = dwfl_module_build_id (mod, &id, &id_vaddr); + if (id_len > 0) + { + printf ("\n ["); + do + printf ("%02" PRIx8, *id++); + while (--id_len > 0); + printf ("]@0x%0" PRIx64 "+%" PRIx64, start, pc_adjusted - start); + } + } + if (show_source) { Dwfl_Line *lineobj = dwfl_module_getsrc(mod, pc_adjusted); @@ -203,6 +220,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)), show_activation = show_source = show_module = true; break; + case 'b': + show_build_id = true; + break; + case '1': show_one_tid = true; break; @@ -243,6 +264,8 @@ main (int argc, char **argv) N_("Additionally show source file information"), 0 }, { "verbose", 'v', NULL, 0, N_("Show all additional information (activation, module and source)"), 0 }, + { "build-id", 'b', NULL, 0, + N_("Show module build-id, load address and pc offset"), 0 }, { NULL, '1', NULL, 0, N_("Show the backtrace of only one thread"), 0 }, { NULL, 'n', "MAXFRAMES", 0, @@ -270,7 +293,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 [-a] [-m] [-s] [-v] [-1] [-n MAXFRAMES]" + error (2, 0, "eu-stack [-a] [-m] [-b] [-s] [-v] [-1] [-n MAXFRAMES]" " [--debuginfo-path=]" " {-p |--core= [--executable=]|--help}");