From: Pedro Alves <palves@redhat.com>
To: Yao Qi <yao@codesourcery.com>
Cc: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [patch 1/8] Generalize interaction with agent in gdb/gdbserver
Date: Tue, 14 Feb 2012 10:16:00 -0000 [thread overview]
Message-ID: <4F3A344D.7080003@redhat.com> (raw)
In-Reply-To: <4F39C9B3.9010005@codesourcery.com>
On 02/14/2012 02:40 AM, Yao Qi wrote:
> On 02/10/2012 03:20 AM, Pedro Alves wrote:
>>>> +#ifdef GDBSERVER
>>>> + /* Need to read response with the inferior stopped. */
>>>> + if (!ptid_equal (ptid, null_ptid))
>>>> + {
>>>> + int was_non_stop = non_stop;
>>>> + struct target_waitstatus status;
>>>> + struct thread_resume resume_info;
>>>> +
>>>> + /* Stop thread PTID. */
>>>> + resume_info.thread = ptid;
>>>> + resume_info.kind = resume_stop;
>>>> + resume_info.sig = TARGET_SIGNAL_0;
>>>> + (*the_target->resume) (&resume_info, 1);
>>>> +
>>>> + non_stop = 1;
>>>> + mywait (ptid, &status, 0, 0);
>>>> + non_stop = was_non_stop;
>>>> + }
>>>> +#endif
>> Since there's no #else, I take it you haven't really tried using this
>> on GDB, without gdbserver?
>>
>
> I thought this part can be removed.
Then that would be a separate change.
> The intention of this part is to really stop "debugging thread", so it is safe
> to read from command buffer later. We don't have "debugging thread" stopped,
> because the synchronization of read and write is controlled by socket. When
> we get here, after reading one byte from socket, "debugging thread" has
> finished executing command, and write return result in command buffer.
> It is being blocked by reading from socket, even it is not stopped.
> GDB/GDBserver can safely read contents out of command buffer without
> having to stop "debugging thread". Am I missing something here?
It's not really about "safeness". With ptrace or /proc/PID/mem, you can only read
memory from the inferior is it is ptrace-stopped (stopped by a signal, breakpoint, etc.).
From ptrace's perpective, even if the thread is blocked reading from a socket,
the thread is running. Trying to read memory while the thread is running results in
error. Now, what is happening is that we're actually not reading the command
buffer with the helper thread selected as current thread, but instead we're reading
memory through the thread that was selected at run_inferior_command entry (which is
the thread you have selected in GDB). And that happens to be stopped. Try selecting
the helper thread instead:
(gdb) t 3
[Switching to thread 3 (Thread 22463)]
#0 0x0000000000396223 in ?? ()
(gdb) info static-tracepoint-markers
Cnt ID Enb Address What
Remote failure reply: E.UST library not loaded in process. Static tracepoints unavailable.
(gdb)
and things break.
Even if you don't do that, removing that bit breaks gdbserver's track of what is stopped
or not. Vis:
(gdb) b main
Breakpoint 1 at 0x400aa6: file ../../../src/gdb/testsuite/gdb.trace/strace.c, line 29.
(gdb) c
Continuing.
Breakpoint 1,
main () at ../../../src/gdb/testsuite/gdb.trace/strace.c:29
29 int a = 0;
(gdb) info static-tracepoint-markers
Cnt ID Enb Address What
1 metadata/core_marker_format n 0x00007ffff7bb7692
Data: "channel %s name %s format %s"
2 metadata/core_marker_format n 0x00007ffff7bb8897
Data: "channel %s name %s format %s"
3 metadata/core_marker_id n 0x00007ffff7bb957d
Data: "channel %s name %s event_id %hu int #1u%zu long #1u%zu pointer #1u%zu size_t #1u%zu alignment #1u%u"
4 metadata/core_marker_id n 0x00007ffff7bb9a04
Data: "channel %s name %s event_id %hu int #1u%zu long #1u%zu pointer #1u%zu size_t #1u%zu alignment #1u%u"
5 metadata/core_marker_id n 0x00007ffff7bbb006
Data: "channel %s name %s event_id %hu int #1u%zu long #1u%zu pointer #1u%zu size_t #1u%zu alignment #1u%u"
6 metadata/core_marker_format n 0x00007ffff7bbb235
Data: "channel %s name %s format %s"
7 ust/potential_exec n 0x00007ffff7bd8240
Data: " "
8 ust/bar n 0x0000000000400ab3 in main at ../../../src/gdb/testsuite/gdb.trace/strace.c:32
Data: "str %s"
9 ust/bar2 n 0x0000000000400afb in main at ../../../src/gdb/testsuite/gdb.trace/strace.c:33
Data: "number1 %d number2 %d"
10 ust/dummymark n 0x0000000000400b6c
Data: " "
(gdb) info threads
[New Thread 22690]
[New Thread 22691]
Id Target Id Frame
3 Thread 22691 0x0000000000653023 in ?? ()
2 Thread 22690 0x000000339e6e6af3 in __GI___poll (fds=<optimized out>, nfds=<optimized out>, timeout=<optimized out>) at ../sysdeps/unix/sysv/linux/poll.c:87
* 1 Thread 22681 main () at ../../../src/gdb/testsuite/gdb.trace/strace.c:29
(gdb)
Look at what's shown in gdbserver's console:
Listening on port 9999
Remote debugging from host 127.0.0.1
ptrace(regsets_fetch_inferior_registers) PID=22691: No such process
ptrace(regsets_fetch_inferior_registers) PID=22691: No such process
"No such process" also means "the process exists but was not stopped".
$ cat /proc/22681/task/*/status | grep State
State: t (tracing stop)
State: t (tracing stop)
State: S (sleeping)
That is, gdbserver got confused and tried to read registers from 22691 thinking it was
stopped, but it wasn't. And 22691 is thread 3, which is the helper thread.
Things go downhill from here.
> I get rid of this part from its original place (gdbserver/tracepoint.c),
> and run gdb.trace/strace.exp. Results look unchanged.
For the reasons explained above.
--
Pedro Alves
next prev parent reply other threads:[~2012-02-14 10:16 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 13:37 [patch 0/8] GDB/GDBserver talks with agents Yao Qi
2012-01-23 13:48 ` [patch 1/8] Generalize interaction with agent in gdb/gdbserver Yao Qi
2012-01-30 11:25 ` Yao Qi
2012-02-09 19:21 ` Pedro Alves
2012-02-14 2:41 ` Yao Qi
2012-02-14 10:16 ` Pedro Alves [this message]
2012-01-23 13:50 ` [patch 2/8] Add to_use_agent in target_ops Yao Qi
2012-02-09 19:36 ` Pedro Alves
2012-01-23 13:54 ` [patch 3/8] Command `set agent on|off' Yao Qi
2012-01-23 17:14 ` Eli Zaretskii
2012-01-24 0:28 ` Yao Qi
2012-01-24 5:54 ` Eli Zaretskii
2012-01-26 1:32 ` Yao Qi
2012-02-09 20:19 ` Pedro Alves
2012-01-23 13:58 ` [patch 4/8] `use_agent' for remote and QAgent Yao Qi
2012-01-23 17:17 ` Eli Zaretskii
2012-01-26 2:17 ` Yao Qi
2012-01-26 17:43 ` Eli Zaretskii
2012-02-09 19:55 ` Pedro Alves
2012-01-23 14:03 ` [patch 5/8] Doc for agent Yao Qi
2012-01-23 18:12 ` Eli Zaretskii
2012-01-24 0:51 ` Yao Qi
2012-01-24 8:04 ` Eli Zaretskii
2012-01-26 1:53 ` Yao Qi
2012-01-26 17:15 ` Eli Zaretskii
2012-02-09 19:55 ` Pedro Alves
2012-02-10 13:30 ` Yao Qi
2012-02-10 15:01 ` Pedro Alves
2012-02-10 16:18 ` Yao Qi
2012-02-10 16:28 ` Pedro Alves
2012-02-23 7:51 ` Yao Qi
2012-02-23 19:50 ` Pedro Alves
2012-01-23 14:07 ` [patch 6/8] Agent's capability Yao Qi
2012-01-24 3:49 ` Yao Qi
2012-02-09 20:09 ` Pedro Alves
2012-02-10 12:25 ` Yao Qi
2012-02-10 12:37 ` Pedro Alves
2012-02-10 13:07 ` Yao Qi
2012-01-23 14:29 ` [patch 7/8] Agent capability for static tracepoint Yao Qi
2012-02-09 20:13 ` Pedro Alves
2012-02-10 14:29 ` Yao Qi
2012-02-10 14:56 ` Pedro Alves
2012-01-23 16:03 ` [patch 8/8] Control agent in testsuite Yao Qi
2012-02-09 20:16 ` Pedro Alves
2012-02-05 4:32 ` [ping] [patch 0/8] GDB/GDBserver talks with agents Yao Qi
2012-02-09 19:02 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F3A344D.7080003@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=yao@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox