[1/2] gdb/testsuite: fail less catastrophically in gdb.base/style.exp

Message ID 20250311190252.290553-1-simon.marchi@efficios.com
State New
Headers
Series [1/2] gdb/testsuite: fail less catastrophically in gdb.base/style.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply

Commit Message

Simon Marchi March 11, 2025, 7:02 p.m. UTC
  On Debian 12, with gcc 12 and ld 2.40, I get some failures when running:

    $ make check TESTS="gdb.base/style.exp" RUNTESTFLAGS="--target_board=fission"

I think I stumble on this bug [1], preventing to do the
disassembling that the test needs:

    $ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.base/style/style
    Reading symbols from testsuite/outputs/gdb.base/style/style...
    (gdb) x/1i *main
    DW_FORM_strp pointing outside of .debug_str section [in module /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/style/style]
    (gdb)

The regexp in get_single_disassembled_insn fails to match, the insn
variable doesn't get set, and we get one of those unreadable TCL stack
traces:

    ERROR: tcl error sourcing /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/style.exp.
    ERROR: tcl error code TCL READ VARNAME
    ERROR: can't read "insn": no such variable
        while executing
    "return $insn"
        (procedure "get_single_disassembled_insn" line 4)
        invoked from within
    "get_single_disassembled_insn"
        ("uplevel" body line 18)
        invoked from within
    "uplevel 1 $body"
        invoked from within
    ...

Check the return value of the regexp call, return an empty string on
failure.  Log a failure, so that we have a trace that something went
wrong, in case the tests done by the caller happen to pass by change.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111409

Change-Id: I5123d4cc0034da85a093a8531a22e972c10d94ca
---
 gdb/testsuite/gdb.base/style.exp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)


base-commit: 383aa019aea415567ff03c24bccd19dbb13e9e0b
  

Comments

Tom Tromey March 13, 2025, 3:32 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> Check the return value of the regexp call, return an empty string on
Simon> failure.  Log a failure, so that we have a trace that something went
Simon> wrong, in case the tests done by the caller happen to pass by change.

Looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 571cb0f1a158..f63dedc75675 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -431,7 +431,13 @@  proc test_disable_disassembler_styling { } {
 # disassembled instruction part.
 proc get_single_disassembled_insn {} {
     set disasm_line [capture_command_output "x/1i *main" ""]
-    regexp "^\[^:\]+:\\s*(.*)$" $disasm_line whole_match insn
+    set ret [regexp "^\[^:\]+:\\s*(.*)$" $disasm_line whole_match insn]
+
+    if { $ret == 0 } {
+	fail "failed to disassemble main"
+	return ""
+    }
+
     return $insn
 }
 
@@ -463,7 +469,10 @@  proc test_disassembler_error_handling { } {
 
 	# Disassemble a single instruction and ensure that the output
 	# has styling markers in it.
-	set insn_before [get_single_disassembled_insn]
+	with_test_prefix "before" {
+	    set insn_before [get_single_disassembled_insn]
+	}
+
 	gdb_assert { [regexp "\033" $insn_before] } \
 	    "have style markers when Pygments is working fine"
 
@@ -481,7 +490,10 @@  proc test_disassembler_error_handling { } {
 	    "setup replacement colorize_disasm function" \
 	    true
 
-	set insn_after [get_single_disassembled_insn]
+	with_test_prefix "after" {
+	    set insn_after [get_single_disassembled_insn]
+	}
+
 	gdb_assert { ![regexp "\033" $insn_after] } \
 	    "have no style markers when Pygments is broken"
     }