From patchwork Fri Mar 9 21:16:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26267 Received: (qmail 73502 invoked by alias); 9 Mar 2018 21:22:31 -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 73490 invoked by uid 89); 9 Mar 2018 21:22:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=1b X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 21:22:30 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A817BD142C for ; Fri, 9 Mar 2018 21:16:20 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59EA62026DFD for ; Fri, 9 Mar 2018 21:16:20 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 11/11] Fix resolving GNU ifunc bp locations when inferior runs resolver Date: Fri, 9 Mar 2018 21:16:12 +0000 Message-Id: <20180309211612.12941-12-palves@redhat.com> In-Reply-To: <20180309211612.12941-1-palves@redhat.com> References: <20180309211612.12941-1-palves@redhat.com> I noticed that if you set a breakpoint on an ifunc before the ifunc is resolved, and then let the program call the ifunc, thus resolving it, GDB end up with a location for that original breakpoint that is pointing to the ifunc target, but it is left pointing to the first address of the function, instead of after its prologue. After prologue is what you get if you create a new breakpoint at that point. 1) With no debug info for the target function: 1.a) Set before resolving, and then program continued passed resolving: Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000400753 1.b) Breakpoint set after inferior resolved ifunc: Num Type Disp Enb Address What 2 breakpoint keep y 0x0000000000400757 2) With debug info for the target function: 1.a) Set before resolving, and then program continued passed resolving: Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000400753 in final at gdb/testsuite/gdb.base/gnu-ifunc-resd.c:20 1.b) Breakpoint set after inferior resolved ifunc: Num Type Disp Enb Address What 2 breakpoint keep y 0x000000000040075a in final at gdb/testsuite/gdb.base/gnu-ifunc-resd.c:21 The problem is that elf_gnu_ifunc_resolver_return_stop (called by the internal breakpoint that traps the resolver returning) does not agree with linespec.c:minsym_found. It does not skip to the function's start line (i.e., past the prologue). We can now use the find_function_start_sal overload added by the previous commmit to fix this. New tests included, which fail before the patch, and pass afterwards. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * elfread.c (elf_gnu_ifunc_resolver_return_stop): Use find_function_start_sal instead of find_pc_line. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves ifunc breakpoint locations correctly of ifunc breakpoints set while the program resolves the ifunc. --- gdb/elfread.c | 3 ++- gdb/testsuite/gdb.base/gnu-ifunc.exp | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gdb/elfread.c b/gdb/elfread.c index 454b77e9bdc..0cb404186ff 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -990,7 +990,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b) b->type = bp_breakpoint; update_breakpoint_locations (b, current_program_space, - find_pc_line (resolved_pc, 0), {}); + find_function_start_sal (resolved_pc, NULL, true), + {}); } /* A helper function for elf_symfile_read that reads the minimal diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp index fa1464bec51..c936aba7c14 100644 --- a/gdb/testsuite/gdb.base/gnu-ifunc.exp +++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp @@ -108,6 +108,9 @@ proc_with_prefix set-break {resolver_attr resolver_debug resolved_debug} { return 1 } + gdb_breakpoint [gdb_get_line_number "break-at-call"] + gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*" + set ws "\[ \t\]+" if {$resolver_attr} { @@ -122,19 +125,21 @@ proc_with_prefix set-break {resolver_attr resolver_debug resolved_debug} { "Breakpoint $decimal at gnu-indirect-function resolver at $hex" gdb_test "info breakpoints" \ "$decimal${ws}STT_GNU_IFUNC resolver${ws}keep${ws}y${ws}$hex <${gnu_ifunc_resolver}>" + + # Make the breakpoint conditional on a condition that always + # fails. This is so that when the ifunc-resolver breakpoint + # triggers, GDB resumes the program immediately. + gdb_test_no_output "condition \$bpnum 0" } global resdsrc with_test_prefix "resolve" { - delete_breakpoints gdb_breakpoint [gdb_get_line_number "break-at-exit"] gdb_continue_to_breakpoint "break-at-exit" ".*break-at-exit.*" } with_test_prefix "after resolving" { - delete_breakpoints - if {!$resolved_debug} { # Set a breakpoint both at the ifunc, and at the ifunc's # target. GDB should resolve both to the same address. @@ -167,7 +172,12 @@ proc_with_prefix set-break {resolver_attr resolver_debug resolved_debug} { gdb_test "break gnu_ifunc" "Breakpoint .* at $hex: file .*$resdsrc, line $lineno\\." set location "$decimal${ws}breakpoint${ws}keep${ws}y${ws}$hex in final at .*$resdsrc:$lineno" } - gdb_test "info breakpoints" "$location\r\n$location" + + # The first location here is for the breakpoint that was set + # before the ifunc was resolved. It should be resolved by + # now, and it should have the exact same address/line as the + # other two locations. + gdb_test "info breakpoints" "$location\r\n.*$location\r\n$location" } }