From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6d2NGoAHYGnNITMAWB0awg (envelope-from ) for ; Thu, 08 Jan 2026 14:37:36 -0500 Received: by simark.ca (Postfix, from userid 112) id 69BFE1E0B6; Thu, 08 Jan 2026 14:37:36 -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.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 371BC1E08D for ; Thu, 08 Jan 2026 14:37:35 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C4A814BA2E1F for ; Thu, 8 Jan 2026 19:37:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4A814BA2E1F Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 3AB5F4BA2E04 for ; Thu, 8 Jan 2026 19:37:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AB5F4BA2E04 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3AB5F4BA2E04 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767901030; cv=none; b=t741Apw711b9qdXx5KzLrRg0IpT9CDWimTdWbIq/CILRgjaYNMyVBa3+bnWlsg984iBDq8M/4o5zczWsshqpTczxtXvqYUeJRURAuUnsAa7XwCbbxhd45uRtu0TetLA9CXDgKDs22llXkVsdymMBsHr4EjoTuJ2R9Nvuv3qtqRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767901030; c=relaxed/simple; bh=Cr1uuCRXAYPY1jdOAcgzY5iVnFduCkf1625/ATZkdys=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=F5HNh4VBPVM2iQfddZM1F6BWVlp7gjQGp1lWZd71aE1brnLeEwZ06163Ls84s2lL6wjtVRC1dLFjHn/ZCH1O/KUwcoVheuemfXq81zC8Bn3q0rLe+TCwgI0xQN6t3kIUZ+mvCgRey96i+nffDXO7fp8MIhIPHyFYt383taVftZ4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AB5F4BA2E04 Received: by simark.ca (Postfix) id CF1B61E08D; Thu, 08 Jan 2026 14:37:09 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 8/8] gdb/xcoffread: stylistic cleanup Date: Thu, 8 Jan 2026 14:33:26 -0500 Message-ID: <20260108193507.553779-9-simon.marchi@efficios.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260108193507.553779-1-simon.marchi@efficios.com> References: <20260108193507.553779-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Do a few cleanups: - declaring variables where they are used - rename functions to be more precise - add explicit comparison against nullptr or 0 - remove struct/union keywords - remove or update outdated comments Change-Id: I3f9e8604f79ee4d36cbe3d65079cb23051fcc703 --- gdb/xcoffread.c | 123 ++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 78 deletions(-) diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 5ec7281b683b..004035d1f31f 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -35,12 +35,11 @@ #include "dwarf2/sect-names.h" #include "dwarf2/public.h" - struct xcoff_symfile_info - { - /* Offset in data section to TOC anchor. */ - CORE_ADDR toc_offset = 0; - }; +{ + /* Offset in data section to TOC anchor. */ + CORE_ADDR toc_offset = 0; +}; /* Key for XCOFF-associated data. */ @@ -48,7 +47,7 @@ static const registry::key xcoff_objfile_data_key; /* XCOFF names for dwarf sections. There is no compressed sections. */ -static const struct dwarf2_debug_sections dwarf2_xcoff_names = { +static const dwarf2_debug_sections dwarf2_xcoff_names = { { ".dwinfo", NULL }, { ".dwabrev", NULL }, { ".dwline", NULL }, @@ -74,12 +73,6 @@ static const struct dwarf2_debug_sections dwarf2_xcoff_names = { 23 }; -static void xcoff_initial_scan (struct objfile *, symfile_add_flags); - -static void scan_xcoff_symtab (struct objfile *); - -static void xcoff_symfile_init (struct objfile *); - /* Search all BFD sections for the section whose target_index is equal to N_SCNUM. @@ -102,7 +95,7 @@ xcoff_secnum_to_section (int n_scnum, objfile *objfile) uses BFD's determination to vector to us. */ static void -xcoff_symfile_init (struct objfile *objfile) +xcoff_symfile_init (objfile *objfile) { /* Allocate struct to keep track of the symfile. */ xcoff_objfile_data_key.emplace (objfile); @@ -129,16 +122,14 @@ swap_sym (struct internal_syment *symbol, union internal_auxent *aux, } } -static void -scan_xcoff_symtab (struct objfile *objfile) -{ - CORE_ADDR toc_offset = 0; /* toc offset value in data section. */ +/* Locate the TOC offset in the XCOFF symbol table and assign + xcoff_symfile_info::toc_offset. */ +static void +xcoff_find_toc_offset (objfile *objfile) +{ bfd *abfd = objfile->obfd.get (); file_ptr symtab_offset = obj_sym_filepos (abfd); - struct internal_syment symbol; - union internal_auxent main_aux[5]; - unsigned int ssymnum; /* Seek to symbol table location. */ if (int ret = bfd_seek (abfd, symtab_offset, SEEK_SET); @@ -156,22 +147,21 @@ scan_xcoff_symtab (struct objfile *objfile) error (_("reading symbol table: %s"), bfd_errmsg (bfd_get_error ())); char *sraw_symbol = symtbl.data (); - ssymnum = 0; - while (ssymnum < num_symbols) + CORE_ADDR toc_offset = 0; + for (unsigned int ssymnum = 0; ssymnum < num_symbols; ) { - int sclass; - QUIT; + internal_syment symbol; bfd_coff_swap_sym_in (abfd, sraw_symbol, &symbol); - sclass = symbol.n_sclass; - switch (sclass) + switch (symbol.n_sclass) { case C_HIDEXT: { /* The CSECT auxent--always the last auxent. */ - union internal_auxent csect_aux; + internal_auxent csect_aux; + internal_auxent main_aux[5]; swap_sym (&symbol, &main_aux[0], &sraw_symbol, &ssymnum, objfile); if (symbol.n_numaux > 1) @@ -191,24 +181,24 @@ scan_xcoff_symtab (struct objfile *objfile) if ((csect_aux.x_csect.x_smtyp & 0x7) == XTY_SD && csect_aux.x_csect.x_smclas == XMC_TC0) { - if (toc_offset) + if (toc_offset != 0) warning (_("More than one XMC_TC0 symbol found.")); + toc_offset = symbol.n_value; /* Make TOC offset relative to start address of section. */ asection *bfd_sect = xcoff_secnum_to_section (symbol.n_scnum, objfile); - if (bfd_sect) + if (bfd_sect != nullptr) toc_offset -= bfd_section_vma (bfd_sect); break; } } break; + default: - { - complaint (_("Storage class %d not recognized during scan"), - sclass); - } + complaint (_("Storage class %d not recognized during scan"), + symbol.n_sclass); [[fallthrough]]; case C_RSYM: @@ -235,39 +225,29 @@ scan_xcoff_symtab (struct objfile *objfile) /* Return the toc offset value for a given objfile. */ CORE_ADDR -xcoff_get_toc_offset (struct objfile *objfile) +xcoff_get_toc_offset (objfile *objfile) { - if (objfile) + if (objfile != nullptr) return xcoff_objfile_data_key.get (objfile)->toc_offset; + return 0; } -/* Scan and build partial symbols for a symbol file. - We have been initialized by a call to dbx_symfile_init, which - put all the relevant info into a "struct dbx_symfile_info", - hung off the objfile structure. - - SECTION_OFFSETS contains offsets relative to which the symbols in the - various sections are (depending where the sections were actually - loaded). */ +/* Read the XCOFF symbol table. The only thing we are interested in is the TOC + offset value. */ static void -xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) +xcoff_symfile_read (objfile *objfile, symfile_add_flags symfile_flags) { - /* We need to do this to get the TOC information only. STABS - format is no longer supported. */ - scan_xcoff_symtab (objfile); + xcoff_find_toc_offset (objfile); /* DWARF2 sections. */ dwarf2_initialize_objfile (objfile, &dwarf2_xcoff_names); } - -static void -xcoff_symfile_offsets (struct objfile *objfile, - const section_addr_info &addrs) -{ - const char *first_section_name; +static void +xcoff_symfile_offsets (objfile *objfile, const section_addr_info &addrs) +{ default_symfile_offsets (objfile, addrs); /* Oneof the weird side-effects of default_symfile_offsets is that @@ -280,7 +260,7 @@ xcoff_symfile_offsets (struct objfile *objfile, if (objfile->section_offsets.empty ()) return; /* Is that even possible? Better safe than sorry. */ - first_section_name + const char *first_section_name = bfd_section_name (objfile->sections_start[0].the_bfd_section); if (objfile->sect_index_text == 0 @@ -302,20 +282,10 @@ xcoff_symfile_offsets (struct objfile *objfile, /* Register our ability to parse symbols for xcoff BFD files. */ -static const struct sym_fns xcoff_sym_fns = +static const sym_fns xcoff_sym_fns = { - - /* It is possible that coff and xcoff should be merged as - they do have fundamental similarities (for example, the extra storage - classes used for stabs could presumably be recognized in any COFF file). - However, in addition to obvious things like all the csect hair, there are - some subtler differences between xcoffread.c and coffread.c, notably - the fact that coffread.c has no need to read in all the symbols, but - xcoffread.c reads all the symbols and does in fact randomly access them - (in C_BSTAT and line number processing). */ - xcoff_symfile_init, /* read initial info, setup for sym_read() */ - xcoff_initial_scan, /* read a symbol file into symtab */ + xcoff_symfile_read, /* read a symbol file into symtab */ xcoff_symfile_offsets, /* xlate offsets ext->int form */ default_symfile_segments, /* Get segment information from a file. */ default_symfile_relocate, /* Relocate a debug section. */ @@ -328,24 +298,22 @@ static int xcoff_get_core_n_import_files (bfd *abfd) { asection *sect = bfd_get_section_by_name (abfd, ".ldinfo"); - gdb_byte buf[4]; - file_ptr offset = 0; - int n_entries = 0; - if (sect == NULL) return -1; /* Not a core file. */ - for (offset = 0; offset < bfd_section_size (sect);) + int n_entries = 0; + for (file_ptr offset = 0; offset < bfd_section_size (sect);) { - int next; - n_entries++; + gdb_byte buf[4]; if (!bfd_get_section_contents (abfd, sect, buf, offset, 4)) return -1; - next = bfd_get_32 (abfd, buf); + + int next = bfd_get_32 (abfd, buf); if (next == 0) break; /* This is the last entry. */ + offset += next; } @@ -361,8 +329,6 @@ int xcoff_get_n_import_files (bfd *abfd) { asection *sect = bfd_get_section_by_name (abfd, ".loader"); - gdb_byte buf[4]; - int l_nimpid; /* If the ".loader" section does not exist, the objfile is probably not an executable. Might be a core file... */ @@ -372,10 +338,11 @@ xcoff_get_n_import_files (bfd *abfd) /* The number of entries in the Import Files Table is stored in field l_nimpid. This field is always at offset 16, and is always 4 bytes long. Read those 4 bytes. */ - + gdb_byte buf[4]; if (!bfd_get_section_contents (abfd, sect, buf, 16, 4)) return -1; - l_nimpid = bfd_get_32 (abfd, buf); + + int l_nimpid = bfd_get_32 (abfd, buf); /* By convention, the first entry is the default LIBPATH value to be used by the system loader, so it does not count towards -- 2.52.0