From: Doug Evans <dje@google.com>
To: palves@redhat.com, uweigand@de.ibm.com, gdb-patches@sourceware.org
Subject: [PATCH] create_internal_breakpoint: Apply gdbarch_skip_entrypoint.
Date: Sat, 08 Nov 2014 01:49:00 -0000 [thread overview]
Message-ID: <yjt2fvdu5umt.fsf@ruffy.mtv.corp.google.com> (raw)
Hi.
In glibc, _dl_debug_state is usually defined like this:
void
_dl_debug_state (void)
{
}
and thus on powerpc64le-linux this function does not require a TOC register.
This is important because the toolchain will optimize intra-module calls
to skip the first two instructions that set up the TOC register.
And since gdb currently doesn't to "entry point skipping" for internal
breakpoints things work (in particular shlib event breakpoints).
But, if one happens to put something in _dl_debug_state that needs
the TOC register, its caller will enter the function at
_dl_debug_state + 8, but gdb will set its shlib breakpoint
at _dl_debug_state + 0, and shlib tracking stops working.
This patch fixes things by applying entry point skipping to
internal breakpoints. Is this the best place to apply entry point
skipping for internal breakpoints?
Here's a hacky testcase to see the problem.
I haven't put any time into trying to turn it into something
that can be committed.
---snip---
int x;
void
_ovly_debug_event (void)
{
x = 42;
}
int
main ()
{
_ovly_debug_event ();
return 0;
}
---snip---
With unpatched gdb:
(gdb) start
Temporary breakpoint 1 at 0x10000768: file ovly-debug-event.c, line 13.
Starting program: /home/dje/src/play/ovly-debug-event.x
Temporary breakpoint 1, main () at ovly-debug-event.c:13
13 _ovly_debug_event ();
(gdb) mt i br
Num Type Disp Enb Address What
-3 shlib events keep y 0x00003fffb7fd8e40 <__GI__dl_debug_state> inf 1
-5 overlay events keep n 0x0000000010000710 <_ovly_debug_event> inf 1
(gdb) disas _ovly_debug_event
Dump of assembler code for function _ovly_debug_event:
0x0000000010000710 <+0>: addis r2,r12,2
0x0000000010000714 <+4>: addi r2,r2,-31528
0x0000000010000718 <+8>: ...
...
(gdb) disas main
Dump of assembler code for function main:
0x000000001000074c <+0>: addis r2,r12,2
0x0000000010000750 <+4>: addi r2,r2,-31588
...
=> 0x0000000010000768 <+28>: bl 0x10000718 <_ovly_debug_event+8>
...
Note that the "overlay events" breakpoint won't be hit because main calls
_ovly_debug_event after the two insns that set up the TOC register.
With a patched gdb:
(gdb) start
Temporary breakpoint 1 at 0x10000768: file ovly-debug-event.c, line 13.
Starting program: /home/dje/src/play/ovly-debug-event.x
Temporary breakpoint 1, main () at ovly-debug-event.c:13
13 _ovly_debug_event ();
(gdb) mt i br
Num Type Disp Enb Address What
-3 shlib events keep y 0x0000100000020e48 <__GI__dl_debug_state+8> inf 1
-6 overlay events keep n 0x0000000010000718 <_ovly_debug_event+8> inf 1
Note that the "overlay events" breakpoint is now at an instruction
that will get executed.
2014-11-07 Doug Evans <dje@google.com>
* breakpoint.c (create_internal_breakpoint): Apply
gdbarch_skip_entrypoint if it's defined.
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index bd51f5d..1b5cf5f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3306,6 +3306,9 @@ create_internal_breakpoint (struct gdbarch
*gdbarch,
init_sal (&sal); /* Initialize to zeroes. */
+ if (gdbarch_skip_entrypoint_p (gdbarch))
+ address = gdbarch_skip_entrypoint (gdbarch, address);
+
sal.pc = address;
sal.section = find_pc_overlay (sal.pc);
sal.pspace = current_program_space;
next reply other threads:[~2014-11-08 1:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-08 1:49 Doug Evans [this message]
2014-11-08 1:57 ` Doug Evans
2014-11-10 12:58 ` Ulrich Weigand
2014-11-10 15:45 ` Pedro Alves
2014-11-10 17:16 ` Ulrich Weigand
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=yjt2fvdu5umt.fsf@ruffy.mtv.corp.google.com \
--to=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=uweigand@de.ibm.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