diff mbox

create_internal_breakpoint: Apply gdbarch_skip_entrypoint.

Message ID yjt2fvdu5umt.fsf@ruffy.mtv.corp.google.com
State New
Headers show

Commit Message

Doug Evans Nov. 8, 2014, 1:49 a.m. UTC
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.

   sal.pspace = current_program_space;
diff mbox

Patch

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);