From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8POdGftWKmGoFQAAWB0awg (envelope-from ) for ; Sat, 28 Aug 2021 11:32:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 626471EE1C; Sat, 28 Aug 2021 11:32:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 E902F1EE14 for ; Sat, 28 Aug 2021 11:32:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7846A3857410 for ; Sat, 28 Aug 2021 15:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7846A3857410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630164730; bh=nktT0k3y05scTuJ+U0QKVLhW+QlunnO1nnorPpOSyZI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=B+M1WP+903h9+Om6rDooCQdfCw8CBI/1bKpOqGqXQVX9P0+m6191vuGX3svwnzmWh Wxw/qW6stj6fRcTD8aFFWT6FK/odK7q9XtvNVqHDtiQikenft1BuTyjhIYdJP9b4JQ 46y74DfNNDzmn9MiDYrO6vQ+jgRYQE5qbTsDUpZI= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 1734D3858417 for ; Sat, 28 Aug 2021 15:31:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1734D3858417 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-out2.suse.de (Postfix) with ESMTPS id E16EE1FFBE; Sat, 28 Aug 2021 15:31:40 +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 B5C181340C; Sat, 28 Aug 2021 15:31:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id RJdPKtxWKmFFUAAAGKfGzw (envelope-from ); Sat, 28 Aug 2021 15:31:40 +0000 Subject: Re: [PATCH][gdb/testsuite] Support .debug_aranges in dwarf assembly To: Simon Marchi , Tom Tromey , Tom de Vries via Gdb-patches References: <20210826115625.GA22715@delia> <87eeafovsa.fsf@tromey.com> <40b7d95e-cc02-38c7-5406-0fc83a2a1b28@polymtl.ca> Message-ID: Date: Sat, 28 Aug 2021 17:31:40 +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: <40b7d95e-cc02-38c7-5406-0fc83a2a1b28@polymtl.ca> Content-Type: multipart/mixed; boundary="------------32D51CA641584CD6B1508911" 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------32D51CA641584CD6B1508911 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 8/27/21 5:09 PM, Simon Marchi via Gdb-patches wrote: > > > On 2021-08-27 9:35 a.m., 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. > > I personally don't like this style > > proc arange { arange_start arange_length {comment ""} {seg_sel ""} } > > ... because if you want to specify the last parameter, you need to give > all the other optional ones before. > > I also agree that just having: > > proc arange { args } > > is not great, since we have to do the argument parsing by hand, and it's > a bit opaque what the proc accepts. Could we consistently use the > "options" pattern, such as the one used by aranges and cu? > > proc arange { options arange_start arange_length } > > The callers would look like: > > arange {} $start $length > arange { > comment $comment > seg_sel $seg_sel > } $start $length > > I think that's a good compromise. I could re-do the rnglists procs this > way, if you'd like. > This patch implements that approach, using a new proc parse_options similar to parse_args. WDYT? Thanks, - Tom --------------32D51CA641584CD6B1508911 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-testsuite-Improve-argument-syntax-of-proc-arange.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-testsuite-Improve-argument-syntax-of-proc-arange.pa"; filename*1="tch" [gdb/testsuite] Improve argument syntax of proc arange --- gdb/testsuite/gdb.dlang/watch-loc.exp | 2 +- gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp | 6 +-- .../gdb.dwarf2/frame-inlined-in-outer-frame.exp | 2 +- .../template-specification-full-name.exp | 2 +- gdb/testsuite/lib/dwarf.exp | 30 ++++++-------- gdb/testsuite/lib/gdb.exp | 46 ++++++++++++++++------ 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/gdb/testsuite/gdb.dlang/watch-loc.exp b/gdb/testsuite/gdb.dlang/watch-loc.exp index 6e8b26e3109..e13400ed479 100644 --- a/gdb/testsuite/gdb.dlang/watch-loc.exp +++ b/gdb/testsuite/gdb.dlang/watch-loc.exp @@ -68,7 +68,7 @@ Dwarf::assemble $asm_file { } aranges {} cu_start { - arange $dmain_start $dmain_length + arange {} $dmain_start $dmain_length } } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp index e65b4c8610a..d55b7fd150e 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp @@ -125,9 +125,9 @@ Dwarf::assemble $asm_file { } aranges {} cu_label { - arange [lindex $main_func 0] [lindex $main_func 1] - arange [lindex $frame2_func 0] [lindex $frame2_func 1] - arange [lindex $frame3_func 0] [lindex $frame3_func 1] + arange {} [lindex $main_func 0] [lindex $main_func 1] + arange {} [lindex $frame2_func 0] [lindex $frame2_func 1] + arange {} [lindex $frame3_func 0] [lindex $frame3_func 1] } } diff --git a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp index ff12cd79f19..f95558dffef 100644 --- a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp +++ b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp @@ -95,7 +95,7 @@ Dwarf::assemble $dwarf_asm { } aranges {} cu_label { - arange __cu_low_pc __cu_high_pc + arange {} __cu_low_pc __cu_high_pc } } diff --git a/gdb/testsuite/gdb.dwarf2/template-specification-full-name.exp b/gdb/testsuite/gdb.dwarf2/template-specification-full-name.exp index 5c59777e1b6..6e736f2c8ef 100644 --- a/gdb/testsuite/gdb.dwarf2/template-specification-full-name.exp +++ b/gdb/testsuite/gdb.dwarf2/template-specification-full-name.exp @@ -69,7 +69,7 @@ Dwarf::assemble $asm_file { } aranges {} cu_start { - arange "$main_start" "$main_length" + arange {} "$main_start" "$main_length" } } diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 120fa418201..48fcbb0af78 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2212,7 +2212,12 @@ namespace eval Dwarf { # Emit a DWARF .debug_aranges entry. - proc arange { arange_start arange_length {comment ""} {seg_sel ""} } { + proc arange { options arange_start arange_length } { + parse_options { + { comment "" } + { seg_sel "" } + } + if { $comment != "" } { # Wrap set comment " ($comment)" @@ -2270,21 +2275,12 @@ namespace eval Dwarf { 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" } - } + parse_options { + { is_64 0 } + { cu_is_64 0 } + { section_version 2 } + { _seg_size 0 } } if { [is_64_target] } { @@ -2354,9 +2350,9 @@ namespace eval Dwarf { # Terminator tuple. set comment "Terminator" if { $_seg_size == 0 } { - arange 0 0 $comment + arange [list comment $comment] 0 0 } else { - arange 0 0 $comment 0 + arange [list comment $comment seg_sel 0] 0 0 } # End label. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 093392709b4..4ea11d4fd3f 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7293,8 +7293,8 @@ proc using_fission { } { return [regexp -- "-gsplit-dwarf" $debug_flags] } -# Search the caller's ARGS list and set variables according to the list of -# valid options described by ARGSET. +# Search LISTNAME in uplevel LEVEL caller and set variables according to the +# list of valid options with prefix PREFIX described by ARGSET. # # The first member of each one- or two-element list in ARGSET defines the # name of a variable that will be added to the caller's scope. @@ -7308,10 +7308,10 @@ proc using_fission { } { # # Any parse_args elements in (the caller's) ARGS will be removed, leaving # any optional components. - +# # Example: # proc myproc {foo args} { -# parse_args {{bar} {baz "abc"} {qux}} +# parse_list args 1 {{bar} {baz "abc"} {qux}} "-" # # ... # } # myproc ABC -bar -baz DEF peanut butter @@ -7319,34 +7319,38 @@ proc using_fission { } { # foo (=ABC), bar (=1), baz (=DEF), and qux (=0) # args will be the list {peanut butter} -proc parse_args { argset } { - upvar args args +proc parse_list { level listname argset prefix } { + upvar $level $listname args foreach argument $argset { if {[llength $argument] == 1} { # No default specified, so we assume that we should set # the value to 1 if the arg is present and 0 if it's not. # It is assumed that no value is given with the argument. - set result [lsearch -exact $args "-$argument"] + set result [lsearch -exact $args "$prefix$argument"] + if {$result != -1} then { - uplevel 1 [list set $argument 1] + set value 1 set args [lreplace $args $result $result] } else { - uplevel 1 [list set $argument 0] + set value 0 } + uplevel $level [list set $argument $value] } elseif {[llength $argument] == 2} { # There are two items in the argument. The second is a # default value to use if the item is not present. # Otherwise, the variable is set to whatever is provided # after the item in the args. set arg [lindex $argument 0] - set result [lsearch -exact $args "-[lindex $arg 0]"] + + set result [lsearch -exact $args "$prefix[lindex $arg 0]"] if {$result != -1} then { - uplevel 1 [list set $arg [lindex $args [expr $result+1]]] + set value [lindex $args [expr $result+1]] set args [lreplace $args $result [expr $result+1]] } else { - uplevel 1 [list set $arg [lindex $argument 1]] + set value [lindex $argument 1] } + uplevel $level [list set $arg $value] } else { error "Badly formatted argument \"$argument\" in argument set" } @@ -7356,6 +7360,24 @@ proc parse_args { argset } { # number of items expected to be passed into the procedure... } +# Search the caller's args variable and set variables according to the list of +# valid options described by ARGSET. + +proc parse_args { argset } { + parse_list 2 args $argset "-" +} + +# Process the caller's options variable and set variables according +# to the list of valid options described by OPTIONSET. + +proc parse_options { optionset } { + parse_list 2 options $optionset "" + upvar 1 options options + if { [llength $options] != 0 } { + error "Option left unparsed $options" + } +} + # Capture the output of COMMAND in a string ignoring PREFIX (a regexp); # return that string. --------------32D51CA641584CD6B1508911--