From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23131 invoked by alias); 25 Mar 2018 19:19:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22992 invoked by uid 89); 25 Mar 2018 19:19:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 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=stepped, nonnull, TEXT, non-null 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:53 +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 C3D87722D4 for ; Sun, 25 Mar 2018 19:19:51 +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 72E85202699A for ; Sun, 25 Mar 2018 19:19:51 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 11/15] Fix stepping past GNU ifunc resolvers (introduce lookup_msym_prefer) Date: Sun, 25 Mar 2018 19:19:00 -0000 Message-Id: <20180325191943.8246-12-palves@redhat.com> In-Reply-To: <20180325191943.8246-1-palves@redhat.com> References: <20180325191943.8246-1-palves@redhat.com> X-SW-Source: 2018-03/txt/msg00510.txt.bz2 When we're stepping (with "step"), we want to skip trampoline-like functions automatically, including GNU ifunc resolvers. That is done by infrun.c calling into: in_solib_dynsym_resolve_code -> svr4_in_dynsym_resolve_code -> in_gnu_ifunc_stub A problem here is that if there's a regular text symbol at the same address as the ifunc symbol, the minimal symbol lookup in in_gnu_ifunc_stub may miss the GNU ifunc symbol: (...) 41: 000000000000071a 53 FUNC GLOBAL DEFAULT 11 gnu_ifunc_resolver (...) 50: 000000000000071a 53 IFUNC GLOBAL DEFAULT 11 gnu_ifunc (...) This causes this FAIL in the tests added later in the series: (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: resolver received HWCAP set step-mode on (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: set step-mode on step 0x00007ffff7bd371a in gnu_ifunc_resolver () from build/gdb/testsuite/outputs/gdb.base/gnu-ifunc/gnu-ifunc-lib-1-0-0.so (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: step Above, GDB simply thought that it stepped into a regular function, so it stopped stepping, while it should have continued stepping past the resolver. The fix is to teach minimal symbol lookup to prefer GNU ifunc symbols if desired. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Rename to ... (lookup_minimal_symbol_by_pc_section): ... this. Replace 'want_trampoline' parameter by a lookup_msym_prefer parameter. Handle it. (lookup_minimal_symbol_by_pc_section): Delete old implementation. (lookup_minimal_symbol_by_pc): Adjust. (in_gnu_ifunc_stub): Prefer GNU ifunc symbols. (lookup_solib_trampoline_symbol_by_pc): Adjust. * minsyms.h (lookup_msym_prefer): New enum. (lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline' parameter by a lookup_msym_prefer parameter. --- gdb/minsyms.c | 77 ++++++++++++++++++++++++----------------------------------- gdb/minsyms.h | 26 +++++++++++++++++--- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index c75c316c08d..f71e2db484e 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -686,10 +686,9 @@ frob_address (struct objfile *objfile, CORE_ADDR *pc) there are text and trampoline symbols at the same address. Otherwise prefer mst_text symbols. */ -static struct bound_minimal_symbol -lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc_in, - struct obj_section *section, - int want_trampoline) +bound_minimal_symbol +lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *section, + lookup_msym_prefer prefer) { int lo; int hi; @@ -699,10 +698,27 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc_in, struct minimal_symbol *best_symbol = NULL; struct objfile *best_objfile = NULL; struct bound_minimal_symbol result; - enum minimal_symbol_type want_type, other_type; + enum minimal_symbol_type want_type; - want_type = want_trampoline ? mst_solib_trampoline : mst_text; - other_type = want_trampoline ? mst_text : mst_solib_trampoline; + if (section == NULL) + { + section = find_pc_section (pc_in); + if (section == NULL) + return {}; + } + + switch (prefer) + { + case lookup_msym_prefer::TEXT: + want_type = mst_text; + break; + case lookup_msym_prefer::TRAMPOLINE: + want_type = mst_solib_trampoline; + break; + case lookup_msym_prefer::GNU_IFUNC: + want_type = mst_text_gnu_ifunc; + break; + } /* We can not require the symbol found to be in section, because e.g. IRIX 6.5 mdebug relies on this code returning an absolute @@ -821,7 +837,7 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc_in, preceding symbol too. If they are otherwise identical prefer that one. */ if (hi > 0 - && MSYMBOL_TYPE (&msymbol[hi]) == other_type + && MSYMBOL_TYPE (&msymbol[hi]) != want_type && MSYMBOL_TYPE (&msymbol[hi - 1]) == want_type && (MSYMBOL_SIZE (&msymbol[hi]) == MSYMBOL_SIZE (&msymbol[hi - 1])) @@ -918,41 +934,12 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc_in, return result; } -struct bound_minimal_symbol -lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, struct obj_section *section) -{ - if (section == NULL) - { - /* NOTE: cagney/2004-01-27: This was using find_pc_mapped_section to - force the section but that (well unless you're doing overlay - debugging) always returns NULL making the call somewhat useless. */ - section = find_pc_section (pc); - if (section == NULL) - { - struct bound_minimal_symbol result; - - memset (&result, 0, sizeof (result)); - return result; - } - } - return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0); -} - /* See minsyms.h. */ struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR pc) { - struct obj_section *section = find_pc_section (pc); - - if (section == NULL) - { - struct bound_minimal_symbol result; - - memset (&result, 0, sizeof (result)); - return result; - } - return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0); + return lookup_minimal_symbol_by_pc_section (pc, NULL); } /* Return non-zero iff PC is in an STT_GNU_IFUNC function resolver. */ @@ -960,8 +947,9 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc) int in_gnu_ifunc_stub (CORE_ADDR pc) { - struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc); - + bound_minimal_symbol msymbol + = lookup_minimal_symbol_by_pc_section (pc, NULL, + lookup_msym_prefer::GNU_IFUNC); return msymbol.minsym && MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc; } @@ -1470,12 +1458,9 @@ terminate_minimal_symbol_table (struct objfile *objfile) static struct minimal_symbol * lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc) { - struct obj_section *section = find_pc_section (pc); - struct bound_minimal_symbol msymbol; - - if (section == NULL) - return NULL; - msymbol = lookup_minimal_symbol_by_pc_section_1 (pc, section, 1); + bound_minimal_symbol msymbol + = lookup_minimal_symbol_by_pc_section (pc, NULL, + lookup_msym_prefer::TRAMPOLINE); if (msymbol.minsym != NULL && MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline) diff --git a/gdb/minsyms.h b/gdb/minsyms.h index 6bd34a58058..0dab5874a18 100644 --- a/gdb/minsyms.h +++ b/gdb/minsyms.h @@ -240,6 +240,22 @@ struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline struct minimal_symbol *lookup_minimal_symbol_by_pc_name (CORE_ADDR, const char *, struct objfile *); +enum class lookup_msym_prefer +{ + /* Prefer mst_text symbols. */ + TEXT, + + /* Prefer mst_solib_trampoline symbols when there are text and + trampoline symbols at the same address. Otherwise prefer + mst_text symbols. */ + TRAMPOLINE, + + /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc + symbols at the same address. Otherwise prefer mst_text + symbols. */ + GNU_IFUNC, +}; + /* Search through the minimal symbol table for each objfile and find the symbol whose address is the largest address that is still less than or equal to PC, and which matches SECTION. @@ -248,11 +264,15 @@ struct minimal_symbol *lookup_minimal_symbol_by_pc_name instead. The result has a non-NULL 'minsym' member if such a symbol is - found, or NULL if PC is not in a suitable range. */ + found, or NULL if PC is not in a suitable range. + + See definition of lookup_msym_prefer for description of PREFER. By + default mst_text symbols are preferred. */ struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section - (CORE_ADDR, - struct obj_section *); + (CORE_ADDR, + struct obj_section *, + lookup_msym_prefer prefer = lookup_msym_prefer::TEXT); /* Backward compatibility: search through the minimal symbol table for a matching PC (no section given). -- 2.14.3