From 0cb5fde010aa64247bfc17daf86add3b253c6f3e Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 17 Feb 2026 19:20:50 +0100 Subject: [PATCH] [gdb/testsuite] Fix some incorrect uses of decimal Dejagnu defines $decimal as: ... set decimal "\[0-9\]+" ... If we add an equivalent definition in lib/gdb.exp: ... set decimal "(?:\[0-9\]+)" ... we run into this type of ERRORs: ... couldn't compile regular expression pattern: parentheses () not balanced ... This is due to using "\[$decimal\]" instead of "\\\[$decimal\\]" or "[subst_var {\[$decimal\]}]". Add such definitions of decimal and hex, and apply the same technique to positive and octal. Fix the errors mostly using subst_var. Tested on x86_64-linux. --- gdb/testsuite/gdb.base/catch-syscall.exp | 5 ++++- gdb/testsuite/gdb.base/dcache-flush.exp | 4 ++-- .../gdb.base/detach-in-breakpoint-commands.exp | 6 ++++-- gdb/testsuite/gdb.base/exit-in-condition.exp | 14 ++++++++------ gdb/testsuite/gdb.base/multi-forks.exp | 2 +- gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp | 2 +- gdb/testsuite/gdb.reverse/sigall-reverse.exp | 3 ++- .../gdb.threads/process-dies-while-detaching.exp | 3 ++- gdb/testsuite/gdb.threads/wp-replication.exp | 3 ++- gdb/testsuite/lib/gdb.exp | 13 +++++++++++-- 10 files changed, 37 insertions(+), 18 deletions(-) diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp index a40a765ce63..31a42e33b5f 100644 --- a/gdb/testsuite/gdb.base/catch-syscall.exp +++ b/gdb/testsuite/gdb.base/catch-syscall.exp @@ -151,7 +151,10 @@ proc insert_catch_syscall_with_arg { syscall } { # Trying to set the catchpoint set thistest "catch syscall with arguments, $syscall" - gdb_test "catch syscall $syscall" "Catchpoint $decimal \\(syscall \'?${syscall}\'?( \[${decimal}\])?\\)" $thistest + gdb_test "catch syscall $syscall" \ + [subst_vars \ + {Catchpoint $decimal \(syscall '?$syscall'?( \[$decimal\])?\)}] \ + $thistest check_info_bp_specific_syscall $syscall } diff --git a/gdb/testsuite/gdb.base/dcache-flush.exp b/gdb/testsuite/gdb.base/dcache-flush.exp index f1872af178e..7ed60e3e913 100644 --- a/gdb/testsuite/gdb.base/dcache-flush.exp +++ b/gdb/testsuite/gdb.base/dcache-flush.exp @@ -35,7 +35,7 @@ gdb_test "info dcache" \ [multi_line \ "Dcache $decimal lines of $decimal bytes each." \ "Contains data for (process $decimal|Thread \[^\r\n\]*)" \ - "Line 0: address $hex \[$decimal hits\].*" \ + [subst_vars {Line 0: address $hex \[$decimal hits\].*}] \ "Cache state: $decimal active lines, $decimal hits" ] \ "check dcache before flushing" @@ -59,6 +59,6 @@ gdb_test "info dcache" \ [multi_line \ "Dcache $decimal lines of $decimal bytes each." \ "Contains data for (process $decimal|Thread \[^\r\n\]*)" \ - "Line 0: address $hex \[$decimal hits\].*" \ + [subst_vars {Line 0: address $hex \[$decimal hits\].*}] \ "Cache state: $decimal active lines, $decimal hits" ] \ "check dcache before refilling" diff --git a/gdb/testsuite/gdb.base/detach-in-breakpoint-commands.exp b/gdb/testsuite/gdb.base/detach-in-breakpoint-commands.exp index 88778378c36..b0487b58436 100644 --- a/gdb/testsuite/gdb.base/detach-in-breakpoint-commands.exp +++ b/gdb/testsuite/gdb.base/detach-in-breakpoint-commands.exp @@ -34,7 +34,8 @@ gdb_test \ "End with.*" \ "detach in commands" -gdb_test "run" "\[Inferior $decimal \\(\[^\r\n\]*\\) detached\]" \ +gdb_test "run" \ + [subst_vars {\[Inferior $decimal \([^\r\n]*\) detached\]}] \ "run - detach" # Test kill in breakpoint commands. @@ -47,5 +48,6 @@ gdb_test \ "End with.*" \ "kill in commands" -gdb_test "run" "\[Inferior $decimal \\(\[^\r\n\]*\\) killed\]" \ +gdb_test "run" \ + [subst_vars {\[Inferior $decimal \([^\r\n]*\) killed\]}] \ "run - kill" diff --git a/gdb/testsuite/gdb.base/exit-in-condition.exp b/gdb/testsuite/gdb.base/exit-in-condition.exp index 8aa23e5090a..5e99f4f7747 100644 --- a/gdb/testsuite/gdb.base/exit-in-condition.exp +++ b/gdb/testsuite/gdb.base/exit-in-condition.exp @@ -30,9 +30,11 @@ if { [prepare_for_testing "prepare" $testfile $srcfile] != 0 } { gdb_test "break main if callexit()" "Breakpoint $decimal at .*" gdb_test "run" \ - "\[Inferior $decimal \\(\[^\r\n\]*\\) exited normally\].* -Error in testing condition for breakpoint $decimal:.* -The program being debugged exited while in a function called from GDB\\..* -Evaluation of the expression containing the function.* -\\(callexit\\) will be abandoned\\..* -No registers\\." + [multi_line \ + [subst_vars {\[Inferior $decimal \([^\r\n]*\) exited normally\]}] \ + "Error in testing condition for breakpoint $decimal:" \ + [string_to_regexp \ + "The program being debugged exited while in a function called from GDB."] \ + "Evaluation of the expression containing the function" \ + [string_to_regexp "(callexit) will be abandoned."] \ + [string_to_regexp "No registers."]] diff --git a/gdb/testsuite/gdb.base/multi-forks.exp b/gdb/testsuite/gdb.base/multi-forks.exp index e1c76a47ac2..63e83ca023a 100644 --- a/gdb/testsuite/gdb.base/multi-forks.exp +++ b/gdb/testsuite/gdb.base/multi-forks.exp @@ -150,7 +150,7 @@ for {set i 1} {$i <= 15} {incr i} { -re "Continuing\.\r\n" { exp_continue } - -re "\[New inferior $decimal \\(process $decimal\\)\]\r\n" { + -re "\\\[New inferior $decimal \\(process $decimal\\)\\\]\r\n" { exp_continue } -re -wrap "Breakpoint .* main .*exit.*" { diff --git a/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp index 402c58e97da..eb816e2add2 100644 --- a/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp +++ b/gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp @@ -42,7 +42,7 @@ gdb_test "run" "Breakpoint $decimal, solib_main.*" "run with breakpoint" delete_breakpoints gdb_test "with confirm off -- run" \ - "\[Inferior $decimal \\(\[^\r\n\]*\\) exited normally\]" \ + [subst_vars {\[Inferior $decimal \([^\r\n]*\) exited normally\]}] \ "run without breakpoint" set bp_location [gdb_get_line_number "result = solib_main"] diff --git a/gdb/testsuite/gdb.reverse/sigall-reverse.exp b/gdb/testsuite/gdb.reverse/sigall-reverse.exp index 0fef8db2c59..5f0ab640d18 100644 --- a/gdb/testsuite/gdb.reverse/sigall-reverse.exp +++ b/gdb/testsuite/gdb.reverse/sigall-reverse.exp @@ -255,7 +255,8 @@ gdb_test "continue" \ gdb_test "continue" "Breakpoint.*handle_TERM.*" "send signal TERM" with_timeout_factor 2 { - gdb_test "continue" "\[process ${::decimal} .*" "continue to signal exit" \ + gdb_test "continue" "Process record: inferior program stopped.*" \ + "continue to signal exit" \ "The next instruction is syscall exit_group.* program...y. or n. " \ "yes" } diff --git a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp index 70c912a027a..e394edf53ea 100644 --- a/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp +++ b/gdb/testsuite/gdb.threads/process-dies-while-detaching.exp @@ -173,7 +173,8 @@ proc do_detach {multi_process cmd child_exit} { gdb_test "detach" "Detaching from .*, process $decimal\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" \ "detach child" - gdb_test "inferior 1" "\[Switching to inferior $decimal\].*" \ + gdb_test "inferior 1" \ + [subst_vars {\[Switching to inferior $decimal .*}] \ "switch to parent" if {$cmd == "detach"} { diff --git a/gdb/testsuite/gdb.threads/wp-replication.exp b/gdb/testsuite/gdb.threads/wp-replication.exp index 782472b0bcc..d5f0ff0068c 100644 --- a/gdb/testsuite/gdb.threads/wp-replication.exp +++ b/gdb/testsuite/gdb.threads/wp-replication.exp @@ -130,6 +130,7 @@ set TRIGGERS [expr {$NR_THREADS * $hwatch_count * $NR_TRIGGERS_PER_THREAD}] # Move the threads and hit the watchpoints TRIGGERS times. for { set i 1 } { $i <= $TRIGGERS } { incr i } { - gdb_test continue "Continuing\\..*Hardware watchpoint ${::decimal}: watched_data\[${::decimal}\].*Old value = ${::decimal}.*New value = ${::decimal}.*thread_function \\(arg=$hex\\) at .*$srcfile.*" \ + gdb_test continue \ + "Continuing\\..*Hardware watchpoint ${::decimal}: watched_data\\\[${::decimal}\\\].*Old value = ${::decimal}.*New value = ${::decimal}.*thread_function \\(arg=$hex\\) at .*$srcfile.*" \ "Continue to watchpoint trigger $i out of ${TRIGGERS} on watched_data" } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 406c84f5fd8..5f53bb6de2c 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -30,7 +30,16 @@ if {$tool == ""} { } # Add "convience abbreviation" for positive decimals, without leading zeros. -set positive {[1-9][0-9]*} +set positive {(?:[1-9][0-9]*)} + +# Dejagnu defines decimal as one of the "convenience abbreviations". +# Override it with one that uses parentheses, which flushes incorrect uses +# like "\[Inferior $decimal\]". +set decimal {(?:[0-9]+)} + +# Dejagnu defines hex as one of the "convenience abbreviations". +# Override it with one that uses parentheses. +set hex {(?:0x[0-9A-Fa-f]+)} # Execute BODY, if COND wrapped in proc WRAP. # Instead of writing the verbose and repetitive: @@ -332,7 +341,7 @@ if {![info exists env(EXEEXT)]} { set EXEEXT $env(EXEEXT) } -set octal "\[0-7\]+" +set octal {(?:[0-7]+)} set inferior_exited_re "(?:\\\[Inferior ${::decimal} \\(\[^\n\r\]*\\) exited)" -- 2.47.3