From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GE6lCmzy52hf7SUAWB0awg (envelope-from ) for ; Thu, 09 Oct 2025 13:35:40 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=dominicclifton.name header.i=@dominicclifton.name header.a=rsa-sha256 header.s=email header.b=X9mmvuBw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 14F811E0B6; Thu, 09 Oct 2025 13:35:40 -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.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,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 server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 371C21E047 for ; Thu, 09 Oct 2025 13:35:38 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA7483858401 for ; Thu, 9 Oct 2025 17:35:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA7483858401 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=dominicclifton.name header.i=@dominicclifton.name header.a=rsa-sha256 header.s=email header.b=X9mmvuBw Received: from mx03.hydraservices.com (mx03.hydraservices.com [82.113.145.160]) by sourceware.org (Postfix) with ESMTPS id 368FA3858D21 for ; Thu, 9 Oct 2025 17:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 368FA3858D21 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=dominicclifton.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dominicclifton.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 368FA3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=82.113.145.160 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760031306; cv=none; b=OpyiO2KzTKufYns6r3QHW0SR0ggD4DU/WyQRyMFL+PEvY5mpRr9marc4CgB/ys8Czp/sBo4+gs7XgYWY/J03iWBXy849ekgURbojbgwZnNXSEHi5uqK6NiCCTJgGA28wbGdxnxY094dRCabqnP3RzC+yqwiYddvxFt4x74C3OmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760031306; c=relaxed/simple; bh=RkUnJ1zOI+5H6bQHLUE4c6+QUMxGPXj5h++B3EcJVlY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iVr67zIwVMxhabNU3umws1bHi/WkW4vITmrgpcHp9fsgwh7HyBkyo1xzOnNJKtmj3vhSuHeJTQoI2M0H0YwPo98Zr+XJC8vAXMxkf26RsyrjBinzv1c4xXs1ET5S6cczpf4NXPvxh+A53XzVEHHvM4fGZbabuLugb+8OftW4Sak= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 368FA3858D21 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dominicclifton.name; s=email; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:In-Reply-To:References:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7EBGS7yIjGKCuD9C1BXWO4HHtEOx4jpUHUcyqXyp328=; b=X9mmvuBw2ztgPdEileR+0C8clU H0qzIvnnQCysXfygjFnElcsBMmMKVkgFn3qe5Z4LlKuLH0FwE/s6RQlV87pbA/GcuJPgsAN6uVyZk fzmmal+qFgp0XcP6eM11r1nQrXjNIx9hA8qcOembNIWvyJ9oh06C7sHnWj+oCzfjsqWM=; Received: from [45.86.185.202] (helo=HYDRA01) by mx03.hydraservices.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1v6uXg-00ExNR-KJ for gdb-patches@sourceware.org; Thu, 09 Oct 2025 18:35:04 +0100 From: "Dominic Clifton" To: References: <00d101dc3609$37564b00$a602e100$@dominicclifton.name> In-Reply-To: <00d101dc3609$37564b00$a602e100$@dominicclifton.name> Subject: [PATCH] read_file_scope - avoid eventual crash when the file or directory name is null. Date: Thu, 9 Oct 2025 19:35:02 +0200 Message-ID: <017301dc3943$0ba55950$22f00bf0$@dominicclifton.name> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Content-Language: en-gb Thread-Index: Adw5QuSWiIlXBRxRSIGBtSZgikpJfA== 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 * without this, launching the debugger results in the following error: ``` terminate called after throwing an instance of 'std::logic_error' what(): basic_string: construction from null is not valid ``` find_file_and_directory - return empty strings instead of null pointers. --- gdb/dwarf2/read.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 955893c5f0c..287ce7b518c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -5942,10 +5942,18 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) if (cu->per_cu->fnd != nullptr) return *cu->per_cu->fnd; + // Ensure that nullptrs become empty strings + const char *name = dwarf2_string_attr(die, DW_AT_name, cu); + const char *comp_dir = dwarf2_string_attr(die, DW_AT_comp_dir, cu); + + if (!name) + name = ""; + if (!comp_dir) + comp_dir = ""; + /* Find the filename. Do not use dwarf2_name here, since the filename is not a source language identifier. */ - file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu), - dwarf2_string_attr (die, DW_AT_comp_dir, cu)); + file_and_directory res(name, comp_dir); if (res.get_comp_dir () == nullptr && cu->producer_is_gcc_lt_4_3 () @@ -6083,28 +6091,33 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) file_and_directory &fnd = find_file_and_directory (die, cu); + // ensure fnd.get_name() and fnd.get_comp_dir() are never null, which they sometimes are + const char *fname = fnd.get_name() ? fnd.get_name() : ""; + const char *compdir = fnd.get_comp_dir() ? fnd.get_comp_dir() : ""; + /* GAS supports generating dwarf-5 info starting version 2.35. Versions 2.35-2.37 generate an incorrect CU name attribute: it's relative, implicitly prefixing it with the compilation dir. Work around this by prefixing it with the source dir instead. */ - if (cu->header.version == 5 && !IS_ABSOLUTE_PATH (fnd.get_name ()) + if (cu->header.version == 5 && !IS_ABSOLUTE_PATH (fname) && cu->producer_is_gas_lt_2_38 ()) { attr = dwarf2_attr (die, DW_AT_stmt_list, cu); if (attr != nullptr && attr->form_is_unsigned ()) { sect_offset line_offset = (sect_offset) attr->as_unsigned (); - line_header_up lh = dwarf_decode_line_header (line_offset, cu, - fnd.get_comp_dir ()); + line_header_up lh = dwarf_decode_line_header (line_offset, cu, compdir); if (lh->version == 5 && lh->include_dir_at (1) != nullptr) { - std::string dir = lh->include_dir_at (1); - fnd.set_comp_dir (std::move (dir)); + const char* dir_ptr = lh->include_dir_at (1); + std::string dir = dir_ptr ? dir_ptr : compdir; + + fnd.set_comp_dir (std::move (dir)); } } } - cu->start_compunit_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile), + cu->start_compunit_symtab (fname, fnd.intern_comp_dir (objfile), lowpc); gdb_assert (per_objfile->sym_cu == nullptr); -- 2.48.1