From: Tom de Vries <tdevries@suse.de>
To: Simon Marchi <simon.marchi@polymtl.ca>,
Tom Tromey <tom@tromey.com>,
Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH][gdb/testsuite] Support .debug_aranges in dwarf assembly
Date: Sun, 29 Aug 2021 17:31:23 +0200 [thread overview]
Message-ID: <c5d05bd3-0b68-e983-e257-05864803f0a3@suse.de> (raw)
In-Reply-To: <27d5091f-19e7-1f7f-8f0c-06e841c29d79@polymtl.ca>
[-- Attachment #1: Type: text/plain, Size: 3140 bytes --]
On 8/28/21 11:28 PM, Simon Marchi wrote:
>
>
> On 2021-08-28 4:29 p.m., Simon Marchi via Gdb-patches wrote:
>>
>>
>> On 2021-08-28 11:31 a.m., Tom de Vries wrote:
>>> 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 <gdb-patches@sourceware.org> writes:
>>>>>
>>>>> Tom> + # arange [-c <comment>] [<segment selector>] <start> <length>
>>>>> 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?
>>
>> Here:
>>
>> @@ -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
>> }
>>
>>
>> Could we apply some magic so that we are able to use { } instead of
>> list?
>>
>> arange {
>> comment $comment
>> set_seg 0
>> } { ... }
>>
>> ... instead of having to use [list ...]? I suppose doing an "eval" or
>> something of the option value in the caller's context?
>
> Here's a patch that does it using subst (as well as changes rnglists and
> loclists to use parse_options, but that should be in a separate patch):
>
OK, I've integrated the subst bit (and made it conditional, that was
still missing). Also added the subst part for the default arguments,
and added a proper log message. Any further comments?
[ FWIW, a bit of bike-shedding. I could imagine a pattern where you
pair a proc <name> and <name>_ like this:
...
proc arange_ { options start len } {
...
}
proc arange { start len } {
arange_ {} start len
}
...
to be able to do:
...
arange $start $len
...
and:
...
arange_ { comment "bla" } $start $len
...
which would be slightly less annoying that having to specify empty
options. ]
Thanks,
- Tom
[-- Attachment #2: 0001-gdb-testsuite-Improve-argument-syntax-of-proc-arange.patch --]
[-- Type: text/x-patch, Size: 8792 bytes --]
[gdb/testsuite] Improve argument syntax of proc arange
The current syntax of proc arange is:
...
proc arange { arange_start arange_length {comment ""} {seg_sel ""} } {
...
and a typical call looks like:
...
arange $start $len
...
This style is somewhat annoying because if you want to specify the last
parameter, you need to give all the other optional ones before as well:
...
arange $start $len "" $seg_sel
...
Update the syntax to:
...
proc arange { options arange_start arange_length } {
parse_options {
{ comment "" }
{ seg_sel "" }
}
...
such that a typical call looks like:
...
arange {} $start $len
...
and a call using seg_sel looks like:
...
arange {
seg_sel $seg_sel
} $start $len
...
Also update proc aranges, which already has an options argument, to use the
new proc parse_options.
Tested on x86_64-linux.
Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
---
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 | 52 +++++++++++++++++-----
6 files changed, 59 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..e248183d96a 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 {comment $comment} 0 0
} else {
- arange 0 0 $comment 0
+ arange {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..b1f90fcafbb 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,44 @@ 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 eval } {
+ 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]]
+ if { $eval } {
+ set value [uplevel [expr $level + 1] [list subst $value]]
+ }
set args [lreplace $args $result [expr $result+1]]
} else {
- uplevel 1 [list set $arg [lindex $argument 1]]
+ set value [lindex $argument 1]
+ if { $eval } {
+ set value [uplevel $level [list subst $value]]
+ }
}
+ uplevel $level [list set $arg $value]
} else {
error "Badly formatted argument \"$argument\" in argument set"
}
@@ -7356,6 +7366,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 "-" false
+}
+
+# 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 "" true
+ 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.
next prev parent reply other threads:[~2021-08-29 15:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 11:56 Tom de Vries
2021-08-27 13:35 ` Tom Tromey
2021-08-27 14:39 ` Tom de Vries
2021-08-27 15:09 ` Simon Marchi
2021-08-27 16:11 ` Keith Seitz
2021-08-27 16:14 ` Tom Tromey
2021-08-27 17:03 ` Simon Marchi
2021-08-27 17:10 ` Tom Tromey
2021-08-27 17:23 ` Simon Marchi
2021-08-28 15:31 ` Tom de Vries
2021-08-28 20:29 ` Simon Marchi
2021-08-28 21:28 ` Simon Marchi
2021-08-29 15:31 ` Tom de Vries [this message]
2021-08-29 19:54 ` Simon Marchi
2021-08-29 21:11 ` Tom de Vries
2021-08-30 8:35 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c5d05bd3-0b68-e983-e257-05864803f0a3@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).