[2/2] gdb/testsuite/dwarf: use options for rnglists/loclists procs

Message ID 20210830152059.1426626-2-simon.marchi@polymtl.ca
State New
Headers show
Series
  • [1/2] gdb/testsuite/dwarf: don't define nested procs for rnglists/loclists
Related show

Commit Message

Tom de Vries via Gdb-patches Aug. 30, 2021, 3:20 p.m.
Change how rnglists and loclists procs to align them with how procs for
aranges (and other things in the DWARF assembler) work.  Instead of
using "args" (variable number of parameters in TCL) and command-line
style option arguments, use one leading "option" parameters, used as a
kind of key/value dictionary of options parsed using `parse_options`.

Change-Id: I63e60d17ae16a020ce4d6de44baf3d152ea42a1a
---
 gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp   |  4 +-
 .../gdb.dwarf2/loclists-multiple-cus.exp      |  6 +-
 .../gdb.dwarf2/loclists-sec-offset.exp        |  8 +-
 .../gdb.dwarf2/loclists-start-end.exp         |  6 +-
 .../gdb.dwarf2/rnglists-multiple-cus.exp      |  6 +-
 .../gdb.dwarf2/rnglists-sec-offset.exp        |  8 +-
 gdb/testsuite/lib/dwarf.exp                   | 83 ++++++-------------
 7 files changed, 46 insertions(+), 75 deletions(-)

-- 
2.33.0

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
index e43f59ea1ad1..305f4050d662 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp
@@ -81,8 +81,8 @@  foreach_with_prefix ranges_sect {ranges rnglists} {
 		}
 	    }
 
