]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Fix some incorrect uses of decimal
authorTom de Vries <tdevries@suse.de>
Tue, 17 Feb 2026 18:20:50 +0000 (19:20 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 17 Feb 2026 18:20:50 +0000 (19:20 +0100)
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
gdb/testsuite/gdb.base/dcache-flush.exp
gdb/testsuite/gdb.base/detach-in-breakpoint-commands.exp
gdb/testsuite/gdb.base/exit-in-condition.exp
gdb/testsuite/gdb.base/multi-forks.exp
gdb/testsuite/gdb.base/solib-breakpoints-rerun.exp
gdb/testsuite/gdb.reverse/sigall-reverse.exp
gdb/testsuite/gdb.threads/process-dies-while-detaching.exp
gdb/testsuite/gdb.threads/wp-replication.exp
gdb/testsuite/lib/gdb.exp

index a40a765ce631126e13729254d581341e1a53cffa..31a42e33b5ff3ba0909831f6d8d8b4a37ee1f66d 100644 (file)
@@ -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
 }
index f1872af178e9bcd02d4e042dfc5c521b81d65713..7ed60e3e913a8f3e0aeab3db4ac76c27296dfb34 100644 (file)
@@ -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"
index 88778378c365149c80b82278020d060402097b2b..b0487b584367a0fa50a0d0c4051420138a43d003 100644 (file)
@@ -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"
index 8aa23e5090adbf16a35ea66f0141a5be1c379298..5e99f4f7747d982ad4077621d578c386f73953b1 100644 (file)
@@ -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."]]
index e1c76a47ac2b5d8a7756da694a39a50e0150de0e..63e83ca023a0f74cb4fb7916cea759b769e4ed54 100644 (file)
@@ -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.*" {
index 402c58e97da76fc4b3f481acf1d72b1850da29f2..eb816e2add201f36acc7b4cd95c94bea5b3e4005 100644 (file)
@@ -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"]
index 0fef8db2c5942e85f65386ae43d4619eaf494983..5f0ab640d1866b4389a72cb87773063c151101d9 100644 (file)
@@ -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"
 }
index 70c912a027a153876d120ac60d68d4eec2b8094b..e394edf53ea77d1a991cb00aebf45744984ca88d 100644 (file)
@@ -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"} {
index 782472b0bcc9c81a422ef544543120f12375e0e3..d5f0ff0068c1bfbcfb1fb27c9736d91330c69aa0 100644 (file)
@@ -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"
 }
index 406c84f5fd87e2c060dd9a51323de76bc68725dd..5f53bb6de2ca97cfebd8490897fef44dd8ea8a20 100644 (file)
@@ -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)"