From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /BOKCWKg52nafDAAWB0awg (envelope-from ) for ; Tue, 21 Apr 2026 12:05:54 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=oM6A9at4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FxpkLlkW; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=BsFvLli5; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vjjU68dV; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 14EEA1E0C3; Tue, 21 Apr 2026 12:05:54 -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_MSPIKE_H2,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 AC3311E093 for ; Tue, 21 Apr 2026 12:05:52 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id ABB064BA902D for ; Tue, 21 Apr 2026 16:05:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABB064BA902D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=oM6A9at4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FxpkLlkW; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=BsFvLli5; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vjjU68dV Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id A1E7E4B9DB5E for ; Tue, 21 Apr 2026 16:03:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1E7E4B9DB5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1E7E4B9DB5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776787390; cv=none; b=GO3PpGTDWsstAJz+4Q4CCV4mRvuLzeN/7siuLKObBPpudQgeNWpXB4WaXqMb6kbFV8+Gn7srivll79FcOm5sgRKe/pBetScUewm2JajavxuYWgZEQ7a3iDgsQ44z/21ZMbxiwV1tcwY6gSv3u8uLAA4eqtU5LRNengVW+jElU6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776787390; c=relaxed/simple; bh=dY6wWHi62gp9NYR6MDDvY4G8p7k9DToDHOYl5jQUtbE=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=R8h/DZuE63WfjnliBTdHidkrF1Xdy8OXdgHUBfIyHNmtgYK8Slbcdw1YQbib08kLXYHatGffGRSA1iJRCEEaj2SpotKamaDXA4pwvwtk+3mvkVE8LnWXXIKbxng3i9LdujmzI7LEhE0uuCDCX08rICHEJJZO0LBPjCyXZU5tNj8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1E7E4B9DB5E Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6AD5F5BCFE for ; Tue, 21 Apr 2026 16:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776787389; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P/WA76dwMvqdiedB27akGe+4V0ym7gvgbSMjMm7eg7k=; b=oM6A9at4XeGFzW4j3hJzr12a4MS8mFnPAnS9sr1s9l+CIili6nZhI4EfLmRGeIuduhzKZn uAfi9kq70QKv1bO0g+sC37T6tSUDL3Rpwvx+iMNOaiSUKoiyRettoNePIgAI/9KAlvHMw0 9SaoA+pVDrw8tIPShhc4bRbOT5tj7I8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776787389; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P/WA76dwMvqdiedB27akGe+4V0ym7gvgbSMjMm7eg7k=; b=FxpkLlkWj6M4cJB9Cn5BhSIVOt5o6bejLS14Kw3ArFLfq8w64Iyf5U61KO8w+L8Li612Lo ahpjZvGFxLRkWBDw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=BsFvLli5; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=vjjU68dV DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776787388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P/WA76dwMvqdiedB27akGe+4V0ym7gvgbSMjMm7eg7k=; b=BsFvLli5yqKFCKPxaSnno81u8tqm+jPsyUO7r1923pFeZ8FikldWr0/toTYiCejUUVsDXF Wk8q9a5mMVWFn8t6X+0BXRvpTFIHRmJqXGY94v4tV39JC8pS6cI7nggdoFdXM1wCsbt17d nBOd1Ar6i5XaR1YOIsgF3guhNSvizMA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776787388; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P/WA76dwMvqdiedB27akGe+4V0ym7gvgbSMjMm7eg7k=; b=vjjU68dVygx5Ynw5FNRdF1lzgZmr+cXKLJWVLYxLXSCvZaKgDwGt+nFoToYcnZNyZt3iFn d3fzeiBjMHranICw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 57BD9593AF for ; Tue, 21 Apr 2026 16:03:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id lrdEFLyf52m9JwAAD6G6ig (envelope-from ) for ; Tue, 21 Apr 2026 16:03:08 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/symtab] Factor out new_symbol_file_line Date: Tue, 21 Apr 2026 18:03:07 +0200 Message-ID: <20260421160307.1655903-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Queue-Id: 6AD5F5BCFE 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 I was looking at a patch [1] modifying the DW_AT_decl_file / DW_AT_call_file handling of new_symbol, and noticed that: - the code is fairly nested, and - the patch adds another nesting layer. Factor out function new_symbol_file_line out of new_symbol, handling both the DW_AT_decl_file / DW_AT_call_file and DW_AT_call_line / DW_AT_decl_line attributes. Having factored out the code, simplify it using return, and modernize it using bool and nullptr. [1] https://sourceware.org/pipermail/gdb-patches/2026-March/226065.html --- gdb/dwarf2/read.c | 87 +++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 375e8a75db4..d6695627bb2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15426,6 +15426,55 @@ is_ada_import_or_export (dwarf2_cu *cu, const char *name, && !streq (linkagename, "adainit")); } +/* Apply the DW_AT_{call,decl}_{file,line} attributes of DIE in CU to SYM. */ + +static void +new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu, + struct symbol *sym) +{ + struct attribute *attr = nullptr; + + bool inlined_func = (die->tag == DW_TAG_inlined_subroutine); + + /* Handle DW_AT_call_line / DW_AT_decl_line. */ + attr = dwarf2_attr (die, + inlined_func ? DW_AT_call_line : DW_AT_decl_line, + cu); + if (attr != nullptr) + sym->set_line (attr->unsigned_constant ().value_or (0)); + + /* Handle DW_AT_call_file / DW_AT_decl_file. */ + struct dwarf2_cu *file_cu = cu; + attr = dwarf2_attr (die, + inlined_func ? DW_AT_call_file : DW_AT_decl_file, + &file_cu); + if (attr == nullptr) + return; + + std::optional index_cst = attr->unsigned_constant (); + if (!index_cst.has_value ()) + return; + + if (file_cu->line_header == nullptr) + { + file_and_directory fnd (nullptr, nullptr); + decode_line_header_for_cu (file_cu->dies, file_cu, fnd); + } + + file_name_index file_index = (file_name_index) *index_cst; + struct file_entry *fe = nullptr; + if (file_cu->line_header != nullptr) + fe = file_cu->line_header->file_name_at (file_index); + + if (fe == nullptr) + { + complaint (_("file index out of range")); + return; + } + + sym->set_symtab (fe->symtab (*file_cu)); +} + /* Given a pointer to a DWARF information entry, figure out if we need to make a symbol table entry for it, and if so, create a new entry and return a pointer to it. @@ -15446,8 +15495,6 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, struct attribute *attr2 = NULL; std::vector *list_to_add = nullptr; - int inlined_func = (die->tag == DW_TAG_inlined_subroutine); - name = dwarf2_name (die, cu); if (name == nullptr && (die->tag == DW_TAG_subprogram || die->tag == DW_TAG_inlined_subroutine @@ -15500,41 +15547,9 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, sym->set_type (type); else sym->set_type (die_type (die, cu)); - attr = dwarf2_attr (die, - inlined_func ? DW_AT_call_line : DW_AT_decl_line, - cu); - if (attr != nullptr) - sym->set_line (attr->unsigned_constant ().value_or (0)); - struct dwarf2_cu *file_cu = cu; - attr = dwarf2_attr (die, - inlined_func ? DW_AT_call_file : DW_AT_decl_file, - &file_cu); - if (attr != nullptr) - { - std::optional index_cst = attr->unsigned_constant (); - if (index_cst.has_value ()) - { - file_name_index file_index = (file_name_index) *index_cst; - struct file_entry *fe; - - if (file_cu->line_header == nullptr) - { - file_and_directory fnd (nullptr, nullptr); - decode_line_header_for_cu (file_cu->dies, file_cu, fnd); - } - - if (file_cu->line_header != nullptr) - fe = file_cu->line_header->file_name_at (file_index); - else - fe = NULL; - - if (fe == NULL) - complaint (_("file index out of range")); - else - sym->set_symtab (fe->symtab (*file_cu)); - } - } + /* Handle DW_AT_{call,decl}_{file,line}. */ + new_symbol_file_line (die, cu, sym); switch (die->tag) { base-commit: c365a263f5dcf95982464cf6d53db00cc6f04c1c -- 2.51.0