Bug 31452 - [gdb/testsuite] FAIL: gdb.python/py-format-address.exp: symbol_filename=on: gdb.format_address, result should have an offset
Summary: [gdb/testsuite] FAIL: gdb.python/py-format-address.exp: symbol_filename=on: g...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: testsuite (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 16.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-05 23:37 UTC by Tom de Vries
Modified: 2024-06-20 14:54 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2024-03-05 23:37:45 UTC
On arm-linux, I ran into:
...
(gdb) python print("Got: " + gdb.format_address(0x103dd))^M
Got: 0x103dd <main at /home/vries/gdb/src/gdb/testsuite/gdb.python/py-format-address.c:30>^M
(gdb) FAIL: gdb.python/py-format-address.exp: symbol_filename=on: gdb.format_address, result should have an offset
...
Comment 1 Tom de Vries 2024-03-05 23:38:47 UTC
Tentative patch:
...
diff --git a/gdb/testsuite/gdb.python/py-format-address.c b/gdb/testsuite/gdb.python/py-format-address.c
index 2a0e9163db5..626bb41a220 100644
--- a/gdb/testsuite/gdb.python/py-format-address.c
+++ b/gdb/testsuite/gdb.python/py-format-address.c
@@ -28,5 +28,6 @@ FUNCTION_NAME (void)
 int
 main (void)
 {
-  return FUNCTION_NAME ();
+  int res = 0;
+  return res + FUNCTION_NAME ();
 }
diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp
index 8e7cf47e03a..0fd1e63b13f 100644
--- a/gdb/testsuite/gdb.python/py-format-address.exp
+++ b/gdb/testsuite/gdb.python/py-format-address.exp
@@ -40,7 +40,9 @@ 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]]
+
+gdb_test "next" "$decimal\[ \t\]+return .*"
+set next_addr [get_hexadecimal_valueof {$pc} "UNKNOWN"]
 
 foreach_with_prefix symbol_filename { on off } {
     gdb_test_no_output "set print symbol-filename ${symbol_filename}"
@@ -56,7 +58,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"
 }
 
...
Comment 3 Sourceware Commits 2024-06-20 14:53:49 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4429b54cc831e436d27ba6f0e3c417543c22f486

commit 4429b54cc831e436d27ba6f0e3c417543c22f486
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Jun 20 16:54:47 2024 +0200

    [gdb/testsuite] Fix gdb.python/py-format-address.exp on arm
    
    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 not at
    the very start of main.
    
    Tested on arm-linux.
    
    PR testsuite/31452
    Bug: https://www.sourceware.org/bugzilla/show_bug.cgi?id=31452
Comment 4 Tom de Vries 2024-06-20 14:54:20 UTC
Fixed.