* [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
@ 2013-10-01 9:50 Joel Brobecker
2013-10-01 9:57 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2013-10-01 9:50 UTC (permalink / raw)
To: gdb-patches
Hello,
The current implementation is forgetting to populate the thread list
when attaching to the process. This results in an incomplete list of
threads when debugging a threaded program.
Unfortunately, as the added comments hints, there appears to be
no way of getting the list of threads via ptrace, other than by
spawning the "ps" command, and parsing its output. Not great,
but it appears to be the best we can do. This method was actually
inspired by looking at old code which did exactly that.
gdb/gdbserver/ChangeLog:
* lynx-low.c (lynx_add_threads_after_attach): New function.
(lynx_attach): Remove call to add_thread. Add call to
lynx_add_threads_after_attach instead.
Tested on various LynxOS platforms. OK to commit?
Thanks,
--
Joel
---
gdb/gdbserver/lynx-low.c | 38 +++++++++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index 3c75b62..09c214e 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -262,6 +262,42 @@ lynx_create_inferior (char *program, char **allargs)
return pid;
}
+/* Assuming we've just attached to a running inferior whose pid is PID,
+ add all threads runnnig in that process. */
+
+static void
+lynx_add_threads_after_attach (int pid)
+{
+ /* Ugh! There appears to be no way to get the list of threads
+ in the program we just attached to. So get the list by calling
+ the "ps" command. This is only needed now, as we will then
+ keep the thread list up to date thanks to thread creation and
+ exit notifications. */
+ FILE *f;
+ char buf[256];
+ int thread_pid, thread_tid;
+
+ f = popen ("ps atx", "r");
+ if (f == NULL)
+ perror_with_name ("Cannot get thread list");
+
+ while (fgets (buf, sizeof (buf), f) != NULL)
+ if ((sscanf (buf, "%d %d", &thread_pid, &thread_tid) == 2
+ && thread_pid == pid))
+ {
+ ptid_t thread_ptid = lynx_ptid_build (pid, thread_tid);
+
+ if (!find_thread_ptid (thread_ptid))
+ {
+ lynx_debug ("New thread: (pid = %d, tid = %d)",
+ pid, thread_tid);
+ add_thread (thread_ptid, NULL);
+ }
+ }
+
+ pclose (f);
+}
+
/* Implement the attach target_ops method. */
static int
@@ -274,7 +310,7 @@ lynx_attach (unsigned long pid)
strerror (errno), errno);
lynx_add_process (pid, 1);
- add_thread (ptid, NULL);
+ lynx_add_threads_after_attach (pid);
return 0;
}
--
1.7.0.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
2013-10-01 9:50 [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach Joel Brobecker
@ 2013-10-01 9:57 ` Pedro Alves
2013-10-01 10:02 ` Joel Brobecker
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-01 9:57 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On 10/01/2013 10:50 AM, Joel Brobecker wrote:
> Hello,
>
> The current implementation is forgetting to populate the thread list
> when attaching to the process. This results in an incomplete list of
> threads when debugging a threaded program.
>
> Unfortunately, as the added comments hints, there appears to be
> no way of getting the list of threads via ptrace, other than by
> spawning the "ps" command, and parsing its output. Not great,
> but it appears to be the best we can do. This method was actually
> inspired by looking at old code which did exactly that.
Huh. I didn't really look at the patch yet, but, then, how
does "ps" manage to work? If you strace "ps", what system calls
is it using? I'd imagine if not ptrace, then it would be reading
/proc or some such?
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
2013-10-01 9:57 ` Pedro Alves
@ 2013-10-01 10:02 ` Joel Brobecker
2013-10-01 10:16 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2013-10-01 10:02 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> > Unfortunately, as the added comments hints, there appears to be
> > no way of getting the list of threads via ptrace, other than by
> > spawning the "ps" command, and parsing its output. Not great,
> > but it appears to be the best we can do. This method was actually
> > inspired by looking at old code which did exactly that.
>
> Huh. I didn't really look at the patch yet, but, then, how
> does "ps" manage to work? If you strace "ps", what system calls
> is it using? I'd imagine if not ptrace, then it would be reading
> /proc or some such?
I can look. But what strongly detered me from doing that is the fact
that it'd be starting to use unpublished interfaces. Running "ps"
isn't pretty, but I can hope it'll keep working across versions of
Lynx (we tested against Lynx 178 and 5.x, knowing that this has worked
with 4.x as well).
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
2013-10-01 10:02 ` Joel Brobecker
@ 2013-10-01 10:16 ` Pedro Alves
2013-10-01 10:52 ` Joel Brobecker
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-01 10:16 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On 10/01/2013 11:02 AM, Joel Brobecker wrote:
>>> Unfortunately, as the added comments hints, there appears to be
>>> no way of getting the list of threads via ptrace, other than by
>>> spawning the "ps" command, and parsing its output. Not great,
>>> but it appears to be the best we can do. This method was actually
>>> inspired by looking at old code which did exactly that.
>>
>> Huh. I didn't really look at the patch yet, but, then, how
>> does "ps" manage to work? If you strace "ps", what system calls
>> is it using? I'd imagine if not ptrace, then it would be reading
>> /proc or some such?
>
> I can look. But what strongly detered me from doing that is the fact
> that it'd be starting to use unpublished interfaces.
Well, how are you sure they're unpublished, if you don't know
at least approximately which interfaces it's using? (reading /proc,
using ptrace+peeking at program memory, etc.) ;-) I've really no
clue on the ABI garantees copying newer/older "ps" to an older/newer
system would have, but I'd expect it to have some.
BTW, was that "old code" the old native gdb port?
> Running "ps" isn't pretty, but I can hope it'll keep working across versions of
> Lynx (we tested against Lynx 178 and 5.x, knowing that this has worked
> with 4.x as well).
It's hard to believe such a basic feature would go missing from
a public debug API :-(, but I can't say I really object to the patch.
If it works for you...
> +/* Assuming we've just attached to a running inferior whose pid is PID,
> + add all threads runnnig in that process. */
"running".
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
2013-10-01 10:16 ` Pedro Alves
@ 2013-10-01 10:52 ` Joel Brobecker
2013-10-01 11:33 ` Pedro Alves
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2013-10-01 10:52 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> Well, how are you sure they're unpublished, if you don't know
> at least approximately which interfaces it's using? (reading /proc,
> using ptrace+peeking at program memory, etc.) ;-) I've really no
> clue on the ABI garantees copying newer/older "ps" to an older/newer
> system would have, but I'd expect it to have some.
That's true. In the end, I wasn't able to get that piece of information,
as I could not find a tool on LynxOS that can trace system calls.
There is no /proc, and I couldn't find anything in /dev that seems
related to that sort of thing.
> BTW, was that "old code" the old native gdb port?
I must have been confused somewhere. It was for sure a gdbserver port,
which I thought I had completely removed in order to make room for
an implementation-from-scratch. I haven't looked at the sources in
a long time, and the only reason I mention them is because I saw that
hack when I first worked on the LynxOS gdbserver, and the first thing
I did was get rid of it, to see if it was useful in any way.
> It's hard to believe such a basic feature would go missing from
> a public debug API :-(, but I can't say I really object to the patch.
> If it works for you...
I was convinced too. But I've read many times the man page, and looked
at ptrace.h for the beginning of a way that might work, and couldn't
find anything.
> > +/* Assuming we've just attached to a running inferior whose pid is PID,
> > + add all threads runnnig in that process. */
>
> "running".
Thanks. I will fix that before checking in.
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach
2013-10-01 10:52 ` Joel Brobecker
@ 2013-10-01 11:33 ` Pedro Alves
0 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2013-10-01 11:33 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On 10/01/2013 11:52 AM, Joel Brobecker wrote:
>> Well, how are you sure they're unpublished, if you don't know
>> at least approximately which interfaces it's using? (reading /proc,
>> using ptrace+peeking at program memory, etc.) ;-) I've really no
>> clue on the ABI garantees copying newer/older "ps" to an older/newer
>> system would have, but I'd expect it to have some.
>
> That's true. In the end, I wasn't able to get that piece of information,
> as I could not find a tool on LynxOS that can trace system calls.
> There is no /proc, and I couldn't find anything in /dev that seems
> related to that sort of thing.
We could always ask the LynxOS folks (lynuxworks.com it seems), if we wanted
to bother, I guess. Oh well, I personally don't care that much.
>>> +/* Assuming we've just attached to a running inferior whose pid is PID,
>>> + add all threads runnnig in that process. */
>>
>> "running".
>
> Thanks. I will fix that before checking in.
Thanks.
--
Pedro Alves
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-01 11:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-01 9:50 [RFA/gdbserver/LynxOS]: Incomplete thread list after --attach Joel Brobecker
2013-10-01 9:57 ` Pedro Alves
2013-10-01 10:02 ` Joel Brobecker
2013-10-01 10:16 ` Pedro Alves
2013-10-01 10:52 ` Joel Brobecker
2013-10-01 11:33 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).