gdb/testsuite: Make it possible to use TCL variables in DWARF assembler loclists

Message ID 20210706150230.169406-1-pedro@palves.net
State New
Headers show
Series
  • gdb/testsuite: Make it possible to use TCL variables in DWARF assembler loclists
Related show

Commit Message

Pedro Alves July 6, 2021, 3:02 p.m.
It is currently not possible to use variables in locations lists.  For
example, with:

  diff --git a/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp b/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
  index 6b4f5c8cbb8..cdbf948619f 100644
  --- a/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
  +++ b/gdb/testsuite/gdb.dwarf2/loclists-multiple-cus.exp
  @@ -30,6 +30,8 @@ if {![dwarf2_support]} {
       return 0
   }

  +set myconst 0x123456
  +
   # Test with 32-bit and 64-bit DWARF.
   foreach_with_prefix is_64 {false true} {
       if { $is_64 } {
  @@ -49,6 +51,7 @@ foreach_with_prefix is_64 {false true} {
	  global func1_addr func1_len
	  global func2_addr func2_len
	  global is_64
  +       global myconst

	  # The CU uses the DW_FORM_loclistx form to refer to the .debug_loclists
	  # section.
  @@ -107,7 +110,7 @@ foreach_with_prefix is_64 {false true} {
		  list_ {
		      # When in func1.
		      start_length $func1_addr $func1_len {
  -                       DW_OP_constu 0x123456
  +                       DW_OP_constu $myconst
			  DW_OP_stack_value
		      }

we get:

  $ make check TESTS="*/loclists-multiple-cus.exp"
  ...
  gdb compile failed, build/gdb/testsuite/outputs/gdb.dwarf2/loclists-multiple-cus/loclists-multiple-cus-dw32.S: Assembler messages:
  build/gdb/testsuite/outputs/gdb.dwarf2/loclists-multiple-cus/loclists-multiple-cus-dw32.S:78: Error: leb128 operand is an undefined symbol: $myconst
  ...

That means $myconst was copied literally to the generated assembly
file.

This patch fixes it, by running subst on the location list body, in
the context of the caller.  The fix is applied to both
Dwarf::loclists::table::list_::start_length and
Dwarf::loclists::table::list_::start_end.

Reported-by: Zoran Zaric <Zoran.Zaric@amd.com>

Change-Id: I615a64431857242d9f477d5699e3732df1b31322
---
 gdb/testsuite/lib/dwarf.exp | 4 ++++
 1 file changed, 4 insertions(+)


base-commit: 579f0281f38afffe2ae5692f6ce61598c5dbfe8c
-- 
2.26.2

Comments

Tom Tromey July 28, 2021, 6:02 p.m. | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:


Pedro> +		    set locdesc [uplevel "subst \"$locdesc\""]

This way of writing it seems un-idiomatic to me.  I suppose it would
only fail for weird expressions, like say an unmatched single quote.
But at the same time, I wonder if this other approach would still get
the desired results:

    set locdesc [uplevel [list subst $locdesc]]

This approach is used elsewhere in dwarf.exp.

If not, this is fine by me.

thanks,
Tom

Patch

diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 4e6879a2d3f..da14ccb728a 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -1830,6 +1830,8 @@  namespace eval Dwarf {
 		    variable _debug_loclists_list_count
 		    variable _debug_loclists_locdesc_count
 
+		    set locdesc [uplevel "subst \"$locdesc\""]
+
 		    _op .byte 0x08 "DW_LLE_start_length"
 
 		    # Start and end of the address range.
@@ -1859,6 +1861,8 @@  namespace eval Dwarf {
 		    variable _debug_loclists_list_count
 		    variable _debug_loclists_locdesc_count
 
+		    set locdesc [uplevel "subst \"$locdesc\""]
+
 		    _op .byte 0x07 "DW_LLE_start_end"
 
 		    # Start and end of the address range.