[binutils-gdb] [gdb/testsuite] Fix gdb.tui/tailcall-msym.exp on ppc64-linux

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4ed310516eb76cbf650523a53f733060d3ae71b9

commit 4ed310516eb76cbf650523a53f733060d3ae71b9
Author: Tom de Vries <[email protected]>
Date:   Wed Aug 19 11:21:27 2026 +0200

    [gdb/testsuite] Fix gdb.tui/tailcall-msym.exp on ppc64-linux
    
    On ppc64-linux, with test-case gdb.tui/tailcall-msym.exp I ran into:
    ...
    FAIL: $exp: status bar says main
    ...
    
    The test-case:
    - compiles the source to executable tailcall-msym
    - gets some information about addresses
    - recompiles the source to assembly
    - adds some extra text to the assembly
    - compiles the updated assembly into tailcall-msym-updated
    
    The test-case source contains three functions: main, caller and callee.
    
    The idea is that the updated executable has the same instructions, but an
    additional function dumy_func at the location of the instructions of caller
    after the call to callee.
    
    On x86_64-linux, that looks like this:
    ...
    000000000040111d <caller>:
      40111d:       55                      push   %rbp
      40111e:       48 89 e5                mov    %rsp,%rbp
      401121:       e8 f0 ff ff ff          call   401116 <callee>
    
    0000000000401126 <dummy_func>:
      401126:       8b 05 e8 2e 00 00       mov    0x2ee8(%rip),%eax
      40112c:       83 c0 01                add    $0x1,%eax
      40112f:       89 05 df 2e 00 00       mov    %eax,0x2edf(%rip)
      401135:       8b 05 d9 2e 00 00       mov    0x2ed9(%rip),%eax
      40113b:       83 c0 01                add    $0x1,%eax
      40113e:       89 05 d0 2e 00 00       mov    %eax,0x2ed0(%rip)
      401144:       90                      nop
      401145:       5d                      pop    %rbp
      401146:       c3                      ret
    ...
    
    On ppc64-linux using the v1 ABI that doesn't work out (because of the complex
    way functions are laid out in assembly), and instead caller stays the same,
    but main is renamed to dummy_func:
    ...
    (gdb) p dummy_func
    $3 = {<text variable, no debug info>} 0x9b0 <dummy_func>
    (gdb) p main
    $4 = {<text variable, no debug info>} 0x9b0 <dummy_func>
    (gdb)
    ...
    
    There's a note in the test-case:
    ...
     # Emit a new size for function 'caller', the assembler seems happy
     # enough to just use this new length instead of the original length
     # the compiler emitted.
     #
     # If this is ever a problem then we'll need to parse through the
     # assembler file and remove the original .size directive.
    ...
    and I tried that out manually, but it didn't help either.
    
    Fix this by bailing out if not all four functions exist:
    ...
    UNSUPPORTED: $exp: couldn't find function main
    ...
    
    Likewise in gdb.base/tailcall-msym.exp.
    
    Tested on ppc64-linux and x86_64-linux.

Diff:
---
 gdb/testsuite/gdb.base/tailcall-msym.exp | 19 +++++++++++++++++++
 gdb/testsuite/gdb.tui/tailcall-msym.exp  | 27 ++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.base/tailcall-msym.exp b/gdb/testsuite/gdb.base/tailcall-msym.exp
index d6cd06f88cd..9ffaa7f17c1 100644
--- a/gdb/testsuite/gdb.base/tailcall-msym.exp
+++ b/gdb/testsuite/gdb.base/tailcall-msym.exp
@@ -132,6 +132,25 @@ if { [prepare_for_testing "prepare" ${testfile}-updated $asm_file {nodebug}] } {
     return
 }
 
+foreach func {caller callee main dummy_func} {
+    set re_found \
+	"^$valnum_re = {<text variable, no debug info>} $hex <$func>"
+
+    set found 0
+    gdb_test_multiple "p $func" "" {
+       -re -wrap $re_found {
+	   set found 1
+       }
+       -re -wrap "" {
+       }
+    }
+
+    if {!$found} {
+       unsupported "couldn't find function $func"
+       return
+    }
+}
+
 if {![runto callee]} {
     return
 }
diff --git a/gdb/testsuite/gdb.tui/tailcall-msym.exp b/gdb/testsuite/gdb.tui/tailcall-msym.exp
index 81b52355c01..1e13414f760 100644
--- a/gdb/testsuite/gdb.tui/tailcall-msym.exp
+++ b/gdb/testsuite/gdb.tui/tailcall-msym.exp
@@ -136,15 +136,36 @@ if { [build_executable "build" $real_testfile $asm_file {nodebug}] } {
 
 Term::clean_restart 24 80 $real_testfile
 
-if {![runto callee]} {
+if {![Term::prepare_for_tui]} {
+    unsupported "TUI not supported"
     return
 }
 
-if {![Term::enter_tui]} {
-    unsupported "TUI not supported"
+foreach func {caller callee main dummy_func} {
+    set re_found \
+	"^$valnum_re = {<text variable, no debug info>} $hex <$func>"
+
+    set found 0
+    gdb_test_multiple "p $func" "" {
+       -re -wrap $re_found {
+	   set found 1
+       }
+       -re -wrap "" {
+       }
+    }
+
+    if {!$found} {
+       unsupported "couldn't find function $func"
+       return
+    }
+}
+
+if {![runto callee]} {
     return
 }
 
+Term::command_no_prompt_prefix "tui enable"
+
 # Check the function name on display in the status bar.  The interesting
 # case here is 'caller', which is a tailcall function in an objfile with
 # no debug information.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.