From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id B12B73858C60 for ; Fri, 27 Aug 2021 14:39:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B12B73858C60 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BC085223F1; Fri, 27 Aug 2021 14:39:36 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id A56E813927; Fri, 27 Aug 2021 14:39:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id GRpLJyj5KGHUcwAAGKfGzw (envelope-from ); Fri, 27 Aug 2021 14:39:36 +0000 Subject: Re: [PATCH][gdb/testsuite] Support .debug_aranges in dwarf assembly To: Tom Tromey , Tom de Vries via Gdb-patches References: <20210826115625.GA22715@delia> <87eeafovsa.fsf@tromey.com> From: Tom de Vries Message-ID: <339bd513-48c7-691f-faff-a3bffea787b7@suse.de> Date: Fri, 27 Aug 2021 16:39:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <87eeafovsa.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------BFC1495BA6369EE6DECC7692" Content-Language: en-US X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 27 Aug 2021 14:39:48 -0000 This is a multi-part message in MIME format. --------------BFC1495BA6369EE6DECC7692 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 8/27/21 3:35 PM, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries via Gdb-patches writes: > > Tom> + # arange [-c ] [] > Tom> + # -- adds an address range. > > I wonder if there's a way to make this more tcl-ish, say by rearranging > the order of arguments so that things can be defaulted. I think the > "args"-parsing style should normally be a last resort. > Done. > Tom> + proc arange { args } { > > This is nested in 'aranges', but that's weird style in Tcl. > It redefines the proc every time 'aranges' is invoked. > I think it's better to just namespace scope this. Done. Committed as attached. Thanks, - Tom --------------BFC1495BA6369EE6DECC7692 Content-Type: text/x-patch; charset=UTF-8; name="0002-gdb-testsuite-Support-.debug_aranges-in-dwarf-assembly.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0002-gdb-testsuite-Support-.debug_aranges-in-dwarf-assembly."; filename*1="patch" [gdb/testsuite] Support .debug_aranges in dwarf assembly Add a proc aranges such that we can generate .debug_aranges sections in dwarf assembly using: ... cu { label cu_label } { ... } aranges {} cu_label { arange $addr $len [] [$segment_selector] } ... Tested on x86_64-linux. --- gdb/testsuite/lib/dwarf.exp | 153 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 3aef58e8560..a058a78df2e 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2210,6 +2210,159 @@ namespace eval Dwarf { define_label $unit_end_label } + # Emit a DWARF .debug_aranges entry. + + proc arange { arange_start arange_length {comment ""} {seg_sel ""} } { + if { $comment != "" } { + # Wrap + set comment " ($comment)" + } + + if { $seg_sel != "" } { + variable _seg_size + if { $_seg_size == 8 } { + set seg_op .8byte + } elseif { $_seg_size == 4 } { + set seg_op .4byte + } else { + error \ + "Don't know how to handle segment selector size $_seg_size" + } + _op $seg_op $seg_sel "Address range segment selector$comment" + } + + variable _addr_size + if { $_addr_size == 8 } { + set addr_op .8byte + } elseif { $_addr_size == 4 } { + set addr_op .4byte + } + + _op $addr_op $arange_start "Address range start$comment" + _op $addr_op $arange_length "Address range length$comment" + } + + # Emit a DWARF .debug_aranges unit. + # + # OPTIONS is a list with an even number of elements containing + # option-name and option-value pairs. + # Current options are: + # is_64 0|1 - boolean indicating if you want to emit 64-bit DWARF + # default = 0 (32-bit) + # cu_is_64 0|1 - boolean indicating if LABEL refers to a 64-bit DWARF CU + # default = 0 (32-bit) + # section_version n + # - section version number to emit + # default = 2 + # seg_size n - the size of the adress selector in bytes: 0, 4, or 8 + # default = 0 + # + # LABEL is the label of the corresponding CU. + # + # BODY is Tcl code that emits the parts which make up the body of + # the aranges unit. It is evaluated in the caller's context. The + # following commands are available for the BODY section: + # + # arange [-c ] [] + # -- adds an address range. + + proc aranges { options label body } { + variable _addr_size + variable _seg_size + + # Establish the defaults. + set is_64 0 + set cu_is_64 0 + set section_version 2 + set _seg_size 0 + + # Handle options. + foreach { name value } $options { + switch -exact -- $name { + is_64 { set is_64 $value } + cu_is_64 { set cu_is_64 $value } + section_version {set section_version $value } + seg_size { set _seg_size $value } + default { error "unknown option $name" } + } + } + + if { [is_64_target] } { + set _addr_size 8 + } else { + set _addr_size 4 + } + + # Switch to .debug_aranges section. + _section .debug_aranges + + # Keep track of offset from start of section entry to determine + # padding amount. + set offset 0 + + # Initial length. + declare_labels aranges_start aranges_end + set length "$aranges_end - $aranges_start" + set comment "Length" + if { $is_64 } { + _op .4byte 0xffffffff + _op .8byte $length $comment + incr offset 12 + } else { + _op .4byte $length $comment + incr offset 4 + } + + # Start label. + aranges_start: + + # Section version. + _op .2byte $section_version "Section version" + incr offset 2 + + # Offset into .debug_info. + upvar $label my_label + if { $cu_is_64 } { + _op .8byte $my_label "Offset into .debug_info" + incr offset 8 + } else { + _op .4byte $my_label "Offset into .debug_info" + incr offset 4 + } + + # Address size. + _op .byte $_addr_size "Address size" + incr offset + + # Segment selector size. + _op .byte $_seg_size "Segment selector size" + incr offset + + # Padding. + set tuple_size [expr 2 * $_addr_size + $_seg_size] + while { 1 } { + if { [expr $offset % $tuple_size] == 0 } { + break + } + _op .byte 0 "Pad to $tuple_size byte boundary" + incr offset + } + + # Range tuples. + uplevel $body + + # Terminator tuple. + set comment "Terminator" + if { $_seg_size == 0 } { + arange 0 0 $comment + } else { + arange 0 0 $comment 0 + } + + # End label. + aranges_end: + } + proc _empty_array {name} { upvar $name the_array --------------BFC1495BA6369EE6DECC7692--