From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YdhPHSaI4mnK9B8AWB0awg (envelope-from ) for ; Fri, 17 Apr 2026 15:21:10 -0400 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=gJ8IdFQg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 48F071E0B1; Fri, 17 Apr 2026 15:21:10 -0400 (EDT) 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 1199F1E04F for ; Fri, 17 Apr 2026 15:21:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 834764D108D2 for ; Fri, 17 Apr 2026 19:21:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 834764D108D2 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=gJ8IdFQg Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 023B84CCCA2C for ; Fri, 17 Apr 2026 19:20:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 023B84CCCA2C 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 023B84CCCA2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776453643; cv=none; b=PsiyBP7D3U5GtKqHcENNg0BXyQ00VAD2eOxcSxz0vrsz7yMmYme6PEGbfy9wlVnnkBZyVi3sNsQqkNxapa0iJqDJpCzESfVOzFngjH4lyMe6feNJ5cL68DzGoUepucYBHsecuLUwAaAmG7DmyZPyP62MH0++s/92Lh8cwm/satI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776453643; c=relaxed/simple; bh=8Y5eYbFvF/6bEv8KwhzlxkHSI/7umgff0T8KjhuSZuo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DNhqODvvPEldQ9DCdQXcJ1MaC+YTPS66yRrFJhLZMfxJ6ZixC9dqN4z7c7Hduu4GfxfjNxC1UFiokzArFSRJBYObKH464IiZ9L2JJ5Gr+PC1qwIf12sM8yFZuhaofwX53UBxwfcYrwWvFsEzQWtX5c8WCfdxxlRLrWXVlECbWQo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 023B84CCCA2C Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7dbd1458a77so786176a34.2 for ; Fri, 17 Apr 2026 12:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1776453642; x=1777058442; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=E2EREDKQxAlnAddDmXYlhV+GqA7HZa5TWssbEXj9pts=; b=gJ8IdFQgnyXBAnqxd1IC++YIW76Yj7ksOvXVZ6hqGQgLKJGN7P4a1Ju/v/oGbEUAks QmQkLGQrD0EsaYnpSIhs6RycR0K9PHdds3mW7r4VqExfqWN91KO5Er5jAbPvIImmRcSN aC/hiTshPg+QnWjL6s2Lei8GLt1mp6JIdkrce8BxEtTNsDFtBrEDj03PQRY8AXSitqh2 i1CExV/jGU18z5cfe003OQDrwRf1WjkubdCjKKKF2CY8r64JmeaICsTf1yICpFzO/LKe 5r1qkWaiwUEyK5/rApxtTuOdreUqd1b6mx/MlugukXi4Ul+fF45TiTNLREcQ/szBnybB Ig2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776453642; x=1777058442; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E2EREDKQxAlnAddDmXYlhV+GqA7HZa5TWssbEXj9pts=; b=sH0AVzhnWGTCKc4g38ievzYFgnuBgShYeGCYrXvYoFSRLCS9Lj6uP3WyQmqwx0maMw 37rnwsPlx0JYMWTrO6vLkIeRB4IV1f0laXbMe1lVV5a1A4XsTDLNVBX7ZVE4nvkrz1p6 Q1cPpKE+NHxXAr5l0NqQUDu684iYufnDv2heepoIfiFMn+boA6LtciGbNoiVJ/v/NwuH WkZGVNIRzs1WDC4pR59bbzk0Z3RFXgOeOd7qJf+Zs9Pohk0uQs/MsoG5HWrBGiVff6O3 EwlFlQdy1xquiiywgJvpwwvkU5w/H1SD3j0KVM5MYwqBP4G7kvH8VdK6A6mgeF2sF9NQ 2CLg== X-Gm-Message-State: AOJu0YxHe0Jiiub4DrTmhl0M4g+5prJHv5N8J853N3IBsUXUQ43/lCd6 hO1XtRapdC0i2ruY7N9PA3WIvUPjmTuUsUahvqZUM22B3BAaIBMBFzNcU73B2QUB8wky8excVIi 6oGc= X-Gm-Gg: AeBDieuWMnZ8WGFdS3BwT4nvA44mfzccSy72UM1vjjyIcyIeQZMgf00sRmrvzC3pl9k fMnhq4SEAZSnOv5+c3RrfGbR51b12zc9qkJil6NTULx4C55hNHjXl9XdIGP9MlLHhEF+uKQAMHV B2tueSyrdOLHBO59b5HRiDVCqLwjlP2ms8Pzea5hpYm6nxYkRYD3s2tI3ge/DbdbBZZM1t/l1I2 ujSu7h7u8+pvQEO6WUCW/xhv4tazdxXeajdIk3CZErEqhq0hb9+gDCqcwg0qIwwj3ieAsZdC1nm MNCVEHjMX4iwH9rJEY8qpLU1lq19QLW6168XCgcGpUKvMYf11828/WpT6TJxA4zXRsoqnps2fhk /4UsZD+quUv6OefAxfA2MHJAN7/i7Yly2JOjabPADay5uFBZE9ZMZPwY9sw/WJ/GZ0W+Qmv++A3 Em62sfHvepfbZPqTpdT8OcBUV5OkcnKX9v7kqEv0eoXqX2h2FEQnucV2Px+h4Myn+F X-Received: by 2002:a05:6830:67cd:b0:7d9:d2b6:155c with SMTP id 46e09a7af769-7dc94fa5f95mr2698109a34.2.1776453642068; Fri, 17 Apr 2026 12:20:42 -0700 (PDT) Received: from bapiya (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7dc975b06d2sm1801835a34.23.2026.04.17.12.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 12:20:41 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove OBJSTAT and OBJSTATS macros Date: Fri, 17 Apr 2026 13:20:39 -0600 Message-ID: <20260417192039.2758461-1-tromey@adacore.com> X-Mailer: git-send-email 2.53.0 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 The OBJSTATS macro seems pretty pointless, so I removed it. Then when looking at the OBJSTAT macro as well, I decided to remove it and also struct objstats. After this patch, symbols are allocated using a template method that automatically updates the n_syms member. This cleans up the code a little. Also, nothing ever set objstats::sz_strtab, so this is removed. Regression tested on x86-64 Fedora 43. --- gdb/ctfread.c | 12 ++++-------- gdb/dwarf2/read.c | 7 +++---- gdb/gdbtypes.c | 2 +- gdb/objfiles.h | 36 +++++++++++++++--------------------- gdb/symmisc.c | 11 ++++------- 5 files changed, 27 insertions(+), 41 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 0ddb2325344..5f8c54a34df 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -416,8 +416,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg) if (name != nullptr && *name != '\0') { objfile *objfile = ccp->per_objfile->objfile; - struct symbol *sym = new (&objfile->objfile_obstack) symbol; - OBJSTAT (objfile, n_syms++); + symbol *sym = objfile->new_symbol (); sym->set_language (language_c, &objfile->objfile_obstack); sym->compute_and_set_names (name, false, objfile->per_bfd); @@ -444,8 +443,7 @@ new_type_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid) if (name != nullptr && *name != '\0') { objfile *objfile = ccp->per_objfile->objfile; - struct symbol *sym = new (&objfile->objfile_obstack) symbol; - OBJSTAT (objfile, n_syms++); + symbol *sym = objfile->new_symbol (); sym->set_language (language_c, &objfile->objfile_obstack); sym->compute_and_set_names (name, false, objfile->per_bfd); @@ -1131,8 +1129,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg) complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id); type = builtin_type (objfile)->builtin_error; } - sym = new (&objfile->objfile_obstack) symbol; - OBJSTAT (objfile, n_syms++); + sym = objfile->new_symbol (); sym->set_type (type); sym->set_loc_class_index (LOC_OPTIMIZED_OUT); sym->compute_and_set_names (name, false, objfile->per_bfd); @@ -1178,8 +1175,7 @@ add_stt_entries (struct ctf_context *ccp, int functions) ctf_debug_printf ("adding %s '%s' tid=0x%lx", functions ? "function" : "object", tname, tid); - sym = new (&objfile->objfile_obstack) symbol; - OBJSTAT (objfile, n_syms++); + sym = objfile->new_symbol (); sym->set_type (type); sym->set_domain (functions ? FUNCTION_DOMAIN : VAR_DOMAIN); sym->set_loc_class_index (LOC_STATIC); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4035bba6e45..9eedfe2794c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7797,7 +7797,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) if (child_die->tag == DW_TAG_template_type_param || child_die->tag == DW_TAG_template_value_param) { - templ_func = new (&objfile->objfile_obstack) template_symbol; + templ_func = objfile->new_symbol (); templ_func->subclass = SYMBOL_TEMPLATE; break; } @@ -8351,7 +8351,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu) { struct objfile *objfile = cu->per_objfile->objfile; - storage = new (&objfile->objfile_obstack) rust_vtable_symbol; + storage = objfile->new_symbol (); storage->concrete_type = containing_type; storage->subclass = SYMBOL_RUST_VTABLE; } @@ -15479,8 +15479,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, if (space) sym = space; else - sym = new (&objfile->objfile_obstack) symbol; - OBJSTAT (objfile, n_syms++); + sym = objfile->new_symbol (); /* Cache this symbol's name and the name's demangled form (if any). */ sym->set_language (cu->lang (), &objfile->objfile_obstack); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 07a8c7065ea..2f566583509 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -222,7 +222,7 @@ type_allocator::new_type () if (m_is_objfile) { - OBJSTAT (m_data.objfile, n_types++); + ++m_data.objfile->n_types; type->set_owner (m_data.objfile); } else diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 89ac559ce81..fc6d9d97c83 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -142,25 +142,6 @@ struct entry_info uninitialized section index. */ #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss -/* The "objstats" structure provides a place for gdb to record some - interesting information about its internal state at runtime, on a - per objfile basis, such as information about the number of symbols - read, size of string table (if any), etc. */ - -struct objstats -{ - /* Number of full symbols read. */ - int n_syms = 0; - - /* Number of types. */ - int n_types = 0; - - /* Size of stringtable, (if applicable). */ - int sz_strtab = 0; -}; - -#define OBJSTAT(objfile, expr) (objfile -> stats.expr) -#define OBJSTATS struct objstats stats extern void print_objfile_statistics (void); /* Number of entries in the minimal symbol hash table. */ @@ -694,6 +675,17 @@ struct objfile : intrusive_list_node section_iterator (sections_end, sections_end))); } + /* Allocate a new symbol on this objfile's obstack. Normally a + symbol is made, but other subtypes (e.g., template_symbol) can + also be created. */ + template + T *new_symbol () + { + T *result = new (&objfile_obstack) T; + ++n_syms; + return result; + } + public: /* The object file's original name as specified by the user, @@ -823,9 +815,11 @@ struct objfile : intrusive_list_node struct objfile *separate_debug_objfile_link = nullptr; - /* Place to stash various statistics about this objfile. */ + /* Number of full symbols read. */ + int n_syms = 0; - OBJSTATS; + /* Number of types. */ + int n_types = 0; /* A linked list of symbols created when reading template types or function templates. These symbols are not stored in any symbol diff --git a/gdb/symmisc.c b/gdb/symmisc.c index b586f8fdb00..89374bd8a2f 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -63,12 +63,12 @@ print_objfile_statistics (void) if (objfile.per_bfd->n_minsyms > 0) gdb_printf (_(" Number of \"minimal\" symbols read: %d\n"), objfile.per_bfd->n_minsyms); - if (OBJSTAT ((&objfile), n_syms) > 0) + if (objfile.n_syms > 0) gdb_printf (_(" Number of \"full\" symbols read: %d\n"), - OBJSTAT ((&objfile), n_syms)); - if (OBJSTAT ((&objfile), n_types) > 0) + objfile.n_syms); + if (objfile.n_types > 0) gdb_printf (_(" Number of \"types\" defined: %d\n"), - OBJSTAT ((&objfile), n_types)); + objfile.n_types); i = linetables = 0; for (compunit_symtab &cu : objfile.compunits ()) @@ -90,9 +90,6 @@ print_objfile_statistics (void) objfile.print_stats (false); - if (OBJSTAT ((&objfile), sz_strtab) > 0) - gdb_printf (_(" Space used by string tables: %d\n"), - OBJSTAT ((&objfile), sz_strtab)); gdb_printf (_(" Total memory used for objfile obstack: %s\n"), pulongest (obstack_memory_used (&objfile .objfile_obstack))); base-commit: bfd118583ed69db365265915d1a48eb719e997f5 -- 2.53.0