public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Fix gdb.python/py-format-address.exp on arm
@ 2024-06-07 14:44 Tom de Vries
  2024-06-20 14:55 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2024-06-07 14:44 UTC (permalink / raw)
  To: gdb-patches

When running test-case gdb.python/py-format-address.exp on arm-linux, I get:
...
(gdb) python print("Got: " + gdb.format_address(0x103dd))^M
Got: 0x103dd <main at py-format-address.c:30>^M
(gdb) FAIL: $exp: symbol_filename=on: gdb.format_address, \
result should have an offset
...

What is expected here is:
...
Got: 0x103dd <main+1 at py-format-address.c:30>^M
...

Main starts at main_addr:
...
(gdb) print /x &main^M
$1 = 0x103dc^M
...
and we obtained next_addr 0x103dd by adding 1 to it:
...
set next_addr [format 0x%x [expr $main_addr + 1]]
...

Adding 1 to $main_addr results in an address for a thumb function starting at
address 0x103dc, which is incorrect because main is an arm function (because
I'm running with target board unix/-marm).

At some point during the call to format_addr, arm_addr_bits_remove removes
the thumb bit, which causes the +1 offset to be dropped, causing the FAIL.

Fix this by using the address of the breakpoint on main, provided it's on at
the very start of main.

Tested on arm-linux.

PR testsuite/31452
Bug: https://www.sourceware.org/bugzilla/show_bug.cgi?id=31452
---
 .../gdb.python/py-format-address.exp          | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp
index 8e7cf47e03a..ab8022c753b 100644
--- a/gdb/testsuite/gdb.python/py-format-address.exp
+++ b/gdb/testsuite/gdb.python/py-format-address.exp
@@ -40,7 +40,23 @@ if ![runto_main] {
 # for the program space and architecture (these will be selected based
 # on the current inferior).
 set main_addr [get_hexadecimal_valueof "&main" "UNKNOWN"]
-set next_addr [format 0x%x [expr $main_addr + 1]]
+require {!string equal $main_addr {UNKNOWN}}
+
+set next_addr "UNKNOWN"
+gdb_test_multiple "info break 1" "" {
+    -re -wrap " y +($hex) +in .*" {
+	set next_addr $expect_out(1,string)
+	set next_addr [regsub {^0x0+} $next_addr "0x"]
+	pass $gdb_test_name
+    }
+}
+if { $next_addr == "UNKNOWN" || $next_addr == $main_addr } {
+    set next_addr [format 0x%x [expr $main_addr + 1]]
+}
+
+verbose -log "main_addr: $main_addr"
+verbose -log "next_addr: $next_addr"
+
 
 foreach_with_prefix symbol_filename { on off } {
     gdb_test_no_output "set print symbol-filename ${symbol_filename}"
@@ -56,7 +72,7 @@ foreach_with_prefix symbol_filename { on off } {
 	"gdb.format_address, result should have no offset"
 
     gdb_test "python print(\"Got: \" + gdb.format_address($next_addr))" \
-	"Got: $next_addr <main\\+1${filename_pattern}>" \
+	"Got: $next_addr <main\\+$decimal${filename_pattern}>" \
 	"gdb.format_address, result should have an offset"
 }
 

base-commit: 1b8ad3bd6cd98260ae6c415f2ae87b4d813b1cb6
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb/testsuite] Fix gdb.python/py-format-address.exp on arm
  2024-06-07 14:44 [PATCH] [gdb/testsuite] Fix gdb.python/py-format-address.exp on arm Tom de Vries
@ 2024-06-20 14:55 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2024-06-20 14:55 UTC (permalink / raw)
  To: gdb-patches

On 6/7/24 16:44, Tom de Vries wrote:
> When running test-case gdb.python/py-format-address.exp on arm-linux, I get:
> ...
> (gdb) python print("Got: " + gdb.format_address(0x103dd))^M
> Got: 0x103dd <main at py-format-address.c:30>^M
> (gdb) FAIL: $exp: symbol_filename=on: gdb.format_address, \
> result should have an offset
> ...
> 
> What is expected here is:
> ...
> Got: 0x103dd <main+1 at py-format-address.c:30>^M
> ...
> 
> Main starts at main_addr:
> ...
> (gdb) print /x &main^M
> $1 = 0x103dc^M
> ...
> and we obtained next_addr 0x103dd by adding 1 to it:
> ...
> set next_addr [format 0x%x [expr $main_addr + 1]]
> ...
> 
> Adding 1 to $main_addr results in an address for a thumb function starting at
> address 0x103dc, which is incorrect because main is an arm function (because
> I'm running with target board unix/-marm).
> 
> At some point during the call to format_addr, arm_addr_bits_remove removes
> the thumb bit, which causes the +1 offset to be dropped, causing the FAIL.
> 
> Fix this by using the address of the breakpoint on main, provided it's on at
> the very start of main.
> 
> Tested on arm-linux.
> 

Pushed.

Thanks,
- Tom

> PR testsuite/31452
> Bug: https://www.sourceware.org/bugzilla/show_bug.cgi?id=31452
> ---
>   .../gdb.python/py-format-address.exp          | 20 +++++++++++++++++--
>   1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp
> index 8e7cf47e03a..ab8022c753b 100644
> --- a/gdb/testsuite/gdb.python/py-format-address.exp
> +++ b/gdb/testsuite/gdb.python/py-format-address.exp
> @@ -40,7 +40,23 @@ if ![runto_main] {
>   # for the program space and architecture (these will be selected based
>   # on the current inferior).
>   set main_addr [get_hexadecimal_valueof "&main" "UNKNOWN"]
> -set next_addr [format 0x%x [expr $main_addr + 1]]
> +require {!string equal $main_addr {UNKNOWN}}
> +
> +set next_addr "UNKNOWN"
> +gdb_test_multiple "info break 1" "" {
> +    -re -wrap " y +($hex) +in .*" {
> +	set next_addr $expect_out(1,string)
> +	set next_addr [regsub {^0x0+} $next_addr "0x"]
> +	pass $gdb_test_name
> +    }
> +}
> +if { $next_addr == "UNKNOWN" || $next_addr == $main_addr } {
> +    set next_addr [format 0x%x [expr $main_addr + 1]]
> +}
> +
> +verbose -log "main_addr: $main_addr"
> +verbose -log "next_addr: $next_addr"
> +
>   
>   foreach_with_prefix symbol_filename { on off } {
>       gdb_test_no_output "set print symbol-filename ${symbol_filename}"
> @@ -56,7 +72,7 @@ foreach_with_prefix symbol_filename { on off } {
>   	"gdb.format_address, result should have no offset"
>   
>       gdb_test "python print(\"Got: \" + gdb.format_address($next_addr))" \
> -	"Got: $next_addr <main\\+1${filename_pattern}>" \
> +	"Got: $next_addr <main\\+$decimal${filename_pattern}>" \
>   	"gdb.format_address, result should have an offset"
>   }
>   
> 
> base-commit: 1b8ad3bd6cd98260ae6c415f2ae87b4d813b1cb6


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-20 14:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-07 14:44 [PATCH] [gdb/testsuite] Fix gdb.python/py-format-address.exp on arm Tom de Vries
2024-06-20 14:55 ` Tom de Vries

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).