From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SXjWLMKOamn5pQYAWB0awg (envelope-from ) for ; Fri, 16 Jan 2026 14:17:22 -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=S6GFhhc/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B2DF61E08D; Fri, 16 Jan 2026 14:17:22 -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 626071E08D for ; Fri, 16 Jan 2026 14:17:21 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 6F4A84B9DB40 for ; Fri, 16 Jan 2026 19:17:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F4A84B9DB40 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=S6GFhhc/ Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id C78FD4BA23D2 for ; Fri, 16 Jan 2026 19:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C78FD4BA23D2 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 C78FD4BA23D2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768590698; cv=none; b=lbmI23vuerLj6NEbpNlegXGLZbxGOySUyOQ/TuApc1rgCxGyIP0B59XgRXk5cSe0dwE1AIcAVt9yhPYDJKmC3L6+GWFLByt9qirm8DHRRUOL2R3QtJYfXInZ5O+uAdirl7d7JecdSzSXHdT27qtl5HkUEChO6X7zSl/hvn7lkM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768590698; c=relaxed/simple; bh=QYjblsMmwwddUs68g4h4EwRciVBdDu9vHATRb/ejFFU=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=xNcBpyUVQJWHM/DeL+BIFGKeUXNo8ZeKBGzCuMKIpYmbk7Jt13ychEAoa8q4gcVS2sfXY3yOCwlSk3aIIyWGLS9+LG5dpYbysuFiDbIZz19vdvEWwQE+RlL/rfvJiBv2qSD/XiLf6zRzdlWjnHKcTHD+3BZWPxtV8H1PLqSesSU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C78FD4BA23D2 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7cfd57f0bf7so1444821a34.3 for ; Fri, 16 Jan 2026 11:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1768590698; x=1769195498; 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=JoQNtT1bb3JMWuKPhfiyLfG/VfseCY7VFwaoNfHPCr8=; b=S6GFhhc/aOxwXF599HIrvf9UMQnuVhQeuoqEdSMFyfXCK/Gw1afCIFL3nT0AXFZ0Tm o9GwbR6/JnufpVINKkeQjArCKxKOdAF466DunIY4AgirrQ4WqQYzVhklzRe7VnCZMzA5 s4sz0ntcyhUnnHZymUWxtjxkoNj7B+N9c0szTq0L5BZSiaJRi+AZJjzq156n4+N+7BdA zPhlnb9ptxklnO12DXfL80mJpDl2HPxGC1r/xqUAsP1jLxbxnAZvSPRA99U01qnQrtgf 0dGjsHcOZqSZkvWXcvxSTbkQZVeacqev+MaxXK8HZckFWr015WwqlrtXPqX0h47xKjKc md+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768590698; x=1769195498; 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=JoQNtT1bb3JMWuKPhfiyLfG/VfseCY7VFwaoNfHPCr8=; b=u5mGdI+lKweVyqepJD8rjM5aEPwqmsPpYaMg83WtIt8qOqaTZtfaeRF8ess6aaUGc4 2gvDY+hyHauKFK9fbB2x0DsJycAmcHlYKr4Er+Go1hurPkuzZFro/Uq7GMyCXKGOvTW7 vD9w2z4Mza1V3FoWV3VOtiNg0QlT4ZWCHyHgOicV4cU+HILEI2Ch2DaoSoUSCUYHL3w3 7kk/ednvRFWY2xatwlX+UaaKeCs+6LLZFf0esdfQEFRrpR4abQsK1NauTcCAnxtTZW+o B0V2883sR3NjY/E19FMPW9tekstm4EATpxFwHcBGhrQI09f9+1WsODEHkgq8KM7QpWzv qVQw== X-Gm-Message-State: AOJu0Yyn92bsu3ivGAPpaHEiNK9bi/OZ/aEQv4GGtr45SoFXkqbPmMKn 44BXG16knu0emO6xDnY76rPUmWzStejotqzuWez3RlqpVn9mvFAg7KroPgFCM9T4Xw== X-Gm-Gg: AY/fxX4E+H3t4aEhd169raSB77tj2THEl5bLBhEFhy8gCTvC++BQJK7JkiBmZIRlVps U5w2LIDB31+HQWo1tPJc4ueTS1yNaG2EA5abauTyIyT0yyz+Hjbr1wbBhs5llHVWRFfDk+8wams iEKn4xuo1/pvVKu2KlJsutHY8gEujoanZ7TsiziV7N8Bgg/EiRM13xBXtVWrC+ofVpbQZDFHbn6 muTBrmBLabKFW57YdJDuwKJjnIQ7bm5qcBNiAOC4iBG3O0j8Vqs/aSbt/6LNr93gUC1G4IW7WIr GZu1YOM4pU60lFslY10L4734+a5kZsvnnuq2RoTeKQUFRECOcdgXabbcxNmwP5dHM4fJnOgt9Pv ucTVd7o5PZdXmbrd7NICKEBwygzwhppKIRX7r+rKw2azbEIDOe6GoG/OnV69EoFpdK7oALnd0E2 oW6rTkzIT2rWFQyw+w5rwGEIK34yk58zkFM3t9WGNH2A== X-Received: by 2002:a05:6830:6507:b0:7cf:ced8:b5cf with SMTP id 46e09a7af769-7cfdee3da44mr1874924a34.26.1768590696581; Fri, 16 Jan 2026 11:11:36 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 11:11:36 -0800 (PST) From: Tom Tromey Date: Fri, 16 Jan 2026 12:11:37 -0700 Subject: [PATCH 09/10] Remove all globals from coffread.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260116-coffread-cleanups-v1-9-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 This patch changes coffread.c to add a reader object type. All globals are moved into this type, and the majority of functions in coffread.c are changed to be methods. --- gdb/coffread.c | 178 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 77 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 5ea2d940faa..9716bdceaec 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -28,44 +28,6 @@ #include "dwarf2/public.h" #include "coff-pe-read.h" -/* The objfile we are currently reading. */ - -static struct objfile *coffread_objfile; - -/* The BFD for this file -- only good while we're actively reading - symbols into a psymtab or a symtab. */ - -static bfd *symfile_bfd; - -/* Pointers to scratch storage, used for reading raw symbols and - auxents. */ - -static char *temp_sym; -static char *temp_aux; - -/* Local variables that hold the shift and mask values for the - COFF file that we are currently reading. These come back to us - from BFD, and are referenced by their macro names, as well as - internally to the ISFCN macro from include/coff/internal.h . */ - -static unsigned local_n_btshft; -static unsigned local_n_tmask; - -#define N_BTSHFT local_n_btshft -#define N_TMASK local_n_tmask - -/* Local variables that hold the sizes in the file of various COFF - structures. (We only need to know this to read them from the file - -- BFD will then translate the data in them, into `internal_xxx' - structs in the right byte order, alignment, etc.) */ - -static unsigned local_symesz; -static unsigned local_auxesz; - -/* This is set if this is a PE format file. */ - -static bool pe_file; - /* Simplified internal version of coff symbol table information. */ struct coff_symbol @@ -79,24 +41,79 @@ struct coff_symbol unsigned int c_type; }; -static char *stringtab = NULL; -static long stringtab_length = 0; +/* A class that reads symbols from a COFF file. */ +struct coff_reader +{ + explicit coff_reader (objfile *objfile) + : coffread_objfile (objfile), + symfile_bfd (objfile->obfd.get ()) + { + } + + /* Do the work of reading. */ + void symfile_read (symfile_add_flags symfile_flags); -/* Used when reading coff symbols. */ -static int symnum; +private: -static const char *getsymname (struct internal_syment *); + /* The objfile we are currently reading. */ + objfile *coffread_objfile; -static int init_stringtab (file_ptr, gdb::unique_xmalloc_ptr *); + /* The BFD for this file. */ + bfd *symfile_bfd; -static void read_one_sym (struct coff_symbol *); + /* Pointers to scratch storage, used for reading raw symbols and + auxents. */ + char *temp_sym; + char *temp_aux; -static void coff_symtab_read (minimal_symbol_reader &, file_ptr, unsigned int); + /* Local variables that hold the shift and mask values for the + COFF file that we are currently reading. These come back to us + from BFD, and are referenced by their macro names, as well as + internally to the ISFCN macro from include/coff/internal.h . */ + unsigned local_n_btshft; + unsigned local_n_tmask; + +#define N_BTSHFT local_n_btshft +#define N_TMASK local_n_tmask + + /* Local variables that hold the sizes in the file of various COFF + structures. (We only need to know this to read them from the file + -- BFD will then translate the data in them, into `internal_xxx' + structs in the right byte order, alignment, etc.) */ + unsigned local_symesz; + unsigned local_auxesz; + + /* This is set if this is a PE format file. */ + bool pe_file; + + char *stringtab = NULL; + long stringtab_length = 0; + + /* Used when reading coff symbols. */ + int symnum; + + asection *cs_to_bfd_section (coff_symbol *cs); + int cs_to_section (coff_symbol *cs); + CORE_ADDR cs_section_address (coff_symbol *cs); + int is_import_fixup_symbol (coff_symbol *cs, minimal_symbol_type type); + minimal_symbol *record_minimal_symbol (minimal_symbol_reader &reader, + coff_symbol *cs, + unrelocated_addr address, + minimal_symbol_type type, + int section); + void read_minsyms (file_ptr symtab_offset, unsigned int nsyms); + void symtab_read (minimal_symbol_reader &reader, file_ptr symtab_offset, + unsigned int nsyms); + void read_one_sym (coff_symbol *cs); + int init_stringtab (file_ptr offset, + gdb::unique_xmalloc_ptr *storage); + const char *getsymname (struct internal_syment *symbol_entry); +}; /* Return the BFD section that CS points to. */ -static asection * -cs_to_bfd_section (struct coff_symbol *cs) +asection * +coff_reader::cs_to_bfd_section (struct coff_symbol *cs) { for (asection *sect : gdb_bfd_sections (symfile_bfd)) if (sect->target_index == cs->c_secnum) @@ -106,8 +123,8 @@ 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) +int +coff_reader::cs_to_section (struct coff_symbol *cs) { asection *sect = cs_to_bfd_section (cs); @@ -118,8 +135,8 @@ cs_to_section (struct coff_symbol *cs) /* Return the address of the section of a COFF symbol. */ -static CORE_ADDR -cs_section_address (struct coff_symbol *cs) +CORE_ADDR +coff_reader::cs_section_address (struct coff_symbol *cs) { asection *sect = cs_to_bfd_section (cs); @@ -133,9 +150,9 @@ cs_section_address (struct coff_symbol *cs) functions referencing variables imported from another DLL. Return nonzero if the given symbol corresponds to one of them. */ -static int -is_import_fixup_symbol (struct coff_symbol *cs, - enum minimal_symbol_type type) +int +coff_reader::is_import_fixup_symbol (struct coff_symbol *cs, + enum minimal_symbol_type type) { /* The following is a bit of a heuristic using the characteristics of these fixup symbols, but should work well in practice... */ @@ -162,10 +179,12 @@ is_import_fixup_symbol (struct coff_symbol *cs, return 1; } -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 minimal_symbol * +coff_reader::record_minimal_symbol (minimal_symbol_reader &reader, + struct coff_symbol *cs, + unrelocated_addr address, + enum minimal_symbol_type type, + int section) { /* We don't want TDESC entry points in the minimal symbol table. */ if (cs->c_name[0] == '@') @@ -187,9 +206,8 @@ record_minimal_symbol (minimal_symbol_reader &reader, /* A helper function for coff_symfile_read that reads minimal symbols. It may also read other forms of symbol as well. */ -static void -coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms) - +void +coff_reader::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 @@ -209,7 +227,7 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms) { /* Now that the executable file is positioned at symbol table, process it and define symbols accordingly. */ - coff_symtab_read (reader, symtab_offset, nsyms); + symtab_read (reader, symtab_offset, nsyms); } /* Install any minimal symbols that have been collected as the @@ -260,11 +278,9 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms) /* Read a symbol file, after initialization by coff_symfile_init. */ -static void -coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) +void +coff_reader::symfile_read (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); int val; @@ -310,7 +326,7 @@ 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); + read_minsyms (symtab_offset, num_symbols); if (!(coffread_objfile->flags & OBJF_READNEVER)) { @@ -342,14 +358,21 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) } } +static void +coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) +{ + coff_reader reader (objfile); + reader.symfile_read (symfile_flags); +} + /* Given pointers to a symbol table in coff style exec file, analyze them and create struct symtab's describing the symbols. NSYMS is the number of symbols in the symbol table. We read them one at a time using read_one_sym (). */ -static void -coff_symtab_read (minimal_symbol_reader &reader, - file_ptr symtab_offset, unsigned int nsyms) +void +coff_reader::symtab_read (minimal_symbol_reader &reader, + file_ptr symtab_offset, unsigned int nsyms) { struct gdbarch *gdbarch = coffread_objfile->arch (); struct coff_symbol coff_symbol; @@ -498,8 +521,8 @@ coff_symtab_read (minimal_symbol_reader &reader, /* Read the next symbol into CS. */ -static void -read_one_sym (struct coff_symbol *cs) +void +coff_reader::read_one_sym (struct coff_symbol *cs) { int i; bfd_size_type bytes; @@ -560,8 +583,9 @@ read_one_sym (struct coff_symbol *cs) /* Support for string table handling. */ -static int -init_stringtab (file_ptr offset, gdb::unique_xmalloc_ptr *storage) +int +coff_reader::init_stringtab (file_ptr offset, + gdb::unique_xmalloc_ptr *storage) { long length; int val; @@ -601,8 +625,8 @@ init_stringtab (file_ptr offset, gdb::unique_xmalloc_ptr *storage) return 0; } -static const char * -getsymname (struct internal_syment *symbol_entry) +const char * +coff_reader::getsymname (struct internal_syment *symbol_entry) { static char buffer[SYMNMLEN + 1]; const char *result; -- 2.52.0