From patchwork Wed Jan 18 15:30:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63343 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 406EE385B520 for ; Wed, 18 Jan 2023 15:31:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 406EE385B520 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674055897; bh=6hVVcxskqY/Cv13lpqL8djMXmfdGyLmMX/QvcQz8pwo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x6sM3OmSowXbiQl8qY7D0Z8Fg+PEm7wLLfFogk9nStW5hKardKWzBJ1J3Dl4Jsi+n XDl8kD2TNjl/hbDqBrTP29hcgxpdfp2YtKOpul30V9Bg2JZH+IoFMdy1KnwNzfFgKw M+8Zc6ZnOYyVP5Re6RbepxFWCifUcQ7LkFcOuthY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 523FC3858291 for ; Wed, 18 Jan 2023 15:30:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 523FC3858291 Received: by mail-il1-x133.google.com with SMTP id i17so12331637ila.9 for ; Wed, 18 Jan 2023 07:30:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6hVVcxskqY/Cv13lpqL8djMXmfdGyLmMX/QvcQz8pwo=; b=xoXWS1DtAAOSXC6sQbd+a4Qd3feFGigFrMf012cyndg1LTroqjP7znP00VkWQPTjSL u8jYvPIvLID3GAfC+xQ7lQbRYY6J7O3IMautX+eA0znWeygwySZ9wnuhqdkRpAMnTeHF a9KvKf7hAQguTSVU5Y6mWVhMet/WwMsx67nW6KZuekx8iyxON+HopfB5I0xHhAQgHaC6 RPevG8RKaEsKac/M0pJLkGzdxsSnLT9KSZ571j46yqpgSTOroE+LvLgOzlgXe6qQHZOg /DSxrWqId2R6CfCFmHd9RPMVycCKcGyIhPzcklan6M7hy0d4GJc3bm/vrrTPr5ZcioT6 K+Fw== X-Gm-Message-State: AFqh2kqOuiYGuIagCY1R+pRCybv3BDmRRNlce3mzX3JPeJ5tdpE48jpi 3u2GnOqSE6PN0UBcjRsZRyOWr118SqqFQIFB X-Google-Smtp-Source: AMrXdXsyTe9nmLvl55XxxWOqaQ42ZhcrXtAYEwUar3bUkxzC1RDQhYy/Bg2Pq/SL77jLmFOBA6PQfw== X-Received: by 2002:a92:c94a:0:b0:30e:4d3d:3aae with SMTP id i10-20020a92c94a000000b0030e4d3d3aaemr5874822ilq.1.1674055840539; Wed, 18 Jan 2023 07:30:40 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id m4-20020a056e020de400b0030bf2476c5fsm10106502ilj.25.2023.01.18.07.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:30:40 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/6] Merge fixup_section and fixup_symbol_section Date: Wed, 18 Jan 2023 08:30:25 -0700 Message-Id: <20230118153025.342512-7-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230118153025.342512-1-tromey@adacore.com> References: <20230118153025.342512-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" fixup_symbol_section delegates all its work to fixup_section, so merge the two. Because there is only a single caller to fixup_symbol_section, we can also remove some of the introductory logic. For example, this will never be called with a NULL objfile any more. The LOC_BLOCK case can be removed, because such symbols are handled by the buildsym code now. Finally, it a symbol can only appear in a SEC_ALLOC section, so the loop is modified to skip sections that do not have this flag set. --- gdb/symtab.c | 103 +++++++++++++++++++-------------------------------- gdb/symtab.h | 8 +++- 2 files changed, 45 insertions(+), 66 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 2d3aafd140a..82d6bc28795 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1701,14 +1701,39 @@ symtab_free_objfile_observer (struct objfile *objfile) symbol_cache_flush (objfile->pspace); } -/* Debug symbols usually don't have section information. We need to dig that - out of the minimal symbols and stash that in the debug symbol. */ +/* See symtab.h. */ -static void -fixup_section (struct general_symbol_info *ginfo, - CORE_ADDR addr, struct objfile *objfile, - int default_section) +void +fixup_symbol_section (struct symbol *sym, struct objfile *objfile) { + gdb_assert (sym != nullptr); + gdb_assert (sym->is_objfile_owned ()); + gdb_assert (objfile != nullptr); + gdb_assert (sym->section_index () == -1); + + /* Note that if this ends up as -1, fixup_section will handle that + reasonably well. So, it's fine to use the objfile's section + index without doing the check that is done by the wrapper macros + like SECT_OFF_TEXT. */ + int fallback; + switch (sym->aclass ()) + { + case LOC_STATIC: + fallback = objfile->sect_index_data; + break; + + case LOC_LABEL: + fallback = objfile->sect_index_text; + break; + + default: + /* Nothing else will be listed in the minsyms -- no use looking + it up. */ + return; + } + + CORE_ADDR addr = sym->value_address (); + struct minimal_symbol *msym; /* First, check whether a minimal symbol with the same name exists @@ -1716,10 +1741,10 @@ fixup_section (struct general_symbol_info *ginfo, e.g. on PowerPC64, where the minimal symbol for a function will point to the function descriptor, while the debug symbol will point to the actual function code. */ - msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->linkage_name (), + msym = lookup_minimal_symbol_by_pc_name (addr, sym->linkage_name (), objfile); if (msym) - ginfo->set_section_index (msym->section_index ()); + sym->set_section_index (msym->section_index ()); else { /* Static, function-local variables do appear in the linker @@ -1758,10 +1783,12 @@ fixup_section (struct general_symbol_info *ginfo, a search of the section table. */ struct obj_section *s; - int fallback = default_section; ALL_OBJFILE_OSECTIONS (objfile, s) { + if ((bfd_section_flags (s->the_bfd_section) & SEC_ALLOC) == 0) + continue; + int idx = s - objfile->sections; CORE_ADDR offset = objfile->section_offsets[idx]; @@ -1770,7 +1797,7 @@ fixup_section (struct general_symbol_info *ginfo, if (s->addr () - offset <= addr && addr < s->endaddr () - offset) { - ginfo->set_section_index (idx); + sym->set_section_index (idx); return; } } @@ -1779,64 +1806,12 @@ fixup_section (struct general_symbol_info *ginfo, section. If there is no allocated section, then it hardly matters what we pick, so just pick zero. */ if (fallback == -1) - ginfo->set_section_index (0); + sym->set_section_index (0); else - ginfo->set_section_index (fallback); + sym->set_section_index (fallback); } } -struct symbol * -fixup_symbol_section (struct symbol *sym, struct objfile *objfile) -{ - CORE_ADDR addr; - - if (!sym) - return NULL; - - if (!sym->is_objfile_owned ()) - return sym; - - /* We either have an OBJFILE, or we can get at it from the sym's - symtab. Anything else is a bug. */ - gdb_assert (objfile || sym->symtab ()); - - if (objfile == NULL) - objfile = sym->objfile (); - - if (sym->obj_section (objfile) != nullptr) - return sym; - - /* We should have an objfile by now. */ - gdb_assert (objfile); - - /* Note that if this ends up as -1, fixup_section will handle that - reasonably well. So, it's fine to use the objfile's section - index without doing the check that is done by the wrapper macros - like SECT_OFF_TEXT. */ - int default_section = objfile->sect_index_text; - switch (sym->aclass ()) - { - case LOC_STATIC: - default_section = objfile->sect_index_data; - /* FALLTHROUGH. */ - case LOC_LABEL: - addr = sym->value_address (); - break; - case LOC_BLOCK: - addr = sym->value_block ()->entry_pc (); - break; - - default: - /* Nothing else will be listed in the minsyms -- no use looking - it up. */ - return sym; - } - - fixup_section (sym, addr, objfile, default_section); - - return sym; -} - /* See symtab.h. */ demangle_for_lookup_info::demangle_for_lookup_info diff --git a/gdb/symtab.h b/gdb/symtab.h index ac3f6391dc3..50b801830c7 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2394,8 +2394,12 @@ extern void skip_prologue_sal (struct symtab_and_line *); extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr); -extern struct symbol *fixup_symbol_section (struct symbol *, - struct objfile *); +/* If SYM requires a section index, find it either via minimal symbols + or examining OBJFILE's sections. Note that SYM's current address + must not have any runtime offsets applied. */ + +extern void fixup_symbol_section (struct symbol *sym, + struct objfile *objfile); /* If MSYMBOL is an text symbol, look for a function debug symbol with the same address. Returns NULL if not found. This is necessary in