This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] stack: show binary and source file names where a function is defined


On Tue, 2013-12-17 at 12:03 +0900, Masatake YAMATO wrote:
> 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
> <jan.kratochvil@redhat.com>.
> 
> In v2 patch, `-s' and `-m' options are introduced instead
> of using `-v' repeatedly as suggested by Mark Wielaard <mjw@redhat.com>.
> 
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>

> +2013-12-16  Masatake YAMATO  <yamato@redhat.com>
> +
> +	* 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.

I like it, but do want to tweak the formatting a little. In particular
don't print any information we don't have, like missing columns or
lines. I think it would be good to treat the activation info like the
rest of the extra/verbose information. And since source lines are
usually fairly large I think they should be on their own line.

What do you think of the attached. It produces the following with -v:

TID 7172:
#0  0x00000033c82ac8be     __waitpid - /lib64/libc-2.12.so
    ../sysdeps/unix/sysv/linux/waitpid.c:32
#1  0x000000000043eb72 - 1 waitchld - /bin/bash
    /usr/src/debug/bash-4.1/jobs.c:3064
#2  0x000000000043fe0f - 1 wait_for - /bin/bash
    /usr/src/debug/bash-4.1/jobs.c:2422
#3  0x00000000004309f9 - 1 execute_command_internal - /bin/bash
    /usr/src/debug/bash-4.1/execute_cmd.c:780
#4  0x0000000000430bee - 1 execute_command - /bin/bash
    /usr/src/debug/bash-4.1/execute_cmd.c:379
#5  0x000000000041d536 - 1 reader_loop - /bin/bash
    /usr/src/debug/bash-4.1/eval.c:153
#6  0x000000000041ccf9 - 1 main - /bin/bash
    /usr/src/debug/bash-4.1/shell.c:759
#7  0x00000033c821ed1d - 1 __libc_start_main - /lib64/libc-2.12.so
    /usr/src/debug/glibc-2.12-2-gc4ccff1/csu/libc-start.c:226
#8  0x000000000041af19 - 1 _start - /bin/bash

Thanks,

Mark
>From f3a3095ca205fcef8962ec7c0810b8b57bd24ecf Mon Sep 17 00:00:00 2001
From: Masatake YAMATO <yamato@redhat.com>
Date: Tue, 17 Dec 2013 12:03:29 +0900
Subject: [PATCH] stack: show binary and source file names where a function is defined

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
<jan.kratochvil@redhat.com>.

In v2 patch, `-s' and `-m' options are introduced instead
of using `-v' repeatedly as suggested by Mark Wielaard <mjw@redhat.com>.

In v3 patch `-a' is added as extra option and source lines are
printed on their own line.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog |   10 ++++++++
 src/stack.c   |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index f899858..77e4240 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2013-12-17  Masatake YAMATO  <yamato@redhat.com>
+	    Mark Wielaard  <mjw@redhat.com>
+
+	* stack.c (show_activation, show_module, show_source): New variables.
+	(parse_opt): Set show_activation if -a option is given.
+	Set show_module if -m option is given. Set show_source if -s option
+	is given. Set all show booleans when -v option is given.
+	(main): Added `-a', `-m', `-s', and `-v' to the help message.
+	(frame_callback): Print module and source file information.
+
 2013-11-25  Petr Machata  <pmachata@redhat.com>
 
 	* elflint.c (valid_e_machine): Add EM_AARCH64.
diff --git a/src/stack.c b/src/stack.c
index f428ed0..242d393 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -36,7 +36,9 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
 /* Bug report address.  */
 ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
 
-static bool verbose = false;
+static bool show_activation = false;
+static bool show_module = false;
+static bool show_source = false;
 
 static int
 frame_callback (Dwfl_Frame *state, void *arg)
@@ -76,9 +78,44 @@ frame_callback (Dwfl_Frame *state, void *arg)
     width = 16;
 
   printf ("#%-2u 0x%0*" PRIx64, (*framenop)++, width, (uint64_t) pc);
-  if (verbose)
+
+  if (show_activation)
     printf ("%4s", ! isactivation ? "- 1" : "");
-  printf (" %s\n", symname);
+
+  if (symname != NULL)
+    printf (" %s", symname);
+
+  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_source)
+    {
+      Dwfl_Line *lineobj = dwfl_module_getsrc(mod, pc_adjusted);
+      if (lineobj)
+	{
+	  int line, col;
+	  const char* sname;
+	  line = col = -1;
+	  sname = dwfl_lineinfo (lineobj, NULL, &line, &col, NULL, NULL);
+	  if (sname != NULL)
+	    {
+	      printf ("\n    %s", sname);
+	      if (line > 0)
+		{
+		  printf (":%d", line);
+		  if (col > 0)
+		    printf (":%d", col);
+		}
+	    }
+	}
+    }
+  printf ("\n");
   return DWARF_CB_OK;
 }
 
@@ -117,8 +154,20 @@ 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 'a':
+      show_activation = true;
+      break;
+
     case 'v':
-      verbose = true;
+      show_activation = show_source = show_module = true;
       break;
 
     default:
@@ -140,7 +189,14 @@ main (int argc, char **argv)
 
   const struct argp_option options[] =
     {
-      { "verbose", 'v', NULL, 0, N_("Additionally show frames activation"), 0 },
+      { "activation",  'a', NULL, 0,
+	N_("Additionally show frame 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_("Show all additional information (activation, module and source)"), 0 },
       { NULL, 0, NULL, 0, NULL, 0 }
     };
 
@@ -165,7 +221,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 [-a] [-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.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]