From patchwork Tue Oct 29 16:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 99783 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 299DB3858C98 for ; Tue, 29 Oct 2024 16:58:32 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id AD2583858414 for ; Tue, 29 Oct 2024 16:57:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD2583858414 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 AD2583858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730221076; cv=none; b=C385Ek+aPBjVK7ObIKcngT3l0sSGI6AdzxkF9Fi7sEB2eLzLIMxUIpYw1UTuy0heIyOzFIBiwfYxgSoN2yQtuH921O/QPDQTjmgonlATkudmUHSuRlCeR0ugUH8k/bl1aKEp36aSuac9jdZjXJOzDgsIAhTFFP8okRD76/O3Eyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730221076; c=relaxed/simple; bh=pELGAgGSA3gaEz4CIEkaZ2rL8pDudpEHB9OF7Z+GkNQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=L46rRakV68ekad8xwCjsEeBfbnYNLB7w+6fyFDQziy6wLTrlyAFctFSS54zmFZLcUiFmqNO2tNYWrtZechq4BZM1RqCe1qaHFuhbMGc3ZLl/nZDXAL7VIwBZJiRH+SgkdxAPnP+CcCZZD/Qr/tzuexx2m53hTqepZ1FBHkGJWRw= ARC-Authentication-Results: i=1; server2.sourceware.org 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-out1.suse.de (Postfix) with ESMTPS id A5EF221D3B; Tue, 29 Oct 2024 16:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730221070; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VxxbohuDRXzPgyRp42TTPd2i12tzburVOMOB8+EZrpE=; b=Cem66msvPGj7/F9kwC9IRo3FzHOHNbV2f3Ds5hdVKkjZe8y0d4cHdr7aqoSLlvQcv4xEkx Ik9Cn7G1eSVaEMOr9uS2n4eZjIrYL3eW2+JmBqylB94j0ZcvVOo80Z3Fg921dztuIY4RDS GHDObaH/qVAQ3dxBQhLX/wblvFYgVkQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730221070; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VxxbohuDRXzPgyRp42TTPd2i12tzburVOMOB8+EZrpE=; b=vLd4vxp/MDP912timShkKxvCUk16YpueQjp/xXhx/PUkIYsL+jVl19OCq9wDz4nZY3s3Lc WG9+zzZs65FWOYAA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Cem66msv; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="vLd4vxp/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1730221070; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VxxbohuDRXzPgyRp42TTPd2i12tzburVOMOB8+EZrpE=; b=Cem66msvPGj7/F9kwC9IRo3FzHOHNbV2f3Ds5hdVKkjZe8y0d4cHdr7aqoSLlvQcv4xEkx Ik9Cn7G1eSVaEMOr9uS2n4eZjIrYL3eW2+JmBqylB94j0ZcvVOo80Z3Fg921dztuIY4RDS GHDObaH/qVAQ3dxBQhLX/wblvFYgVkQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1730221070; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VxxbohuDRXzPgyRp42TTPd2i12tzburVOMOB8+EZrpE=; b=vLd4vxp/MDP912timShkKxvCUk16YpueQjp/xXhx/PUkIYsL+jVl19OCq9wDz4nZY3s3Lc WG9+zzZs65FWOYAA== 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 8CB40136A5; Tue, 29 Oct 2024 16:57:50 +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 F2YcIQ4UIWdfLgAAD6G6ig (envelope-from ); Tue, 29 Oct 2024 16:57:50 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] [gdb/symtab] Fix parent map when handling .debug_info and .debug_types Date: Tue, 29 Oct 2024 17:57:36 +0100 Message-Id: <20241029165738.6105-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: A5EF221D3B X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org From: "Author: Tom Tromey" Consider test-case: ... $ cat test.c namespace sp1 { class A { int i; const int f1 = 1; ... const int f29 = 1; }; } sp1::A a; void _start (void) {} $ cat test2.c namespace sp2 { class B { float f; const float f1 = 1; ... const float f29 = 1; }; } sp2::B b; ... compiled like this: ... $ g++ test.c -gdwarf-4 -c -g -fdebug-types-section $ g++ test2.c -gdwarf-5 -c -g -fdebug-types-section $ g++ -g test.o test2.o -nostdlib ... Using: ... $ gdb -q -batch -iex "maint set worker-threads 0" a.out -ex "maint print objfiles" ... we get a cooked index entry with incorrect parent: ... [29] ((cooked_index_entry *) 0x3c57d1a0) name: B canonical: B qualified: sp1::A::B DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x154 parent: ((cooked_index_entry *) 0x3c57d110) [A] ... The problem is that the parent map assumes that all offsets are in the same section. Fix this by using dwarf2_section_info::buffer-relative addresses instead, which get us instead: ... [29] ((cooked_index_entry *) 0x3f0962b0) name: B canonical: B qualified: sp2::B DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x154 parent: ((cooked_index_entry *) 0x3f096280) [sp2] ... Tested on x86_64-linux. PR symtab/32225 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225 --- gdb/dwarf2/parent-map.h | 11 ++++------- gdb/dwarf2/read.c | 12 +++++------- 2 files changed, 9 insertions(+), 14 deletions(-) base-commit: 7ffd4868a7e22dd2f8126822501bfa18479d715c diff --git a/gdb/dwarf2/parent-map.h b/gdb/dwarf2/parent-map.h index 6cff548a2a7..a9ea34ec08c 100644 --- a/gdb/dwarf2/parent-map.h +++ b/gdb/dwarf2/parent-map.h @@ -69,18 +69,15 @@ class parent_map parent_map (parent_map &&) = default; parent_map &operator= (parent_map &&) = default; - /* A reasonably opaque type that is used here to combine a section - offset and the 'dwz' flag into a single value. */ + /* A reasonably opaque type that is used as part of a DIE range. */ enum addr_type : CORE_ADDR { }; /* Turn a section offset into a value that can be used in a parent map. */ - static addr_type form_addr (sect_offset offset, bool is_dwz) + static addr_type form_addr (const gdb_byte *info_ptr) { - CORE_ADDR value = to_underlying (offset); - if (is_dwz) - value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); - return addr_type (value); + static_assert (sizeof (addr_type) >= sizeof (uintptr_t)); + return (addr_type) (uintptr_t) info_ptr; } /* Add a new entry to this map. DIEs from START to END, inclusive, diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2a29b844845..e9f97380d56 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16360,8 +16360,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, with a NULL result when when we see a reference to a DIE in another CU that we may or may not have imported locally. */ - parent_map::addr_type addr - = parent_map::form_addr (origin_offset, origin_is_dwz); + parent_map::addr_type addr = parent_map::form_addr (new_info_ptr); if (new_reader->cu != reader->cu || new_info_ptr > watermark_ptr) *maybe_defer = addr; else @@ -16500,11 +16499,10 @@ cooked_indexer::recurse (cutu_reader *reader, /* Both start and end are inclusive, so use both "+ 1" and "- 1" to limit the range to the children of parent_entry. */ parent_map::addr_type start - = parent_map::form_addr (parent_entry->die_offset + 1, - reader->cu->per_cu->is_dwz); - parent_map::addr_type end - = parent_map::form_addr (sect_offset (info_ptr - 1 - reader->buffer), - reader->cu->per_cu->is_dwz); + = parent_map::form_addr (reader->buffer + + to_underlying (parent_entry->die_offset) + + 1); + parent_map::addr_type end = parent_map::form_addr (info_ptr - 1); m_die_range_map->add_entry (start, end, parent_entry); }