From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id NnHQErTCkl+aXAAAWB0awg (envelope-from ) for ; Fri, 23 Oct 2020 07:47:00 -0400 Received: by simark.ca (Postfix, from userid 112) id 3F5841EE09; Fri, 23 Oct 2020 07:47:00 -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 B85761E58D for ; Fri, 23 Oct 2020 07:46:58 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2275E3987958; Fri, 23 Oct 2020 11:46:58 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 1C8873987936 for ; Fri, 23 Oct 2020 11:46:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1C8873987936 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 30D7AAAB2 for ; Fri, 23 Oct 2020 11:46:55 +0000 (UTC) Date: Fri, 23 Oct 2020 13:46:53 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Don't use default form in Dwarf::_guess_form Message-ID: <20201023114652.GA26275@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, The only possible form for a DW_AT_low_pc attribute is DW_FORM_addr. When specifying in dwarf assembly a low_pc attribute without explicit form: ... {low_pc {main_label - 4}} ... the resulting attribute uses DW_FORM_string, which is misinterpreted by gdb when reading it as: ... cu->base_address = attr->as_address (); ... Stop using DW_FORM_string as default form. Instead, use a default form based on the attribute name, if possible and unambiguous. Otherwise, error out. F.i.: - for DW_AT_low_pc we use DW_FORM_addr. - For DW_AT_high_pc, we don't specify a default form because it could be either address or constant class. - For DW_AT_name, we use DW_FORM_string. While we could encode with DW_FORM_strp instead, DW_FORM_string is always ok. Tested on x86_64-linux. Any comments? Thanks, - Tom [gdb/testsuite] Don't use default form in Dwarf::_guess_form gdb/testsuite/ChangeLog: 2020-10-23 Tom de Vries * lib/dwarf.exp (Dwarf::_guess_form): Return "" by default instead of DW_FORM_string. (Dwarf::_default_form): New proc. (Dwarf::_handle_DW_TAG): Use _default_form. Error out if no form was guessed. --- gdb/testsuite/lib/dwarf.exp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 5c84063105..b6b7844726 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -247,11 +247,13 @@ proc get_func_info { name {options {debug}} } { # and DW_FORM_ref4 is used. See 'new_label' and 'define_label'. # * If VALUE starts with the "%" character, then it is a label # reference too, but DW_FORM_ref_addr is used. -# * Otherwise, VALUE is taken to be a string and DW_FORM_string is -# used. In order to prevent bugs where a numeric value is given but +# * In order to prevent bugs where a numeric value is given but # no form is specified, it is an error if the value looks like a number # (using Tcl's "string is integer") and no form is provided. -# More form-guessing functionality may be added. +# * Otherwise, if the attribute name has a default form (f.i. DW_FORM_addr for +# DW_AT_low_pc), then that one is used. +# * Otherwise, an error is reported. Either specify a form explicitly, or +# add a default for the the attribute name in _default_form. # # CHILDREN is just Tcl code that can be used to define child DIEs. It # is evaluated in the caller's context. @@ -590,9 +592,25 @@ namespace eval Dwarf { } default { + return "" + } + } + } + + proc _default_form { attr } { + switch -exact -- $attr { + DW_AT_low_pc { + return DW_FORM_addr + } + DW_AT_producer - + DW_AT_comp_dir - + DW_AT_linkage_name - + DW_AT_MIPS_linkage_name - + DW_AT_name { return DW_FORM_string } } + return "" } # Map NAME to its canonical form. @@ -697,6 +715,12 @@ namespace eval Dwarf { error "Integer value requires a form" } set attr_form [_guess_form $attr_value attr_value] + if { $attr_form eq "" } { + set attr_form [_default_form $attr_name] + } + if { $attr_form eq "" } { + error "No form for $attr_name $attr_value" + } } set attr_form [_map_name $attr_form _FORM]