From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id jdb4FqIz7Wjf6y4AWB0awg (envelope-from ) for ; Mon, 13 Oct 2025 13:15:14 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dMMvoKBU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4F01B1E047; Mon, 13 Oct 2025 13:15:14 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 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 31C9D1E047 for ; Mon, 13 Oct 2025 13:15:13 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CEBF3856DEE for ; Mon, 13 Oct 2025 17:15:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CEBF3856DEE Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dMMvoKBU Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 0AAB43857711 for ; Mon, 13 Oct 2025 17:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AAB43857711 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0AAB43857711 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760375672; cv=none; b=iGHiLYBnonYsQe27fPtc0zU1opkz9sKogCMuSnbz+jQH2cPlqcBkKEV6l4TOzeJoX3npuK+VYa3+bFOrVP1HoLkdZZqgE/P/xrmIwIBeMTn2anX9uEG1RQRPjkLCLMsXZmYFM/aZDtXqCMWn/X49BZzUCvXLs8/A9lPCxoXjI7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760375672; c=relaxed/simple; bh=UXuy0Q6a8N29bI9JHLxD1dIWtHKXhWe3wsGSFxo+9nQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uXyR/Cj1eukHwc94fOS5ofF4YjeKeSCBBfhPVjIIlAl+BteXIXpmt7fxvbhW6t8kbOjRjVjdBMnZtlgRlJ5g1Dn8HNngu1+Up5XTe1FS7S1idu03eVrr/qMoJ/1mRbPry61lShQo1oxj0tFMzUUw6X8/2YmJsQGO6sPnX4cI27E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AAB43857711 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760375670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WdftngCiFlXwwRkB2qWwfvOwlohHAYUxW1RJ7xkjMF4=; b=dMMvoKBUOZFQg6+FRIXV8q7t4/gPqSNUOREmPbv873rW9kjF6gdxoFcXMbXufkWuR71yfg 2RQqbgUEbApSBp3sx9czUSzvdij5xFaPy2YQAUi5jimCMENILRw7w0xmQpT1KSFOlyEKdm V4d3IE6hHlwKQzW2tNUk7kDUzDzcEf8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-aBNe8o6wP0y4Ep97Gg7DYw-1; Mon, 13 Oct 2025 13:14:29 -0400 X-MC-Unique: aBNe8o6wP0y4Ep97Gg7DYw-1 X-Mimecast-MFC-AGG-ID: aBNe8o6wP0y4Ep97Gg7DYw_1760375668 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3ef9218daf5so3675802f8f.1 for ; Mon, 13 Oct 2025 10:14:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760375668; x=1760980468; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WdftngCiFlXwwRkB2qWwfvOwlohHAYUxW1RJ7xkjMF4=; b=GKzKyv9SAReCuC6SC9BTqEWBnasMvEYg0d2RfkTp26yOOFHx/36JlTjKIdPWGucunm 9SAi/9UxpA8+e5Y8WAsGx0+NoMJzV7liwQcX39L72rwzTfQt7sX5j09TfPAq0F5GwcSf 08B5eLlyerKxw838ooh3t8hZhJRyihJGo0an34D5D2iBQxTqPfOaFAI9JvqDSLZaNVKS gwDssRjmgjjHDY2IJVbOa/b55MN2LmAC7Umh5y7D8Kmu+DvGz2rF437VOPymlXYssrj3 N8yQyKfWjWW4cSR0cMcWPQM1dq+bl2nrhQzTfZcmSY9EyjMt2j31Sh2aVNOvHRWFj2NM GL8A== X-Forwarded-Encrypted: i=1; AJvYcCXAta6y3kRmz/R2SuZUDjYQlpfKXagQgmS70PG6L+figMKNyGDt1uh+arfxk9bPmTih8wOkJtsLZZrSpQ==@sourceware.org X-Gm-Message-State: AOJu0YyRgj2NFxXwytr+OGYt2uR9OabkEjmxKKd3/QDRwC+LTMbHtNU8 AkD/uS6grH3a/RLAxXca9Oiv+gXk8TMPKGLRAem4U8Ex+/W8+IJkP/mFTfBrzFPRnteArcCP4TY kCJ0FOKN9ZlLe3iC7FS1cVtdMPiBmWGOTX2TSdinnaEafYwO0CwJa9h9TQPB2FWqAwfPGdfQ= X-Gm-Gg: ASbGncuUzffuUWedWVm2764isdnG1gF3RUuNGMAYl4YTkcKtRzYllLYjpTKd+FPOBj6 n1zZdpuDMqo+TgSVW/rfIDFMKEexzCtwnH/X3DkN5bOeKrtdGEx+0C4z12qNKPmvfcWVkZgu4Su 4cRhcbpACE3Ex/nDy4QCh+kCnr/d/jh93fHOIlKSkhIRNLkrGg8OEFHFmC5bOLH6iylSrTSW+FJ 1wi+PiK/w5MTPQaDM7wS2oZTzuzCSGNb3PrZ7ks6KEWnfTyHYPtCubczYIDHqGo8NJYM+++Vij7 BQDiMdQIVFmobZTd+1F5Cq8arR9z5IsHtEQ= X-Received: by 2002:a05:6000:603:b0:407:77f9:949e with SMTP id ffacd0b85a97d-42666ac7026mr13426201f8f.21.1760375668017; Mon, 13 Oct 2025 10:14:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEipSyIZ9hcy08581h5Dz6SX71h+sJj603ClZDHGfIz5AI2HxKaa9d5C7nm1HApualYUZkK1g== X-Received: by 2002:a05:6000:603:b0:407:77f9:949e with SMTP id ffacd0b85a97d-42666ac7026mr13426183f8f.21.1760375667614; Mon, 13 Oct 2025 10:14:27 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-426ce57cc0esm19310065f8f.6.2025.10.13.10.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Oct 2025 10:14:27 -0700 (PDT) From: Andrew Burgess To: Dominic Clifton , gdb-patches@sourceware.org Subject: Re: [PATCH] read_file_scope - avoid eventual crash when the file or directory name is null. In-Reply-To: <017301dc3943$0ba55950$22f00bf0$@dominicclifton.name> References: <00d101dc3609$37564b00$a602e100$@dominicclifton.name> <017301dc3943$0ba55950$22f00bf0$@dominicclifton.name> Date: Mon, 13 Oct 2025 18:14:26 +0100 Message-ID: <877bwybu6l.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bJg3plp2gz7cUL-_kO5hCk2dPSGs3anSQeEshJ-ggZI_1760375668 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 "Dominic Clifton" writes: > * 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 > ``` Thanks for looking into this failure. > > 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); I suspect this change is going to cause problems. If you checkout struct file_and_directory in file-and-dir.h you'll see there are a couple of methods which check for nullptr as a special value, so masking all of the nullptr inputs is going to change the behaviour. > > if (res.get_comp_dir () == nullptr And just here we have an example of some code which appears to be checking for nullptr, which is no longer going to work as expected after this change. Could you expand on what the DWARF looks like that is triggering this failure? We have a DWARF assembler in our testsuite, see gdb.dwarf2/ for some examples (look for 'Dwarf::assemble'), so we should be able to reproduce the problematic DWARF and trigger the failure. I initially figured it might be as simple as a missing DW_AT_name on a DW_TAG_compile_unit, but that didn't seem to trigger the issue, so there must be more too it. If you can show the DWARF in question then we can likely write a test for this issue, or, if you feel adventurous, you could have a go yourself. Thanks, Andrew > && 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