From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 8BBB43858002 for ; Thu, 18 Mar 2021 15:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8BBB43858002 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 601D5562AC; Thu, 18 Mar 2021 11:58:28 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 0a89CKrVO7BN; Thu, 18 Mar 2021 11:58:28 -0400 (EDT) Received: from murgatroyd.Home (71-211-137-228.hlrn.qwest.net [71.211.137.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 1982C562A9; Thu, 18 Mar 2021 11:58:28 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add some error checking to DWARF assembler Date: Thu, 18 Mar 2021 09:58:26 -0600 Message-Id: <20210318155826.3703918-1-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 18 Mar 2021 15:58:29 -0000 I had written a DWARF location expression like DW_OP_const1u DW_OP_stack_value ... and was surprised to see that the DW_OP_stack_value didn't appear in the "readelf" output. The problem here is that DW_OP_const1u requires an operand, but neither the DWARF assembler nor gas diagnosed this problem. This patch adds some checking to Dwarf::_location to try to avoid this in the future. I removed some existing checks in the name of normalization; while the new messages are a bit worse (being one-size-fits-all), I think this doesn't matter hugely, since this should only be seen for test suite bugs. gdb/testsuite/ChangeLog 2021-03-18 Tom Tromey * lib/dwarf.exp (Dwarf::_check_n): New proc. (Dwarf::_location): Use it. --- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/lib/dwarf.exp | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index f8fbd381810..64b9e263f10 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -890,6 +890,13 @@ namespace eval Dwarf { } } + # Require N arguments for the opcode. + proc _check_n {line op n} { + if {[llength $line] != $n + 1} { + error "$op requires $n arguments" + } + } + # This is a miniature assembler for location expressions. It is # suitable for use in the attributes to a DIE. Its output is # prefixed with "=" to make it automatically use DW_FORM_block. @@ -926,56 +933,68 @@ namespace eval Dwarf { switch -exact -- $opcode { DW_OP_addr { + _check_n $line $opcode 1 _op .${addr_size}byte [lindex $line 1] } DW_OP_regx { + _check_n $line $opcode 1 _op .uleb128 [lindex $line 1] } DW_OP_pick - DW_OP_const1u - DW_OP_const1s { + _check_n $line $opcode 1 _op .byte [lindex $line 1] } DW_OP_const2u - DW_OP_const2s { + _check_n $line $opcode 1 _op .2byte [lindex $line 1] } DW_OP_const4u - DW_OP_const4s { + _check_n $line $opcode 1 _op .4byte [lindex $line 1] } DW_OP_const8u - DW_OP_const8s { + _check_n $line $opcode 1 _op .8byte [lindex $line 1] } DW_OP_constu { + _check_n $line $opcode 1 _op .uleb128 [lindex $line 1] } DW_OP_consts { + _check_n $line $opcode 1 _op .sleb128 [lindex $line 1] } DW_OP_plus_uconst { + _check_n $line $opcode 1 _op .uleb128 [lindex $line 1] } DW_OP_piece { + _check_n $line $opcode 1 _op .uleb128 [lindex $line 1] } DW_OP_bit_piece { + _check_n $line $opcode 2 _op .uleb128 [lindex $line 1] _op .uleb128 [lindex $line 2] } DW_OP_skip - DW_OP_bra { + _check_n $line $opcode 1 _op .2byte [lindex $line 1] } @@ -1000,9 +1019,7 @@ namespace eval Dwarf { DW_OP_implicit_pointer - DW_OP_GNU_implicit_pointer { - if {[llength $line] != 3} { - error "usage: $opcode LABEL OFFSET" - } + _check_n $line $opcode 2 # Here label is a section offset. set label [lindex $line 1] @@ -1015,9 +1032,7 @@ namespace eval Dwarf { } DW_OP_GNU_variable_value { - if {[llength $line] != 2} { - error "usage: $opcode LABEL" - } + _check_n $line $opcode 1 # Here label is a section offset. set label [lindex $line 1] @@ -1029,14 +1044,12 @@ namespace eval Dwarf { } DW_OP_deref_size { - if {[llength $line] != 2} { - error "usage: DW_OP_deref_size SIZE" - } - + _check_n $line $opcode 1 _op .byte [lindex $line 1] } DW_OP_bregx { + _check_n $line $opcode 2 _op .uleb128 [lindex $line 1] _op .sleb128 [lindex $line 2] } -- 2.26.2