From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cruZItxOkV+VMwAAWB0awg (envelope-from ) for ; Thu, 22 Oct 2020 05:20:28 -0400 Received: by simark.ca (Postfix, from userid 112) id 80E7E1EFC3; Thu, 22 Oct 2020 05:20:28 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 304201E58E for ; Thu, 22 Oct 2020 05:20:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A6813844047; Thu, 22 Oct 2020 09:20:26 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 2BEAE3844047 for ; Thu, 22 Oct 2020 09:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2BEAE3844047 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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 38845B248 for ; Thu, 22 Oct 2020 09:20:22 +0000 (UTC) Date: Thu, 22 Oct 2020 11:20:19 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix language of frame without debug info Message-ID: <20201022092018.GA13164@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, On openSUSE Leap 15.2, I run into this FAIL with target board readnow and test-case gdb.dwarf2/dw2-align.exp: ... (gdb) set lang c++^M Warning: the current language does not match this frame.^M (gdb) FAIL: gdb.dwarf2/dw2-align.exp: set lang c++ ... Adding some extra debugging shows that the current language differs without and with readnow: ... Breakpoint 1, 0x00000000004004ab in main ()^M (gdb) show lang^M -The current source language is "auto; currently c".^M +The current source language is "auto; currently asm".^M ... This is explained by find_pc_compunit_symtab (0x4004ab) called from select_frame, which: - without readnow: returns NULL, and - with readnow: returns the symtab for the CU crtn.S, wich has language "MIPS assembler". In the former case, the symtab for crtn.S is not expanded, and find_pc_compunit_symtab hits the default NULL return. In the latter case, the symtab for crtn.S is expanded, and the "best match" loop in find_pc_compunit_symtab returns that symtab as its best match. The GLOBAL_BLOCK for crtn.S has these outer limits of the address range: ... (gdb) p /x b.startaddr $6 = 0x4003c2 (gdb) p /x b.endaddr $7 = 0x40053d ... and 0x4004ab indeed fits in that range, which explains why the CU is considered a match. However, the actual address ranges for the CU are: ... 00000040 ffffffffffffffff 0000000000000000 (base address) 00000040 00000000004003c2 00000000004003c7 00000040 0000000000400538 000000000040053d 00000040 ... which confirms that the CU should not be considered a match. The problem is that the "best match" loop is based on the assumption that a symtab with a better match will be found, but in this case we don't find a better match because there's no debug info describing main. Fix this by preferring to use the addres map in the "best match" loop, which will accurately tell us that addrmap_find (bv.map, 0x4004ab) == NULL. Tested on x86_64-linux (that is, openSUSE Leap 15.2), with and without readnow. In the case of a readnow run, brings down the number of unexpected failures from 66 to 38. The FAIL does not reproduce on f.i. Ubuntu 18.04.5, because there the exec does not contain debug info for crtn.S. The dwarf assembly test-case mimics the scenario described above, and reproduces the FAIL with and without -readnow, for both mentioned OS configurations. Also fixes PR25980 - "Overlapping Dwarf Compile Units with non-overlapping subranges gives incorrect line information". Any comments? Thanks, - Tom [gdb/symtab] Fix language of frame without debug info gdb/ChangeLog: 2020-10-22 Tom de Vries PR symtab/26772 * symtab.c (find_pc_sect_compunit_symtab): In case there's an address map, check it in the "best match" loop. gdb/testsuite/ChangeLog: 2020-10-22 Tom de Vries PR symtab/26772 * gdb.dwarf2/dw2-ranges-overlap.c: New test. * gdb.dwarf2/dw2-ranges-overlap.exp: New file. --- gdb/symtab.c | 18 +++-- gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c | 36 ++++++++++ gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp | 87 +++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 4 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index a4f8239a8a..1148527f68 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2920,10 +2920,20 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) bv = COMPUNIT_BLOCKVECTOR (cust); b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); - if (BLOCK_START (b) <= pc - && BLOCK_END (b) > pc - && (distance == 0 - || BLOCK_END (b) - BLOCK_START (b) < distance)) + bool in_range_p = BLOCK_START (b) <= pc && pc < BLOCK_END (b); + if (!in_range_p) + continue; + + if (BLOCKVECTOR_MAP (bv)) + { + if (addrmap_find (BLOCKVECTOR_MAP (bv), pc) == nullptr) + continue; + + return cust; + } + + if (distance == 0 + || BLOCK_END (b) - BLOCK_START (b) < distance) { /* For an objfile that has its functions reordered, find_pc_psymtab will find the proper partial symbol table diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c b/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c new file mode 100644 index 0000000000..cbc4551e43 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c @@ -0,0 +1,36 @@ +/* + Copyright 2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +bar (int a) +{ + asm ("bar_label: .globl bar_label"); + return a + 1; +} + +int +foo (int a) +{ + asm ("foo_label: .globl foo_label"); + return bar (a * 2) + 3; +} + +int +main (void) +{ + asm ("main_label: .globl main_label"); + return foo (5) + 1; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp new file mode 100644 index 0000000000..59c10c8ae2 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp @@ -0,0 +1,87 @@ +# Copyright 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +load_lib dwarf.exp + +# The function foo is encapsulated by two functions from CU +# $srcfile (main and bar), but the debug info does not describe foo, so +# foo should not be seen as part of CU $srcfile. +# Run to foo, and check that the current language is the default auto/C. +# If foo is considered part of CU $srcfile, the language will be auto/C++ +# instead. + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + verbose "Skipping $gdb_test_file_name." + return 0 +} + +# The .c files use __attribute__. +if [get_compiler_info] { + return -1 +} +if !$gcc_compiled { + verbose "Skipping $gdb_test_file_name." + return 0 +} + +standard_testfile .c -dw.S + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + declare_labels ranges_label + + # Find start address and length for our functions. + set main_func \ + [function_range main [list ${srcdir}/${subdir}/$srcfile]] + set foo_func \ + [function_range foo [list ${srcdir}/${subdir}/$srcfile]] + set bar_func \ + [function_range bar [list ${srcdir}/${subdir}/$srcfile]] + + cu {} { + compile_unit { + {language @DW_LANG_C_plus_plus} + {name $srcfile} + {ranges ${ranges_label} DW_FORM_sec_offset} + } { + subprogram { + {external 1 flag} + {name main} + } + } + } + + ranges {is_64 [is_64_target]} { + ranges_label: sequence { + {base [lindex $main_func 0]} + {range 0 [lindex $main_func 1]} + {base [lindex $bar_func 0]} + {range 0 [lindex $bar_func 1]} + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto foo] { + return -1 +} + +gdb_test "show language" \ + "The current source language is \"auto; currently c\"\."