From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EjJdJmnPmV96bwAAWB0awg (envelope-from ) for ; Wed, 28 Oct 2020 16:07:05 -0400 Received: by simark.ca (Postfix, from userid 112) id 9432E1EFC1; Wed, 28 Oct 2020 16:07:05 -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 332021E590 for ; Wed, 28 Oct 2020 16:07:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FC673858001; Wed, 28 Oct 2020 20:07:03 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 3DCB83858001 for ; Wed, 28 Oct 2020 20:07:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3DCB83858001 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 4D3C7AC97 for ; Wed, 28 Oct 2020 20:06:59 +0000 (UTC) Subject: Re: [PATCH][gdb/symtab] Fix language of frame without debug info From: Tom de Vries To: gdb-patches@sourceware.org References: <20201022092018.GA13164@delia> Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pH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HQPd9+RybW2l7sJv26nkUH5Z 5s84P6894ebgimcprJdAkjJTgprl1nhgvptU5M9Uv85Pferoh2groQEAtRPlCGrZ2/2qVNe9 XJfSYbiyedvApWcJs5DOByTaKkcAEQEAAcLAkwQYAQgAJhYhBKydJ7mEpsswrWYaaO6FXats 4kSgBQJdJbQnAhsMBQkDwmcAACEJEO6FXats4kSgFiEErJ0nuYSmyzCtZhpo7oVdq2ziRKD3 twf7BAQBZ8TqR812zKAD7biOnWIJ0McV72PFBxmLIHp24UVe0ZogtYMxSWKLg3csh0yLVwc7 H3vldzJ9AoK3Qxp0Q6K/rDOeUy3HMqewQGcqrsRRh0NXDIQk5CgSrZslPe47qIbe3O7ik/MC q31FNIAQJPmKXX25B115MMzkSKlv4udfx7KdyxHrTSkwWZArLQiEZj5KG4cCKhIoMygPTA3U yGaIvI/BGOtHZ7bEBVUCFDFfOWJ26IOCoPnSVUvKPEOH9dv+sNy7jyBsP5QxeTqwxC/1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: Date: Wed, 28 Oct 2020 21:06:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201022092018.GA13164@delia> Content-Type: multipart/mixed; boundary="------------E9F7F09554D55F0E0F23CC7D" Content-Language: en-US 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" This is a multi-part message in MIME format. --------------E9F7F09554D55F0E0F23CC7D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 10/22/20 11:20 AM, Tom de Vries wrote: Rebased on current master, committed as attached below. Thanks, - Tom --------------E9F7F09554D55F0E0F23CC7D Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-symtab-Fix-language-of-frame-without-debug-info.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-symtab-Fix-language-of-frame-without-debug-info.pat"; filename*1="ch" [gdb/symtab] Fix language of frame without debug info 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". 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 | 8 +++ gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.c | 36 ++++++++++ gdb/testsuite/gdb.dwarf2/dw2-ranges-overlap.exp | 87 +++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index f6e2475800..b7aae1bed1 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2923,6 +2923,14 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) if (!in_range_p) continue; + if (BLOCKVECTOR_MAP (bv)) + { + if (addrmap_find (BLOCKVECTOR_MAP (bv), pc) == nullptr) + continue; + + return cust; + } + CORE_ADDR range = end - start; if (best_cust != nullptr && range >= best_cust_range) 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\"\." --------------E9F7F09554D55F0E0F23CC7D--