Signed-off-by: Mark Wielaard <m...@redhat.com> --- libdwfl/ChangeLog | 5 +++++ libdwfl/linux-pid-attach.c | 21 +++++++++++++++++++++ src/ChangeLog | 4 ++++ src/stack.c | 2 ++ 4 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 723ea71..8a164f0 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-12-23 Mark Wielaard <m...@redhat.com> + + * linux-pid-attach.c (__libdwfl_attach_state_for_pid): Report actual + pid (thread group leader) to dwfl_attach_state. + 2013-12-21 Mark Wielaard <m...@redhat.com> * linux-pid-attach.c (struct pid_arg): New field should_detach. diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index 1e1ccfa..232a3de 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -301,6 +301,27 @@ bool internal_function __libdwfl_attach_state_for_pid (Dwfl *dwfl, pid_t pid) { + char buffer[36]; + FILE *procfile; + + /* Make sure to report the actual PID (thread group leader) to + dwfl_attach_state. */ + snprintf (buffer, sizeof (buffer), "/proc/%ld/status", (long) pid); + procfile = fopen (buffer, "r"); + if (procfile == NULL) + return false; + + while (fgets (buffer, sizeof (buffer), procfile) != NULL) + if (strncmp (buffer, "Tgid:", 5) == 0) + { + pid = atoi (&buffer[5]); + break; + } + fclose (procfile); + + if (pid == 0) + return false; + char dirname[64]; int i = snprintf (dirname, sizeof (dirname), "/proc/%ld/task", (long) pid); assert (i > 0 && i < (ssize_t) sizeof (dirname) - 1); diff --git a/src/ChangeLog b/src/ChangeLog index ea30556..0f1b971 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2013-12-23 Mark Wielaard <m...@redhat.com> + * stack.c (main): Print pid of process or core. + +2013-12-23 Mark Wielaard <m...@redhat.com> + * stack.c (OPT_DEBUGINFO): New define. (OPT_COREFILE): Likewise. (pid): New static. diff --git a/src/stack.c b/src/stack.c index 3b0d767..dfb0272 100644 --- a/src/stack.c +++ b/src/stack.c @@ -376,6 +376,7 @@ main (int argc, char **argv) if (show_one_tid) { + printf ("TID %d:\n", pid); switch (dwfl_getthread_frames (dwfl, pid, frame_callback, frames)) { case DWARF_CB_OK: @@ -391,6 +392,7 @@ main (int argc, char **argv) } else { + printf ("PID %d - %s\n", dwfl_pid (dwfl), pid != 0 ? "process" : "core"); switch (dwfl_getthreads (dwfl, thread_callback, frames)) { case DWARF_CB_OK: -- 1.7.1