diff options
author | Mark Wielaard <mjw@redhat.com> | 2013-12-23 14:20:06 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2013-12-25 22:24:56 +0100 |
commit | 97bbf9b7ca002aab236bf750aba699d81f7985f7 (patch) | |
tree | e817c431270bb134dc7abf18a423ccda48b77a36 /libdwfl | |
parent | 3e98ab73f31ed35fcd83e0e1a01147a559d1858b (diff) | |
download | elfutils-97bbf9b7ca002aab236bf750aba699d81f7985f7.tar.gz |
libdwfl: linux-pid-attach.c: Report actual PID (Tgid) to dwfl_attach_state.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 5 | ||||
-rw-r--r-- | libdwfl/linux-pid-attach.c | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 13a4ff9d..8e50f2f2 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-12-23 Mark Wielaard <mjw@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 <mjw@redhat.com> * frame_unwind.c (handle_cfi): Track whether the return register diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index 2e1d3592..70bd666a 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -285,6 +285,30 @@ 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; + + char *line = NULL; + size_t linelen = 0; + while (getline (&line, &linelen, procfile) >= 0) + if (strncmp (line, "Tgid:", 5) == 0) + { + pid = atoi (&line[5]); + break; + } + free (line); + 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); |