From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +Hz8Lkier2CiPQAAWB0awg (envelope-from ) for ; Thu, 27 May 2021 09:27:36 -0400 Received: by simark.ca (Postfix, from userid 112) id BE3CD1F11C; Thu, 27 May 2021 09:27:36 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 827001E783 for ; Thu, 27 May 2021 09:27:35 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A583384601E; Thu, 27 May 2021 13:27:35 +0000 (GMT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 293DF3860C39 for ; Thu, 27 May 2021 13:27:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 293DF3860C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 43B5B1FD2F for ; Thu, 27 May 2021 13:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1622122052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=I9KVw5myJBotV2Hc1JjNPBfR3OuHm2MxTsL6+7uGWWQ=; b=EnnRpjoeIFrJy76P+XyNwltgztRVWt79C+Mctod/QJDh2NEk1aub90g6u7RJk2rLxeBjT2 GkM8eRSCLXyByeWAkU2qxhw190Q6Mp0fKB8SERKkYI8OsdX13QVSwoNEgZoKZL4aBbD7Vv u+O5xYpi7NH3HLDObwL2IfPj2wHrcsQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1622122052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=I9KVw5myJBotV2Hc1JjNPBfR3OuHm2MxTsL6+7uGWWQ=; b=YP1YNC20iztIduTO5Su2/klCHvP1iaP2YTr9kxyEEbt85XuwQk7fo8QvTiR0qgliMP/znn +thtPt4qcFAfj0Aw== Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id 33C4211A98 for ; Thu, 27 May 2021 13:27:32 +0000 (UTC) Date: Thu, 27 May 2021 15:27:30 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Fix segfault in process_psymtab_comp_unit Message-ID: <20210527132729.GA3386@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.dwarf2/dw2-dummy-cu.exp without -readnow, we run into: ... (gdb) file outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu^M Reading symbols from outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu...^M ERROR: Couldn't load dw2-dummy-cu into GDB (eof). ... The problem is that we're running into a segfault: ... Thread 1 "gdb" received signal SIGSEGV, Segmentation fault. process_psymtab_comp_unit (this_cu=0x2141090, per_objfile=0x1aa4140, want_partial_unit=false, pretend_language=language_minimal) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:7023 7023 switch (reader.comp_unit_die->tag) ... due to reader.comp_unit_die == nullptr: ... (gdb) p reader.comp_unit_die $1 = (die_info *) 0x0 ... Indeed, there's no CU DIE in the test-case: ... $ readelf -wi outputs/gdb.dwarf2/dw2-dummy-cu/dw2-dummy-cu Contents of the .debug_info section: Compilation Unit @ offset 0x0: Length: 0x7 (32-bit) Version: 2 Abbrev Offset: 0x0 Pointer Size: 4 $ ... Fix this by handling reader.comp_unit_die == nullptr in process_psymtab_comp_unit. Update the test-case to trigger this PR, as per PR27920 - "[gdb/testsuite] hardcoding -readnow skips testing of partial symbols". Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/symtab] Fix segfault in process_psymtab_comp_unit gdb/ChangeLog: 2021-05-27 Tom de Vries PR symtab/27919 * dwarf2/read.c (process_psymtab_comp_unit): gdb/testsuite/ChangeLog: 2021-05-27 Tom de Vries PR symtab/27919 PR testsuite/27920 * gdb.dwarf2/dw2-dummy-cu.exp: Use maint expand-symtabs instead of -readnow. --- gdb/dwarf2/read.c | 3 +++ gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 0da87bbecd6..4cc5b4f32d7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7020,6 +7020,9 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu, cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false); + if (reader.comp_unit_die == nullptr) + return; + switch (reader.comp_unit_die->tag) { case DW_TAG_compile_unit: diff --git a/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp index 673972447a1..7871851e577 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-dummy-cu.exp @@ -27,13 +27,9 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != " return -1 } -set saved_gdbflags $GDBFLAGS -set GDBFLAGS "$GDBFLAGS -readnow" - clean_restart $executable +gdb_test_no_output "maint expand-symtab" # Something simple to verify gdb didn't crash, and has read in whatever symbol # info is there. gdb_test "info fun main" "main_end" - -set GDBFLAGS $saved_gdbflags