[1/2] gdb/testsuite: allowed for function_range to deal with mangled functions

Message ID 20221013160114.4143323-2-blarsen@redhat.com
State New
Headers
Series Improve error messages with incomplete variables |

Commit Message

Guinevere Larsen Oct. 13, 2022, 4:01 p.m. UTC
  When calling get_func_info inside a test case, it would cause failures
if the function was printed using a C++ style mangled name. The current
patch fixes this by allowing for mangled names along with the current
rules.
---
 gdb/testsuite/lib/dwarf.exp | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

Andrew Burgess Oct. 31, 2022, 2:46 p.m. UTC | #1
Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:

> When calling get_func_info inside a test case, it would cause failures
> if the function was printed using a C++ style mangled name. The current
> patch fixes this by allowing for mangled names along with the current
> rules.

Instead of this approach, I would like to propose an alternative which I
believe also addresses this issue.  What do you think of this?

Thanks,
Andrew

---

commit b6d59ad650cfc552487c82a4eef49442b0642bca
Author: Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org>
Date:   Thu Oct 13 18:01:15 2022 +0200

    gdb/testsuite: allowed for function_range to deal with mangled functions
    
    When calling get_func_info inside a test case, it would cause failures
    if the function was printed using a C++ style mangled name.  Fix this
    by asking the disassembler to demangle symbols.

diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 593f4ea72f1..17faf06992e 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -400,7 +400,7 @@ proc function_range { func src {options {debug}} } {
     if { $func_length != 0 } {
 	set func_pattern "$func_pattern\\+$func_length"
     }
-    set test "x/2i $func+$func_length"
+    set test "with print asm-demangle on -- x/2i $func+$func_length"
     gdb_test_multiple $test $test {
 	-re ".*($hex) <$func_pattern>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
 	    set start $expect_out(1,string)
  
Guinevere Larsen Nov. 3, 2022, 3:46 p.m. UTC | #2
On 31/10/2022 15:46, Andrew Burgess wrote:
> Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:
>
>> When calling get_func_info inside a test case, it would cause failures
>> if the function was printed using a C++ style mangled name. The current
>> patch fixes this by allowing for mangled names along with the current
>> rules.
> Instead of this approach, I would like to propose an alternative which I
> believe also addresses this issue.  What do you think of this?

This sounds like a much better approach. Everyday I'm learning about 
some new thing in GDB.

Will send it like this on v2

Cheers,
Bruno

> Thanks,
> Andrew
>
> ---
>
> commit b6d59ad650cfc552487c82a4eef49442b0642bca
> Author: Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org>
> Date:   Thu Oct 13 18:01:15 2022 +0200
>
>      gdb/testsuite: allowed for function_range to deal with mangled functions
>      
>      When calling get_func_info inside a test case, it would cause failures
>      if the function was printed using a C++ style mangled name.  Fix this
>      by asking the disassembler to demangle symbols.
>
> diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
> index 593f4ea72f1..17faf06992e 100644
> --- a/gdb/testsuite/lib/dwarf.exp
> +++ b/gdb/testsuite/lib/dwarf.exp
> @@ -400,7 +400,7 @@ proc function_range { func src {options {debug}} } {
>       if { $func_length != 0 } {
>   	set func_pattern "$func_pattern\\+$func_length"
>       }
> -    set test "x/2i $func+$func_length"
> +    set test "with print asm-demangle on -- x/2i $func+$func_length"
>       gdb_test_multiple $test $test {
>   	-re ".*($hex) <$func_pattern>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
>   	    set start $expect_out(1,string)
>
  

Patch

diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index b85ec290299..351fc8fad6f 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -397,18 +397,28 @@  proc function_range { func src {options {debug}} } {
     # Take this into account by optionally allowing an argument list after
     # the function name.
     set func_pattern "$func\(\?\:\\(\.\*\\)\)?"
+    # It is also possible that the function is printed as
+    # <'mangled_func'base+[0-9]*> or similar.  Therefore, allow for starting
+    # with a mangled name, and followed by more mangling and offsets.
+    set func_mangled "\_\[a-zA-Z0-9\]\*$func.\*"
     if { $func_length != 0 } {
 	set func_pattern "$func_pattern\\+$func_length"
     }
     set test "x/2i $func+$func_length"
     gdb_test_multiple $test $test {
 	-re ".*($hex) <$func_pattern>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
 	    set start $expect_out(1,string)
 	    set end $expect_out(2,string)
 
+	    set func_length [expr $func_length + $end - $start]
+	}
+	-re ".*($hex) <$func_mangled>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
+	    set start $expect_out(1,string)
+	    set end $expect_out(2,string)
+
 	    set func_length [expr $func_length + $end - $start]
 	}
     }
 
     shared_gdb_end_use