From patchwork Sat Nov 8 01:49:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 3620 Received: (qmail 3736 invoked by alias); 8 Nov 2014 01:49:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 3081 invoked by uid 89); 8 Nov 2014 01:49:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f201.google.com Received: from mail-pd0-f201.google.com (HELO mail-pd0-f201.google.com) (209.85.192.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 08 Nov 2014 01:49:33 +0000 Received: by mail-pd0-f201.google.com with SMTP id r10so728375pdi.4 for ; Fri, 07 Nov 2014 17:49:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=mdI+A+CkbGqVsDvAgTNpFxSqUwEP9PSC4E4xaTR86qw=; b=KDIjwqmcEBqPFvldHabVfPiaiaOlNb+6Djygtzbr1W0WtEFeXXXTfZq9RUquxJPyaL NQppdS+QVFAFxC0WxvZGXucS76gZlEc5k3ZoLKxmbC/YIYEVPRINO3n4fHHadjB+FSDx TLNig+78HPlYbbWv3J5AvWmMUStRDNkNfxXZgLXIiVu/3Ei8TdChOuX4ZhPiJd3PVz7J aMeHLSka0ElXHcTtjCTfBiPOBFy+MSIWG1ZhLP0/48Xt4E8JLZHtAo7EJla2gY3u0uNI s+hIx20cIFTQ4UBL9WBhBeMcG/56XAl3fZtZRIc7yyP+UGpfxcXT9JzxYi5AToiHCKIS DYuQ== X-Gm-Message-State: ALoCoQlp7prrhQjNiT+gCqCJjpGuyL9ttTs87EAl/hYj5NFq+MDOBKiBx/ZMK05yMdifnE3kWeDNCG3HB4tLSGHiAQtioTBJweDWv7qNooMhg+vvHxRlycN7w0iCnPpe00jVpVfLWDASzCtyTBkfUoN5GKL3rC994BpcOvxHYI0ZYCvaPYquYNo= X-Received: by 10.66.65.193 with SMTP id z1mr12155330pas.14.1415411371874; Fri, 07 Nov 2014 17:49:31 -0800 (PST) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n63si436303yho.5.2014.11.07.17.49.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Nov 2014 17:49:31 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTPS id b7QZHJZN.1; Fri, 07 Nov 2014 17:49:31 -0800 From: Doug Evans To: palves@redhat.com, uweigand@de.ibm.com, gdb-patches@sourceware.org Subject: [PATCH] create_internal_breakpoint: Apply gdbarch_skip_entrypoint. Date: Fri, 07 Nov 2014 17:49:30 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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 * breakpoint.c (create_internal_breakpoint): Apply gdbarch_skip_entrypoint if it's defined. sal.pspace = current_program_space; 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);