-	    rnglists {
-		table {
+	    rnglists {} {
+		table {} {
 		    rnglists_label: list_ {
 			start_end 0 1
 		    }
diff --git a/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp b/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
index 6b4f5c8cbb87..d74f3da8700e 100644
--- a/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
+++ b/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
@@ -87,17 +87,17 @@  foreach_with_prefix is_64 {false true} {
 	    }
 	}
 
-	loclists -is-64 $is_64 {
+	loclists {is-64 $is_64} {
 	    # This table is unused, but exists so that the used table is not at
 	    # the beginning of the section.
-	    table {
+	    table {} {
 		list_ {
 		    start_length 0x1000 0x1000 { DW_OP_addr 0x100000 }
 		}
 	    }
 
 	    # The lists in this table are accessed by index (DW_FORM_rnglistx).
-	    table -post-header-label cu_table {
+	    table {post-header-label cu_table} {
 		# This list is unused, but exists to offset the next ones.
 		list_ {
 		    start_length 0x1000 0x1000 { DW_OP_addr 0x100000 }
diff --git a/gdb/testsuite/gdb.dwarf2/loclists-sec-offset.exp b/gdb/testsuite/gdb.dwarf2/loclists-sec-offset.exp
index 573324af3d17..288b18f86bab 100644
--- a/gdb/testsuite/gdb.dwarf2/loclists-sec-offset.exp
+++ b/gdb/testsuite/gdb.dwarf2/loclists-sec-offset.exp
@@ -165,10 +165,10 @@  foreach_with_prefix is_64 {false true} {
 	    }
 	}
 
-	loclists -is-64 $is_64 {
+	loclists {is-64 $is_64} {
 	    # The lists in this table are accessed by direct offset
 	    # (DW_FORM_sec_offset).
-	    table {
+	    table {} {
 		foo_location_list: list_ {
 		    start_length $func1_addr $func1_len {
 			DW_OP_constu 0x123456
@@ -182,7 +182,7 @@  foreach_with_prefix is_64 {false true} {
 		}
 	    }
 
-	    table -post-header-label cu2_table {
+	    table {post-header-label cu2_table} {
 		bar_location_list: list_ {
 		    start_length $func3_addr $func3_len {
 			DW_OP_constu 0x345678
@@ -196,7 +196,7 @@  foreach_with_prefix is_64 {false true} {
 		}
 	    }
 
-	    table -with-offset-array false {
+	    table {with-offset-array false} {
 		baz_location_list: list_ {
 		    start_length $func5_addr $func5_len {
 			DW_OP_constu 0x567890
diff --git a/gdb/testsuite/gdb.dwarf2/loclists-start-end.exp b/gdb/testsuite/gdb.dwarf2/loclists-start-end.exp
index 43ddefcf61de..9302e4878bd3 100644
--- a/gdb/testsuite/gdb.dwarf2/loclists-start-end.exp
+++ b/gdb/testsuite/gdb.dwarf2/loclists-start-end.exp
@@ -78,17 +78,17 @@  foreach_with_prefix is_64 {false true} {
 	    }
 	}
 
-	loclists -is-64 $is_64 {
+	loclists {is-64 $is_64} {
 	    # This table is unused, but exists so that the used table is not at
 	    # the beginning of the section.
-	    table {
+	    table {} {
 		list_ {
 		    start_end 0x1000 0x2000 { DW_OP_addr 0x100000 }
 		}
 	    }
 
 	    # The lists in this table are accessed by index (DW_FORM_rnglistx).
-	    table -post-header-label cu_table {
+	    table {post-header-label cu_table} {
 		# This list is unused, but exists to offset the next ones.
 		list_ {
 		    start_end 0x1000 0x2000 { DW_OP_addr 0x100000 }
diff --git a/gdb/testsuite/gdb.dwarf2/rnglists-multiple-cus.exp b/gdb/testsuite/gdb.dwarf2/rnglists-multiple-cus.exp
index e09cd4e8fe73..2e83b37de66e 100644
--- a/gdb/testsuite/gdb.dwarf2/rnglists-multiple-cus.exp
+++ b/gdb/testsuite/gdb.dwarf2/rnglists-multiple-cus.exp
@@ -63,17 +63,17 @@  foreach_with_prefix is_64 {false true} {
 	    }
 	}
 
-	rnglists -is-64 $is_64 {
+	rnglists {is-64 $is_64} {
 	    # This table is unused, but exists so that the used table is not at
 	    # the beginning of the section.
-	    table {
+	    table {} {
 		list_ {
 		    start_end 0x1000 0x2000
 		}
 	    }
 
 	    # The lists in this table are accessed by index (DW_FORM_rnglistx).
-	    table -post-header-label cu_table {
+	    table {post-header-label cu_table} {
 		# This list is unused, but exists to offset the next ones.
 		list_ {
 		    start_end 0x2000 0x3000
diff --git a/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp b/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp
index 0733e90abc74..e5ae7772e954 100644
--- a/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp
+++ b/gdb/testsuite/gdb.dwarf2/rnglists-sec-offset.exp
@@ -90,10 +90,10 @@  foreach_with_prefix is_64 {false true} {
 	    }
 	}
 
-	rnglists -is-64 $is_64 {
+	rnglists {is-64 $is_64} {
 	    # The lists in this table are accessed by direct offset
 	    # (DW_FORM_sec_offset).
-	    table {
+	    table {} {
 		# For the first CU.
 		cu1_range_list: list_ {
 		    start_end 0x4000 0x5000
@@ -105,7 +105,7 @@  foreach_with_prefix is_64 {false true} {
 		}
 	    }
 
-	    table -post-header-label cu2_table {
+	    table {post-header-label cu2_table} {
 		# For the second CU.
 		cu2_range_list: list_ {
 		    start_end 0x5000 0x6000
@@ -117,7 +117,7 @@  foreach_with_prefix is_64 {false true} {
 		}
 	    }
 
-	    table -with-offset-array false {
+	    table {with-offset-array false} {
 		# For the third CU.
 		cu3_range_list: list_ {
 		    start_end 0x6000 0x7000
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index fbe93207c7a5..ac405f970935 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -1542,27 +1542,18 @@  namespace eval Dwarf {
     #
     # The target address size is based on the current target's address size.
     #
-    # There is one mandatory positional argument, BODY, which must be Tcl code
-    # that emits the content of the section.  It is evaluated in the caller's
-    # context.
+    # BODY must be Tcl code that emits the content of the section.  It is
+    # evaluated in the caller's context.
     #
-    # The following option can be used:
-    #
-    #  - -is-64 true|false: Whether to use 64-bit DWARF instead of 32-bit DWARF.
-    #                       The default is 32-bit.
+    # The `is-64 true|false` options tells whether to use 64-bit DWARF instead
+    # of 32-bit DWARF.  The default is 32-bit.
 
-    proc rnglists { args } {
+    proc rnglists { options body } {
 	variable _debug_rnglists_addr_size
 	variable _debug_rnglists_offset_size
 	variable _debug_rnglists_is_64_dwarf
 
-	parse_args {{"is-64" "false"}}
-
-	if { [llength $args] != 1 } {
-	    error "rnglists proc expects one positional argument (body)"
-	}
-
-	lassign $args body
+	parse_options {{"is-64" "false"}}
 
 	if [is_64_target] {
 	    set _debug_rnglists_addr_size 8
@@ -1602,34 +1593,29 @@  namespace eval Dwarf {
     # This proc is meant to be used within proc rnglists' body.  It is made
     # available as `table` while inside proc rnglists' body.
     #
-    # Accepts one positional argument, BODY.  BODY may call the LIST_ procedure
-    # to generate rnglists.
+    # BODY must be Tcl code that emits the content of the table.  It may call
+    # the LIST_ procedure to generate rnglists.  It is evaluated in the
+    # caller's context.
     #
-    # The -post-header-label option can be used to define a label just after
+    # The `post-header-label` option can be used to define a label just after
     # the header of the table.  This is the label that a DW_AT_rnglists_base
     # attribute will usually refer to.
     #
-    # The `-with-offset-array true|false` option can be used to control whether
+    # The `with-offset-array true|false` option can be used to control whether
     # the headers of the location list tables have an array of offset.  The
     # default is true.
 
-    proc _rnglists_table { args } {
+    proc _rnglists_table { options body } {
 	variable _debug_rnglists_table_count
 	variable _debug_rnglists_addr_size
 	variable _debug_rnglists_offset_size
 	variable _debug_rnglists_is_64_dwarf
 
-	parse_args {
+	parse_options {
 	    {post-header-label ""}
 	    {with-offset-array true}
 	}
 
-	if { [llength $args] != 1 } {
-	    error "table proc expects one positional argument (body)"
-	}
-
-	lassign $args body
-
 	# Count of lists in the table.
 	variable _debug_rnglists_list_count 0
 
@@ -1742,27 +1728,18 @@  namespace eval Dwarf {
     #
     # The target address size is based on the current target's address size.
     #
-    # There is one mandatory positional argument, BODY, which must be Tcl code
-    # that emits the content of the section.  It is evaluated in the caller's
-    # context.
-    #
-    # The following option can be used:
+    # BODY must be Tcl code that emits the content of the section.  It is
+    # evaluated in the caller's context.
     #
-    #  - -is-64 true|false: Whether to use 64-bit DWARF instead of 32-bit DWARF.
-    #                       The default is 32-bit.
+    # The `is-64 true|false` options tells whether to use 64-bit DWARF instead
+    # of 32-bit DWARF.  The default is 32-bit.
 
-    proc loclists { args } {
+    proc loclists { options body } {
 	variable _debug_loclists_addr_size
 	variable _debug_loclists_offset_size
 	variable _debug_loclists_is_64_dwarf
 
-	parse_args {{"is-64" "false"}}
-
-	if { [llength $args] != 1 } {
-	    error "loclists proc expects one positional argument (body)"
-	}
-
-	lassign $args body
+	parse_options {{"is-64" "false"}}
 
 	if [is_64_target] {
 	    set _debug_loclists_addr_size 8
@@ -1802,35 +1779,29 @@  namespace eval Dwarf {
     # This proc is meant to be used within proc loclists' body.  It is made
     # available as `table` while inside proc rnglists' body.
     #
-    # Accepts one position argument, BODY.  BODY may call the LIST_
-    # procedure to generate loclists.
+    # BODY must be Tcl code that emits the content of the table.  It may call
+    # the LIST_ procedure to generate rnglists.  It is evaluated in the
+    # caller's context.
     #
-    # The -post-header-label option can be used to define a label just after the
-    # header of the table.  This is the label that a DW_AT_loclists_base
+    # The `post-header-label` option can be used to define a label just after
+    # the header of the table.  This is the label that a DW_AT_loclists_base
     # attribute will usually refer to.
     #
-    # The `-with-offset-array true|false` option can be used to control
+    # The `with-offset-array true|false` option can be used to control
     # whether the headers of the location list tables have an array of
     # offset.  The default is true.
 
-    proc _loclists_table { args } {
+    proc _loclists_table { options body } {
 	variable _debug_loclists_table_count
 	variable _debug_loclists_addr_size
 	variable _debug_loclists_offset_size
 	variable _debug_loclists_is_64_dwarf
 
-	parse_args {
+	parse_options {
 	    {post-header-label ""}
 	    {with-offset-array true}
 	}
 
-	if { [llength $args] != 1 } {
-	    error "table proc expects one positional argument (body)"
-	}
-
-	lassign $args body
-
-
 	# Count of lists in the table.
 	variable _debug_loclists_list_count 0