From patchwork Sun Mar 25 19:19:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26469 Received: (qmail 22731 invoked by alias); 25 Mar 2018 19:19:54 -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 22581 invoked by uid 89); 25 Mar 2018 19:19:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=locals, touched 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; Sun, 25 Mar 2018 19:19:50 +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 5D9134057287 for ; Sun, 25 Mar 2018 19:19:49 +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 0BF65202699A for ; Sun, 25 Mar 2018 19:19:48 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 07/15] Breakpoints, don't skip prologue of ifunc resolvers with debug info Date: Sun, 25 Mar 2018 20:19:35 +0100 Message-Id: <20180325191943.8246-8-palves@redhat.com> In-Reply-To: <20180325191943.8246-1-palves@redhat.com> References: <20180325191943.8246-1-palves@redhat.com> In v2: - The minsym/symbol matching in convert_linespec_to_sals is done differently. The v1 bsearch method wouldn't work for PPC64, given function descriptors. convert_linespec_to_sals will be touched again later in the series, for PPC64. - Moved declarations of locals closer to uses, because at some point I managed to reuse 'i' in an inner loop messing the outer loop... Without this patch, some of the tests added to gdb.base/gnu-ifunc.exp by a following patch fail like so: FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: info breakpoints All of them trigger iff: - you have debug info for the ifunc resolver. - the resolver and the user-visible symbol have the same name. If you have an ifunc that has a resolver with the same name as the user visible symbol, debug info for the resolver masks out the ifunc minsym. When you set a breakpoint by name on the user visible symbol, GDB finds the DWARF symbol for the resolver, and thinking that it's a regular function, sets a breakpoint location past its prologue. Like so, location 1.2, before the ifunc is resolved by the inferior: (gdb) break gnu_ifunc Breakpoint 2 at 0x7ffff7bd36ea (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 1.1 y 0x00007ffff7bd36ea 1.2 y 0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34 (gdb) And like so, location 2.2, if you set the breakpoint after the ifunc is resolved by the inferior (to "final"): (gdb) break gnu_ifunc Breakpoint 5 at 0x400757 (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y 2.1 y 0x000000000040075a in final at src/gdb/testsuite/gdb.base/gnu-ifunc-resd.c:21 2.2 y 0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34 (gdb) I don't think this is right because when users set a breakpoint at an ifunc, they don't care about debugging the resolver. Instead what you should is a single location for the ifunc in the first case, and a single location of the ifunc target in the second case. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linespec.c (struct bound_minimal_symbol_search_key): New. (convert_linespec_to_sals): Sort minimal symbols earlier. Don't skip first line if we found a GNU ifunc minimal symbol by name. (compare_msymbols): Change parameters to work with a destructured lhs minsym. (compare_msymbols_for_qsort, compare_msymbols_for_bsearch): New functions. --- gdb/linespec.c | 60 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index c549ba09349..70f23187e02 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2308,12 +2308,6 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) else if (ls->function_symbols != NULL || ls->minimal_symbols != NULL) { /* We have just a bunch of functions and/or methods. */ - int i; - struct symtab_and_line sal; - struct symbol *sym; - bound_minimal_symbol_d *elem; - struct program_space *pspace; - if (ls->function_symbols != NULL) { /* Sort symbols so that symbols with the same program space are next @@ -2322,30 +2316,66 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) VEC_length (symbolp, ls->function_symbols), sizeof (symbolp), compare_symbols); - for (i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i) + struct symbol *sym; + for (int i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i) { - pspace = SYMTAB_PSPACE (symbol_symtab (sym)); + program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym)); set_current_program_space (pspace); - if (symbol_to_sal (&sal, state->funfirstline, sym) - && maybe_add_address (state->addr_set, pspace, sal.pc)) - add_sal_to_sals (state, &sals, &sal, - SYMBOL_NATURAL_NAME (sym), 0); + + /* Don't skip to the first line of the function if we + had found an ifunc minimal symbol for this function, + because that means that this function is an ifunc + resolver with the same name as the ifunc itself. */ + bool found_ifunc = false; + + if (state->funfirstline + && ls->minimal_symbols != NULL + && SYMBOL_CLASS (sym) == LOC_BLOCK) + { + const CORE_ADDR addr + = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); + + bound_minimal_symbol_d *elem; + for (int m = 0; + VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols, + m, elem); + ++m) + { + if (MSYMBOL_TYPE (elem->minsym) == mst_text_gnu_ifunc + && BMSYMBOL_VALUE_ADDRESS (*elem) == addr) + { + found_ifunc = true; + break; + } + } + } + + if (!found_ifunc) + { + symtab_and_line sal; + if (symbol_to_sal (&sal, state->funfirstline, sym) + && maybe_add_address (state->addr_set, pspace, sal.pc)) + add_sal_to_sals (state, &sals, &sal, + SYMBOL_NATURAL_NAME (sym), 0); + } } } if (ls->minimal_symbols != NULL) { - /* Sort minimal symbols by program space, too. */ + /* Sort minimal symbols by program space, too */ qsort (VEC_address (bound_minimal_symbol_d, ls->minimal_symbols), VEC_length (bound_minimal_symbol_d, ls->minimal_symbols), sizeof (bound_minimal_symbol_d), compare_msymbols); - for (i = 0; + bound_minimal_symbol_d *elem; + + for (int i = 0; VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols, i, elem); ++i) { - pspace = elem->objfile->pspace; + program_space *pspace = elem->objfile->pspace; set_current_program_space (pspace); minsym_found (state, elem->objfile, elem->minsym, &sals); }