From: Ivo Raisr <ivosh@ivosh.net>
To: gdb@sourceware.org
Subject: Re: Multi-packet gdb server request/response - problem?
Date: Thu, 12 Dec 2013 15:44:00 -0000 [thread overview]
Message-ID: <CANXv6=tByX3xbrKU-uiZwshHVW9k5NcWP5Etd+QDwCU7qe-wFw@mail.gmail.com> (raw)
In-Reply-To: <CANXv6=uV5H9M17qLkSZ+VpX6AqzBBnXRSmK4g1yNyTyExw3SCA@mail.gmail.com>
Hello guys!
After some hackery I think I understand a tiny bit of how remote
support works in gdb.
Request packet "s" ("c") is sent as a part of resume() as can be seen
from the following truss excerpt:
------------------
...
-> remote_serial_write(0xffff80ffbfffef60, 0x5, 0x0, 0x0,
0x18, 0x203a74656b636170)
-> serial_write(0xc195a0, 0xffff80ffbfffef60, 0x5, 0x0,
0x18, 0x203a74656b636170)
-> ser_base_write(0xc195a0, 0xffff80ffbfffef60, 0x5,
0x0, 0x18, 0x203a74656b636170)
-> ser_unix_write_prim(0xc195a0,
0xffff80ffbfffef60, 0x5, 0x0, 0x18, 0x203a74656b636170)
write(9, " $ s # 7 3", 5) = 5
<- ser_unix_write_prim() = 5
<- serial_write() = 0
<- remote_serial_write() = 0
<- putpkt() = 0
<- remote_resume() = 0
...
------------------
However code in resume() does not actively wait for the response.
It is assumed (I think) that target_wait() will do the response handling.
And it initially does, because it does the following:
------------------
for (t = current_target.beneath; t != NULL; t = t->beneath)
{
if (t->to_wait != NULL)
{
ptid_t retval = (*t->to_wait) (t, ptid, status, options);
...
------------------
Initially t->to_wait() is simply remote_wait() which indeed reads the response
packet and parses it.
At some point in the debugging session (not sure when but it does not matter),
I think gdb kicks in the OS-specific functions. For solaris, they are
found in sol-thread.c.
And t->to_wait() is no longer simple remote_wait() but is sol_thread_wait().
At this point, things go awry.
sol_thread_wait() contains the following stuff:
------------------
save_ptid = inferior_ptid;
old_chain = save_inferior_ptid ();
inferior_ptid = thread_to_lwp (inferior_ptid, PIDGET (main_ph.ptid));
if (PIDGET (inferior_ptid) == -1)
inferior_ptid = procfs_first_available ();
...
rtnval = beneath->to_wait (beneath, ptid, ourstatus, options);
------------------
The old remote_wait() function is hidden in the call of "beneath->to_wait()".
However the problem here is that thread_to_lwp() which precedes it is called
_before_ "beneath->to_wait()". And thread_to_lwp() invokes (among others)
target_read_memory() which in turn sends "m" request packet...
Looking at other *-thread.c sources (BSD, DEC, AIX etc.) they usually contain
call to "beneath->to_wait()" as their first thing. So I think the
logic in sol_thread_wait()
is flawed in that "beneath->to_wait()" is not called "early" enough.
I quickly hacked function sol_thread_wait() and removed all calls to
thread_to_lwp()
preceding "beneath->to_wait()". And the conversation with remote stub
is working now!
But now the ptid->lwp conversion is not done properly...
Anyone has any idea of how to overcome this flaw in sol_thread_wait()?
I.
next prev parent reply other threads:[~2013-12-12 15:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 12:23 Ivo Raisr
2013-12-10 21:46 ` Philippe Waroquiers
[not found] ` <CANXv6=vFYfEDLPVHv_TRK4VTLmFX6c+2hvmodM9dg3gcJA4_jQ@mail.gmail.com>
2013-12-12 15:14 ` Fwd: " Ivo Raisr
2013-12-12 15:44 ` Ivo Raisr [this message]
2013-12-12 16:46 ` Pedro Alves
2013-12-11 11:43 ` Yao Qi
2013-12-14 3:39 Ivo Raisr
2013-12-16 14:31 ` 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='CANXv6=tByX3xbrKU-uiZwshHVW9k5NcWP5Etd+QDwCU7qe-wFw@mail.gmail.com' \
--to=ivosh@ivosh.net \
--cc=gdb@sourceware.org \
/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