diff options
| author | Mark Wielaard <[email protected]> | 2013-12-20 10:09:12 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2013-12-23 22:57:22 +0100 |
| commit | e962ec3bcbe8eccdcded36aaafee7bec41fa1bc4 (patch) | |
| tree | d250cd9aecff3f8e539b301398027b1fc0a25c46 /src | |
| parent | b6ef1ce4695cea00d097c7fcac8d0014ff01a5bf (diff) | |
libdwfl: Add dwfl_getthread_frames.
dwfl_getthread_frames is a convenience function for when the user is only
interested in one specific thread id of a process. It can be implemented by
a simple wrapper function that removes an extra callback layer just to
filter on thread id. But it also provides an optimized path to getting
access to just one particular Dwfl_Thread of the Dwfl process by providing
and (optional) new callback for the state provider. The pid_thread_callbacks
now provide an (optional) pid_getthread that doesn't need to travers all
threads anymore. Which is implemented for the linux-pid-attach provider.
stack now uses this to implement a new '-1' option that shows just one
specific thread of a process.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/stack.c | 46 |
2 files changed, 43 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 5722a50c..0e6d2dc5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2013-12-20 Mark Wielaard <[email protected]> + + * stack.c (show_one_tid): New static boolean. + (parse_opt): Handle '-1'. + (main): Add -1 to options. Call dwfl_getthread_frames when + show_one_tid is true. + 2013-12-18 Mark Wielaard <[email protected]> * addr2line.c (options): Add symbol-sections, 'x'. diff --git a/src/stack.c b/src/stack.c index 242d3930..512c85b4 100644 --- a/src/stack.c +++ b/src/stack.c @@ -39,6 +39,7 @@ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT; static bool show_activation = false; static bool show_module = false; static bool show_source = false; +static bool show_one_tid = false; static int frame_callback (Dwfl_Frame *state, void *arg) @@ -170,6 +171,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)), show_activation = show_source = show_module = true; break; + case '1': + show_one_tid = true; + break; + default: return ARGP_ERR_UNKNOWN; } @@ -197,6 +202,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 }, + { NULL, '1', NULL, 0, + N_("Show the backtrace of only one thread"), 0 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -221,23 +228,42 @@ 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] [--debuginfo-path=<path>] {-p <process id>|" - "--core=<file> [--executable=<file>]|--help}"); + error (2, 0, "eu-stack [-a] [-m] [-s] [-v] [-1] [--debuginfo-path=<path>]" + " {-p <process id>|--core=<file> [--executable=<file>]|--help}"); /* dwfl_linux_proc_report has been already called from dwfl_standard_argp's parse_opt function. */ if (dwfl_report_end (dwfl, NULL, NULL) != 0) error (2, 0, "dwfl_report_end: %s", dwfl_errmsg (-1)); - switch (dwfl_getthreads (dwfl, thread_callback, NULL)) + if (show_one_tid) { - case DWARF_CB_OK: - break; - case -1: - error (0, 0, "dwfl_getthreads: %s", dwfl_errmsg (-1)); - break; - default: - abort (); + pid_t tid = dwfl_pid (dwfl); + unsigned frameno = 0; + switch (dwfl_getthread_frames (dwfl, tid, frame_callback, &frameno)) + { + case DWARF_CB_OK: + break; + case -1: + error (0, 0, "dwfl_getthread_frames (%d): %s", tid, + dwfl_errmsg (-1)); + break; + default: + abort (); + } + } + else + { + switch (dwfl_getthreads (dwfl, thread_callback, NULL)) + { + case DWARF_CB_OK: + break; + case -1: + error (0, 0, "dwfl_getthreads: %s", dwfl_errmsg (-1)); + break; + default: + abort (); + } } dwfl_end (dwfl); |
