From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AU6YI3COamn5pQYAWB0awg (envelope-from ) for ; Fri, 16 Jan 2026 14:16:00 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=G6TLuzeX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8D83D1E08D; Fri, 16 Jan 2026 14:16:00 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id CE3A81E08D for ; Fri, 16 Jan 2026 14:15:59 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D25754BA23E7 for ; Fri, 16 Jan 2026 19:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D25754BA23E7 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=G6TLuzeX Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 35CCE4BA2E3A for ; Fri, 16 Jan 2026 19:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35CCE4BA2E3A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 35CCE4BA2E3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768590696; cv=none; b=qzcAHYEX0mQCKiLvCJk4PzxzZGkAva3QuXix0md9kfoLMp2Yx/7rqIVZt0Cd8LJObzkrJYTJZ9bDMigNfx+97uSE5CXnfuwXGGndRSihXIl3G3+Iqh54DOqkWEpUfnc5clGWvDS8be/XVe54nSrfvUXnMCJUMCWYuu1iTPX7Lbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768590696; c=relaxed/simple; bh=sQkV+IwkdAQrQllFYkInw9dSGE6BTmxL9NkGkBZx/Y0=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=oRXyzWD/GLn+aiQ+Kh1Pd2Evu2zIBrHiJTLPjF/IXWEgoXKdND7FHTZGhaXTJvDSCQgpZS01QUHHXav5lFvDZfRN4mWcKlIqx7hq9GnHeU0/fhYsPbZUs9iIxaPua21AXYvZPwDF6mX7s7IjrSPaIwBat52mU3TRr8Q/o5kO+y8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35CCE4BA2E3A Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-7cfd57f0bf7so1444804a34.3 for ; Fri, 16 Jan 2026 11:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1768590695; x=1769195495; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=p/qxD+SK+lzlGjtzBdYvz93lMRbYXLpoWTQM0LDrxJo=; b=G6TLuzeX5wlozHBIEwXxs/amsEKMl/VLc5nrVtISeI4c5aPK6s8+K2sYDbneLlIwi3 +Y+oS+ZET59sGfLQJlXkWL2M6TOJBQGOJ2ruvC8ogVprfR24NNDXXV/6Q7kst/egGraV zmopvEe6zwvRZCOe3QEKhVUKw3KMlYyOD13yKuClWwN4sh5jNU9FRk5KtZMrh8JneeKR 5m1rSJos07PghKWcgdZBWCN39CNgb1rm7b8KoWKTEU45QhX7jTANq7PnZ9S0wvkXDa5f 80oXtx7CRuOvzQCWZeCs7XBOwSrVZW7A1seZ8+OpGSg2x1ycSfLqtJdvqqC2gTAMC/7w 9x1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768590695; x=1769195495; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=p/qxD+SK+lzlGjtzBdYvz93lMRbYXLpoWTQM0LDrxJo=; b=uuQxdPyg265l+JGooe+W/lrxmFc3Z7ZQkydrJgVHdBfOtlEuIoYQJ9PJAMj2U5Reu+ GmZ1yv8Rrj4tQThbp4UkiWDoKj6s3duFUv0s8f1sbJ20eWkUUMlOaSDqtVEZBx7f1jMY KBEVsPuc6krYfMfN86R16aF0Bc2Zij/j/Kbf4mzccZBQ3zRz6uiJOd3r8mqDEXQFzzJ6 3dnlwzFimvJgSuaCIyJT0elufIMdMvS8RryufTUiiMsB1YsUEqhaD7nA6rzCwCbNSKHw aKRJ/eHF4T6FZK729zqs0M7MvJbSaU9E52Uf2+UrkonqzsiBACHo6a1V4Ox4ZkyoSSDa xC0Q== X-Gm-Message-State: AOJu0Yx3TnI/5n7zcRBjMG+bPUr/FYPYbMefEdRsQzFp+LBAK2fHIg/4 xVskCSQnOwVy5wl3m7JlQcJ5d0zK6br7rCVIx6EhAs11g1JlKBzAZ20VLjBShshU+3qfumjugib jTG8= X-Gm-Gg: AY/fxX6uSrWhB8qwH28rHeCN/72MrNw9D/h/T4zrtCcHoFTklHJ70qdLwFl/aOYE2ZW zkz8k6xeJbjf2Jz12C4Lc/SOwgitGzftT+17ellT9G+Hmo7coz7ebFbD8reJFLGqkdPQYVGYH84 RzorQgPbrYUzocOIlRHenYPrw6o2QsrDSni2OuZFU+2rEbQnir7LtLno7GW4/aaDXjeIhCbwuy4 px5fIaolwvqUjXVUD2gSdmUUPvI+nVyt7y37mRsWJkCcPEVfy6DYUj2gHp4BJzTWSacaKWVEc5N +4MwVXnb1v9wVSKh9Rxd6YpKDBy/OnbDpw6b8lA/CoOJuFKtHern5gHbw79qhPpc4Yr9T87Ngir QYEbiQleWB7em9f6Xt5NFEHDgqdKAvwZ2VU+o0f3Dwf74BjIgbkpDD14/xBn67AQ7Uo9uLKu+Qk MvI3/rOhl1MOONg/HcL1R8QQlprRh23dQBifnYRGrX6Q== X-Received: by 2002:a05:6830:6738:b0:7cf:cbec:293f with SMTP id 46e09a7af769-7cfdee6ac0cmr1842439a34.27.1768590695344; Fri, 16 Jan 2026 11:11:35 -0800 (PST) Received: from [192.168.0.26] (97-122-114-32.hlrn.qwest.net. [97.122.114.32]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cfdf0db2c1sm2196681a34.5.2026.01.16.11.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 11:11:34 -0800 (PST) From: Tom Tromey Date: Fri, 16 Jan 2026 12:11:35 -0700 Subject: [PATCH 07/10] Use coffread_objfile throughout coffread.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260116-coffread-cleanups-v1-7-4d46090fad69@adacore.com> References: <20260116-coffread-cleanups-v1-0-4d46090fad69@adacore.com> In-Reply-To: <20260116-coffread-cleanups-v1-0-4d46090fad69@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org coffread.c:coff_symtab_read sets a global objfile while working. It seemed nicer to me to hoist this so that it is set by the main entry point, and then used throughout the file. Normally I wouldn't encourage the use of globals, but shortly we'll be replacing these with an object. Note that while coff_symtab_read cleared coffread_objfile when it was finished, I haven't preserved this in the new patch. First, this should have been done with a scoped_restore. Second, this is the only global to get this treatment. Third, it's not necessary at all. And, finally, this will be moot anyway when the globals are removed. --- gdb/coffread.c | 63 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 5cbbf490937..67fe6483087 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -91,8 +91,7 @@ static int init_stringtab (file_ptr, gdb::unique_xmalloc_ptr *); static void read_one_sym (struct coff_symbol *); -static void coff_symtab_read (minimal_symbol_reader &, - file_ptr, unsigned int, struct objfile *); +static void coff_symtab_read (minimal_symbol_reader &, file_ptr, unsigned int); /* Return the BFD section that CS points to. */ @@ -108,12 +107,12 @@ cs_to_bfd_section (struct coff_symbol *cs) /* Return the section number (SECT_OFF_*) that CS points to. */ static int -cs_to_section (struct coff_symbol *cs, struct objfile *objfile) +cs_to_section (struct coff_symbol *cs) { asection *sect = cs_to_bfd_section (cs); if (sect == NULL) - return SECT_OFF_TEXT (objfile); + return SECT_OFF_TEXT (coffread_objfile); return gdb_bfd_section_index (symfile_bfd, sect); } @@ -166,8 +165,7 @@ is_import_fixup_symbol (struct coff_symbol *cs, static struct minimal_symbol * record_minimal_symbol (minimal_symbol_reader &reader, struct coff_symbol *cs, unrelocated_addr address, - enum minimal_symbol_type type, int section, - struct objfile *objfile) + enum minimal_symbol_type type, int section) { /* We don't want TDESC entry points in the minimal symbol table. */ if (cs->c_name[0] == '@') @@ -206,29 +204,28 @@ coff_symfile_init (struct objfile *objfile) symbols. It may also read other forms of symbol as well. */ static void -coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms, - struct objfile *objfile) +coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms) { /* If minimal symbols were already read, and if we know we aren't going to read any other kind of symbol here, then we can just return. */ - if (objfile->per_bfd->minsyms_read && pe_file && nsyms == 0) + if (coffread_objfile->per_bfd->minsyms_read && pe_file && nsyms == 0) return; - minimal_symbol_reader reader (objfile); + minimal_symbol_reader reader (coffread_objfile); if (pe_file && nsyms == 0) { /* We've got no debugging symbols, but it's a portable executable, so try to read the export table. */ - read_pe_exported_syms (reader, objfile); + read_pe_exported_syms (reader, coffread_objfile); } else { /* Now that the executable file is positioned at symbol table, process it and define symbols accordingly. */ - coff_symtab_read (reader, symtab_offset, nsyms, objfile); + coff_symtab_read (reader, symtab_offset, nsyms); } /* Install any minimal symbols that have been collected as the @@ -238,7 +235,7 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms, if (pe_file) { - for (minimal_symbol *msym : objfile->msymbols ()) + for (minimal_symbol *msym : coffread_objfile->msymbols ()) { const char *name = msym->linkage_name (); @@ -263,7 +260,7 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms, bound_minimal_symbol found = lookup_minimal_symbol (current_program_space, name1, - objfile); + coffread_objfile); /* If found, there are symbols named "_imp_foo" and "foo" respectively in OBJFILE. Set the type of symbol "foo" @@ -282,6 +279,7 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms, static void coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) { + coffread_objfile = objfile; symfile_bfd = objfile->obfd.get (); coff_data_type *cdata = coff_data (symfile_bfd); const char *filename = bfd_get_filename (symfile_bfd); @@ -328,9 +326,9 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) if (val < 0) error (_("\"%s\": can't get string table"), filename); - coff_read_minsyms (symtab_offset, num_symbols, objfile); + coff_read_minsyms (symtab_offset, num_symbols); - if (!(objfile->flags & OBJF_READNEVER)) + if (!(coffread_objfile->flags & OBJF_READNEVER)) { bool found_stab_section = false; @@ -345,18 +343,18 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) warning (_ ("stabs debug information is not supported.")); } - if (dwarf2_initialize_objfile (objfile)) + if (dwarf2_initialize_objfile (coffread_objfile)) { /* Nothing. */ } /* Try to add separate debug file if no symbols table found. */ - else if (!objfile->has_partial_symbols () - && objfile->separate_debug_objfile == NULL - && objfile->separate_debug_objfile_backlink == NULL) + else if (!coffread_objfile->has_partial_symbols () + && coffread_objfile->separate_debug_objfile == NULL + && coffread_objfile->separate_debug_objfile_backlink == NULL) { - if (objfile->find_and_add_separate_symbol_file (symfile_flags)) - gdb_assert (objfile->separate_debug_objfile != nullptr); + if (coffread_objfile->find_and_add_separate_symbol_file (symfile_flags)) + gdb_assert (coffread_objfile->separate_debug_objfile != nullptr); } } @@ -367,10 +365,9 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) static void coff_symtab_read (minimal_symbol_reader &reader, - file_ptr symtab_offset, unsigned int nsyms, - struct objfile *objfile) + file_ptr symtab_offset, unsigned int nsyms) { - struct gdbarch *gdbarch = objfile->arch (); + struct gdbarch *gdbarch = coffread_objfile->arch (); struct coff_symbol coff_symbol; struct coff_symbol *cs = &coff_symbol; int val; @@ -383,9 +380,7 @@ coff_symtab_read (minimal_symbol_reader &reader, val = bfd_seek (symfile_bfd, symtab_offset, 0); if (val < 0) error (_("Error reading symbols from %s: %s"), - objfile_name (objfile), bfd_errmsg (bfd_get_error ())); - - coffread_objfile = objfile; + objfile_name (coffread_objfile), bfd_errmsg (bfd_get_error ())); while (symnum < nsyms) { @@ -398,14 +393,14 @@ coff_symtab_read (minimal_symbol_reader &reader, { /* Record all functions -- external and static -- in minsyms. */ - int section = cs_to_section (cs, objfile); + int section = cs_to_section (cs); tmpaddr = cs->c_value; /* Don't record unresolved symbols. */ if (!(cs->c_secnum <= 0 && cs->c_value == 0)) record_minimal_symbol (reader, cs, unrelocated_addr (tmpaddr), - mst_text, section, objfile); + mst_text, section); continue; } @@ -468,14 +463,14 @@ coff_symtab_read (minimal_symbol_reader &reader, /* Use the correct minimal symbol type (and don't relocate) for absolute values. */ ms_type = mst_abs; - sec = cs_to_section (cs, objfile); + sec = cs_to_section (cs); tmpaddr = cs->c_value; } else { asection *bfd_section = cs_to_bfd_section (cs); - sec = cs_to_section (cs, objfile); + sec = cs_to_section (cs); tmpaddr = cs->c_value; if (bfd_section->flags & SEC_CODE) @@ -505,7 +500,7 @@ coff_symtab_read (minimal_symbol_reader &reader, msym = record_minimal_symbol (reader, cs, unrelocated_addr (tmpaddr), - ms_type, sec, objfile); + ms_type, sec); if (msym) gdbarch_coff_make_msymbol_special (gdbarch, cs->c_sclass, msym); @@ -513,8 +508,6 @@ coff_symtab_read (minimal_symbol_reader &reader, break; } } - - coffread_objfile = NULL; } /* Routines for reading headers and symbols from executable. */ -- 2.52.0