diff mbox

Make gdb.python/python.exp more robust

Message ID 1484923030-16656-1-git-send-email-lgustavo@codesourcery.com
State New
Headers show

Commit Message

Luis Machado Jan. 20, 2017, 2:37 p.m. UTC
I noticed gdb.python/python.exp failing on aarch64-elf like so:

FAIL: gdb.python/python.exp: Test decode_line func1 line number

This particular test expects the line number for func1 to be 19, hardcoded.

In my aarch64-elf tests gdb thinks func1 is at line 20, making the test fail.

The following patch addresses this by reading the line number information from
GDB and comparing it against the python decoded symtab information.

Regression tested on x86-64/Ubuntu 16.04.

gdb/testsuite/ChangeLog:

2017-01-20  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.python/python.exp: Check line number against what GDB thinks
	the line number is for func1.
---
 gdb/testsuite/gdb.python/python.exp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Pedro Alves Jan. 20, 2017, 4:59 p.m. UTC | #1
On 01/20/2017 02:37 PM, Luis Machado wrote:

>  }
>  gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_1_c}" "test decode_line func1 filename"
> -gdb_test "python print (symtab\[1\]\[0\].line)" "19" "test decode_line func1 line number"
> +
> +# Fetch the line GDB thinks func1 starts at.  This may change depending
> +# on the architecture and on how GDB handles the prologue of the function.
> +gdb_test_multiple "info line func1" "info line func1" {
> +    -re "Line ($decimal) of .* starts at address $hex <func1> and ends at $hex <func1\\+$decimal>\.\[\r\n\]+$gdb_prompt $" {
> +	# Fetch the line number.
> +	set func1_lineno $expect_out(1,string)
> +    }
> +}

Do:

  set func1_lineno "noline"

before gdb_test_multiple, so that in case the above FAILs, this:

> +
> +gdb_test "python print (symtab\[1\]\[0\].line)" "$func1_lineno" "test decode_line func1 line number"

FAILs too, instead of ERRORing out with a TCL error, due to
undefined $func1_lineno.

OK with that change.

Thanks,
Pedro Alves
Luis Machado Jan. 20, 2017, 7:16 p.m. UTC | #2
On 01/20/2017 10:59 AM, Pedro Alves wrote:
> On 01/20/2017 02:37 PM, Luis Machado wrote:
>
>>  }
>>  gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_1_c}" "test decode_line func1 filename"
>> -gdb_test "python print (symtab\[1\]\[0\].line)" "19" "test decode_line func1 line number"
>> +
>> +# Fetch the line GDB thinks func1 starts at.  This may change depending
>> +# on the architecture and on how GDB handles the prologue of the function.
>> +gdb_test_multiple "info line func1" "info line func1" {
>> +    -re "Line ($decimal) of .* starts at address $hex <func1> and ends at $hex <func1\\+$decimal>\.\[\r\n\]+$gdb_prompt $" {
>> +	# Fetch the line number.
>> +	set func1_lineno $expect_out(1,string)
>> +    }
>> +}
>
> Do:
>
>   set func1_lineno "noline"
>

Indeed.

> before gdb_test_multiple, so that in case the above FAILs, this:
>
>> +
>> +gdb_test "python print (symtab\[1\]\[0\].line)" "$func1_lineno" "test decode_line func1 line number"
>
> FAILs too, instead of ERRORing out with a TCL error, due to
> undefined $func1_lineno.
>
> OK with that change.
>
> Thanks,
> Pedro Alves
>
>

Fixed and pushed as d334ae250a3ec888f0603cf8e909d0f425aeb30f.

Thanks,
Luis
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 95ec74e..f099cc0 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -246,7 +246,17 @@  if { [is_remote host] } {
     set python_1_c [string_to_regexp "gdb.python/python-1.c"]
 }
 gdb_test "python print (symtab\[1\]\[0\].symtab)" ".*${python_1_c}" "test decode_line func1 filename"
-gdb_test "python print (symtab\[1\]\[0\].line)" "19" "test decode_line func1 line number"
+
+# Fetch the line GDB thinks func1 starts at.  This may change depending
+# on the architecture and on how GDB handles the prologue of the function.
+gdb_test_multiple "info line func1" "info line func1" {
+    -re "Line ($decimal) of .* starts at address $hex <func1> and ends at $hex <func1\\+$decimal>\.\[\r\n\]+$gdb_prompt $" {
+	# Fetch the line number.
+	set func1_lineno $expect_out(1,string)
+    }
+}
+
+gdb_test "python print (symtab\[1\]\[0\].line)" "$func1_lineno" "test decode_line func1 line number"
 gdb_py_test_silent_cmd {python symtab = gdb.decode_line ("func1,func2")} \
     "test decode_line func1,func2" 1
 gdb_test {python print (symtab[0])} ",func2" "stop at comma in linespec"