]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove uses of "eval" from gdb testsuite
authorTom Tromey <tom@tromey.com>
Sat, 13 Sep 2025 18:49:06 +0000 (12:49 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 14 Sep 2025 17:45:21 +0000 (11:45 -0600)
This patch removes a lot of uses of the Tcl "eval" proc from the gdb
test suite.  In most cases the {*} "splat" expansion is used instead.

A few uses of eval remain, primarily ones that were more complicated
to untangle.

In a couple of tests I also replaced some ad hoc code with
string_to_regexp.

Tested on x86-64 Fedora 40.

Reviewed-By: Tom de Vries <tdevries@suse.de>
22 files changed:
gdb/testsuite/boards/native-extended-gdbserver.exp
gdb/testsuite/gdb.ada/unchecked_union.exp
gdb/testsuite/gdb.base/attach-twice.exp
gdb/testsuite/gdb.base/consecutive.exp
gdb/testsuite/gdb.base/ctf-ptype.exp
gdb/testsuite/gdb.base/ending-run.exp
gdb/testsuite/gdb.base/gdbinit-history.exp
gdb/testsuite/gdb.base/ptype.exp
gdb/testsuite/gdb.base/style.exp
gdb/testsuite/gdb.linespec/ls-errs.exp
gdb/testsuite/gdb.mi/mi-break.exp
gdb/testsuite/gdb.opt/inline-break.exp
gdb/testsuite/gdb.reverse/consecutive-precsave.exp
gdb/testsuite/gdb.reverse/consecutive-reverse.exp
gdb/testsuite/gdb.tui/tuiterm.exp
gdb/testsuite/lib/dap-support.exp
gdb/testsuite/lib/dwarf.exp
gdb/testsuite/lib/gdb.exp
gdb/testsuite/lib/gdbserver-support.exp
gdb/testsuite/lib/mi-support.exp
gdb/testsuite/lib/trace-support.exp
gdb/testsuite/lib/tuiterm.exp

index 3299e3140589fc02f0fa68bb71db954505319af8..22d8782090583e2eab33cb0c86b3d5536f40f7ee 100644 (file)
@@ -58,7 +58,7 @@ proc mi_gdb_start { args } {
     global gdbserver_reconnect_p
 
     # Spawn GDB.
-    set res [eval extended_gdbserver_mi_gdb_start $args]
+    set res [extended_gdbserver_mi_gdb_start {*}$args]
     if { $res } {
        return $res
     }
index 89c059317688846a927ccbf77fb2846ea59758fb..5d29e28b4e545322b56df265603d8231a49d9efc 100644 (file)
@@ -26,7 +26,7 @@ proc multi_line_string {str} {
     foreach line [split $str \n] {
        lappend result [string_to_regexp $line]
     }
-    return [eval multi_line $result]
+    return [multi_line {*}$result]
 }
 
 set inner_string {    case ? is
index 3d7429839623dca968755c035cfea82087ee587e..63205e276d3c6c80584b62de4799a1dcf868a4b4 100644 (file)
@@ -45,6 +45,6 @@ gdb_test_multiple "attach $testpid" $test {
 }
 
 if {$parentpid != 0} {
-  eval exec kill -9 $parentpid
+    exec kill -9 $parentpid
 }
 kill_wait_spawned_process $test_spawn_id
index e73b3c3ffc366a031bc4aa12962393830f780f88..fa58a8f02fb650d45f3c93b80f4d9bd879e2810a 100644 (file)
@@ -54,7 +54,7 @@ gdb_test "break \*$bp_addr" "Breakpoint $decimal at $bp_addr: file .*" \
 gdb_test_multiple "step" "stopped at bp, 2nd instr" {
     -re -wrap "Breakpoint $decimal, ($hex) in foo.*" {
        set stop_addr $expect_out(1,string)
-       if {[eval expr "$bp_addr == $stop_addr"]} {
+       if {$bp_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
@@ -65,7 +65,7 @@ gdb_test_multiple "step" "stopped at bp, 2nd instr" {
        set stop_addr_is_stmt [hex_in_list $stop_addr $is_stmt]
        if {!$stop_addr_is_stmt} {
            fail "stopped at bp, 2nd instr (missing hex prefix)"
-       } elseif {[eval expr "$bp_addr == $stop_addr"]} {
+       } elseif {$bp_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
index 3f9023f3c715a2b96797c98122af8cfb8564cb16..6d55cb2614584eb9ca71a5c74f8481642b8289bd 100644 (file)
@@ -234,11 +234,10 @@ proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" }
     # Turn the arguments, which are literal strings, into
     # regular expressions by quoting any special characters they contain.
     foreach var { prototyped plain overprototyped } {
-       eval "set val \$$var"
-       regsub -all "\[\]\[*()\]" $val "\\\\&" val
+       set val [string_to_regexp [set $var]]
        regsub -all "short int" $val "short( int)?" val
        regsub -all "long int" $val "long( int)?" val
-       eval "set $var \$val"
+       set $var $val
     }
 
     gdb_test_multiple "ptype $id" "ptype $id" {
index 022ac28f04f1c445e3383e3bc79d520899defa36..0b5eadf806c60aa83e5480bda02a962b55e4bfdb 100644 (file)
@@ -224,7 +224,7 @@ set program_in_exit 0
 if {!$use_gdb_stub
     && (! [target_info exists use_cygmon] || ! [target_info use_cygmon])} {
     global program_exited
-    if {[eval expr $program_exited == 0]} {
+    if {$program_exited == 0} {
        gdb_test_multiple "n" "step to end of run" {
            -re "$inferior_exited_re normally.*$gdb_prompt $" {
                # If we actually have debug info for the start function,
index 48aae6b1766649676398646758690f0764818985..11a4a23c5289c69fc8ff692fd009a62775f736be 100644 (file)
@@ -141,7 +141,7 @@ proc check_history { hist } {
     if { [llength $hist_lines] == 1 } {
        set pattern [lindex $hist_lines 0]
     } else {
-       set pattern [eval multi_line $hist_lines]
+       set pattern [multi_line {*}$hist_lines]
     }
 
     # Check the history.
index 6971f4c8ca77251089edb7a2bac93609756c2063..04d2d2b0234fb7b9869d401c9497d5144e320a11 100644 (file)
@@ -528,11 +528,10 @@ proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" }
     # Turn the arguments, which are literal strings, into
     # regular expressions by quoting any special characters they contain.
     foreach var { prototyped plain overprototyped } {
-       eval "set val \$$var"
-       regsub -all "\[\]\[*()\]" $val "\\\\&" val
+       set val [string_to_regexp [set $var]]
        regsub -all "short int" $val "short( int)?" val
        regsub -all "long int" $val "long( int)?" val
-       eval "set $var \$val"
+       set $var $val
     }
 
     gdb_test_multiple "ptype $id" "ptype $id" {
index 6ab16ca9e01abb9eb0ed413c313c1b4936c68586..92b508520de0fe13cef98a589e62141fc6f77d73 100644 (file)
@@ -50,7 +50,7 @@ proc clean_restart_and_disable { prefix args } {
     global currently_disabled_style
 
     with_test_prefix "$prefix" {
-       eval "clean_restart $args"
+       clean_restart {*}$args
 
        if { $currently_disabled_style != "" } {
            set st $currently_disabled_style
index 303fd9f5ebb1df4d43e1209ddfa3eee6c94dae34..fc003ea4d8c5c7e019907da47ebe097a33eec0e7 100644 (file)
@@ -89,9 +89,8 @@ proc do_test {lang} {
     proc test_break {linespec msg_id args} {
        global error_messages
 
-       gdb_test "break $linespec" [string_to_regexp \
-                                   [eval format \$error_messages($msg_id) \
-                                    $args]] \
+       gdb_test "break $linespec" \
+           [string_to_regexp [format $error_messages($msg_id) {*}$args]] \
            "'break $linespec'"
     }
 
index 2a212c37496eccb9a95d4ba3ca06a0b30cdb16c3..cb7c14b48867cd4d8dc42aeedd8d47ae1055c52e 100644 (file)
@@ -346,7 +346,7 @@ proc_with_prefix test_forced_conditions {} {
 
     set loc [mi_make_breakpoint_loc -enabled "N"]
     set args [list -cond "bad" -locations "\\\[$loc\\\]"]
-    set bp [eval mi_make_breakpoint_multi $args]
+    set bp [mi_make_breakpoint_multi {*}$args]
 
     mi_gdb_test "-break-insert -c bad --force-condition callme" \
        "${warning}\\^done,$bp" \
index 7ecb3fadfbaf93965017d68ae1751c955c9c2b9c..0805f693e69f466685893bc2fd2fd0b7078fd13b 100644 (file)
@@ -209,7 +209,7 @@ foreach_with_prefix cmd [list "break" "tbreak"] {
     # that we actually stop where we think we should.
     for {set i 1} {$i < 4} {incr i} {
        foreach inline {"not_inline" "inline"} {
-           eval gdb_breakpoint "${inline}_func$i" $break_flags
+           gdb_breakpoint "${inline}_func$i" {*}$break_flags
        }
     }
 
index 2cb139d47bf0611adfa24b8bfb17133ee810ac56..3ccff48296bca16b132cfb45ff99b8c4d9b1ad2b 100644 (file)
@@ -79,7 +79,7 @@ set testmsg "stopped at bp, 2nd instr"
 gdb_test_multiple "step" $testmsg {
     -re -wrap "Breakpoint $decimal, ($hex) in foo.*" {
        set stop_addr $expect_out(1,string)
-       if {[eval expr "$foo2_addr == $stop_addr"]} {
+       if {$foo2_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
@@ -90,7 +90,7 @@ gdb_test_multiple "step" $testmsg {
        set stop_addr_is_stmt [hex_in_list $stop_addr $is_stmt]
        if { ! $stop_addr_is_stmt } {
            fail "stopped at bp, 2nd instr (missing hex prefix)"
-       } elseif {[eval expr "$foo2_addr == $stop_addr"]} {
+       } elseif {$foo2_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
@@ -112,7 +112,7 @@ set test_msg "stopped at bp in reverse, 1st instr"
 gdb_test_multiple "step" "$test_msg" {
     -re "Breakpoint $decimal, ($hex) in foo.*$gdb_prompt $" {
        set stop_addr $expect_out(1,string)
-       if {[eval expr "$foo1_addr == $stop_addr"]} {
+       if {$foo1_addr == $stop_addr} {
            pass "$test_msg"
        } else {
            fail "$test_msg (wrong address)"
index 27f2b72c5317054afab10ed466d98ab2ea7e624f..8996d792ed8c09b46eb08f2a9440c633ca700cc6 100644 (file)
@@ -61,7 +61,7 @@ set testmsg "stopped at bp, 2nd instr"
 gdb_test_multiple "step" $testmsg {
     -re -wrap "Breakpoint $decimal, ($hex) in foo.*" {
        set stop_addr $expect_out(1,string)
-       if {[eval expr "$foo2_addr == $stop_addr"]} {
+       if {$foo2_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
@@ -72,7 +72,7 @@ gdb_test_multiple "step" $testmsg {
        set stop_addr_is_stmt [hex_in_list $stop_addr $is_stmt]
        if { ! $stop_addr_is_stmt } {
            fail "stopped at bp, 2nd instr (missing hex prefix)"
-       } elseif {[eval expr "$foo2_addr == $stop_addr"]} {
+       } elseif {$foo2_addr == $stop_addr} {
            pass "stopped at bp, 2nd instr"
        } else {
            fail "stopped at bp, 2nd instr (wrong address)"
@@ -94,7 +94,7 @@ set test_msg "stopped at bp in reverse, 1st instr"
 gdb_test_multiple "step" "$test_msg" {
     -re "Breakpoint $decimal, ($hex) in foo.*$gdb_prompt $" {
        set stop_addr $expect_out(1,string)
-       if {[eval expr "$foo1_addr == $stop_addr"]} {
+       if {$foo1_addr == $stop_addr} {
            pass "$test_msg"
        } else {
            fail "$test_msg (wrong address)"
index ed9478a67d3292c3982ab78c991cad183fe1d3c8..a91643eba8b4ab35fe9cb17eaed51861b3f4d0d9 100644 (file)
@@ -807,7 +807,7 @@ proc test_attrs {} {
 proc run_one_test_small { test_proc_name } {
     save_vars { env(TERM) stty_init } {
        setup_small
-       eval $test_proc_name
+       $test_proc_name
     }
 }
 
@@ -816,7 +816,7 @@ proc run_one_test_small { test_proc_name } {
 proc run_one_test_large { test_proc_name } {
     save_vars { env(TERM) stty_init } {
        setup_large
-       eval $test_proc_name
+       $test_proc_name
     }
 }
 
index d61b1c47f3cd38bbe02fc5b294bb8ba7bd6c975e..3f0f75ab0ba151187fe40d1e0106373a412f763e 100644 (file)
@@ -443,7 +443,7 @@ proc dap_search_output {name rx events} {
 # key/value pairs given in ARGS.  NAME is used as the test name.
 proc dap_match_values {name d args} {
     foreach {key value} $args {
-       if {[eval dict get [list $d] $key] != $value} {
+       if {[dict get $d {*}$key] != $value} {
            fail "$name (checking $key)"
            return ""
        }
@@ -494,7 +494,7 @@ proc dap_wait_for_event_and_check {name type args} {
 
     set result [_dap_wait_for_event $type]
     set event [lindex $result 0]
-    eval dap_match_values [list $name $event] $args
+    dap_match_values $name $event {*}$args
 
     return $result
 }
index 3a182c22ea05c67955e4cac5a93b153a990953c9..c19240bfc2ee27e24ac0b78fb787e636ac9df5d1 100644 (file)
@@ -1094,7 +1094,7 @@ namespace eval Dwarf {
 
        if {![info exists _deferred_output($_defer)]} {
            set _deferred_output($_defer) ""
-           eval _section $section_spec
+           _section {*}$section_spec
        }
 
        uplevel $body
index 930462f63faeafca2e076322b9509c32066a0319..3c19f7110eafbfacc57abf2b3fa80611bfdd7e9f 100644 (file)
@@ -358,7 +358,7 @@ proc default_gdb_version {} {
     global inotify_pid
 
     if {[info exists inotify_pid]} {
-       eval exec kill $inotify_pid
+       exec kill $inotify_pid
     }
 
     set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
@@ -8266,7 +8266,7 @@ set temp [interp create]
 if { [interp eval $temp "info procs ::unknown"] != "" } {
     set old_args [interp eval $temp "info args ::unknown"]
     set old_body [interp eval $temp "info body ::unknown"]
-    eval proc gdb_tcl_unknown {$old_args} {$old_body}
+    proc gdb_tcl_unknown $old_args $old_body
 }
 interp delete $temp
 unset temp
@@ -8301,11 +8301,11 @@ proc gdb_finish { } {
     gdb_exit
 
     if { [llength $cleanfiles_target] > 0 } {
-       eval remote_file target delete $cleanfiles_target
+       remote_file target delete {*}$cleanfiles_target
        set cleanfiles_target {}
     }
     if { [llength $cleanfiles_host] > 0 } {
-       eval remote_file host delete $cleanfiles_host
+       remote_file host delete {*}$cleanfiles_host
        set cleanfiles_host {}
     }
 
@@ -9251,7 +9251,7 @@ proc build_executable { testname executable {sources ""} {options {debug}} } {
        lappend arglist $source $options
     }
 
-    return [eval build_executable_from_specs $arglist]
+    return [build_executable_from_specs {*}$arglist]
 }
 
 # Starts fresh GDB binary and loads an optional executable into GDB.
@@ -9306,7 +9306,7 @@ proc clean_restart {{executable ""}} {
 # Returns 0 on success, non-zero on failure.
 proc prepare_for_testing_full {testname args} {
     foreach spec $args {
-       if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
+       if {[build_executable_from_specs $testname {*}$spec] == -1} {
            return -1
        }
        set executable [lindex $spec 0]
@@ -9563,12 +9563,12 @@ proc relative_filename {root full} {
 
     set len [llength $root_split]
 
-    if {[eval file join $root_split]
-       != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
+    if {[file join {*}$root_split]
+       != [file join {*}[lrange $full_split 0 [expr {$len - 1}]]]} {
        error "$full not a subdir of $root"
     }
 
-    return [eval file join [lrange $full_split $len end]]
+    return [file join {*}[lrange $full_split $len end]]
 }
 
 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
@@ -9912,7 +9912,7 @@ proc run_on_host { test program args } {
     if {[llength $args] > 1 && [lindex $args 1] == ""} {
        set args [lreplace $args 1 1 "/dev/null"]
     }
-    set result [eval remote_exec host [list $program] $args]
+    set result [remote_exec host $program {*}$args]
     verbose "result is $result"
     set status [lindex $result 0]
     set output [lindex $result 1]
@@ -10716,14 +10716,14 @@ proc with_override { name override body } {
     # Install the override.
     set new_args [info_args_with_defaults $override]
     set new_body [info body $override]
-    eval proc $name {$new_args} {$new_body}
+    proc $name $new_args $new_body
 
     # Execute body.
     set code [catch {uplevel 1 $body} result]
 
     # Restore old proc if it existed on entry, else delete it.
     if { $existed } {
-       eval proc $name {$old_args} {$old_body}
+       proc $name $old_args $old_body
     } else {
        rename $name ""
     }
index 23892068c97879b14b4d975c0c6e1ba2df1964a3..6ff00baedebe42d5dcedd3e32d7abd0c60d83597 100644 (file)
@@ -125,7 +125,7 @@ proc gdb_target_cmd_ext { targetname serialport {additional_text ""} } {
 # Like gdb_target_cmd_ext, but returns 0 on success, 1 on failure.
 
 proc gdb_target_cmd { args } {
-    set res [eval gdb_target_cmd_ext $args]
+    set res [gdb_target_cmd_ext {*}$args]
     return [expr $res == 0 ? 0 : 1]
 }
 
index a3ae648c63ba3a09f5f7bfd684d2d2094d93b672..fcbcddcdf2f9d70d1356ecc53725cffbfe9cc4f4 100644 (file)
@@ -340,7 +340,7 @@ proc default_mi_gdb_start { { flags {} } } {
 # baseboard file.
 #
 proc mi_gdb_start { args } {
-  return [eval default_mi_gdb_start $args]
+    return [default_mi_gdb_start {*}$args]
 }
 
 # Many of the tests depend on setting breakpoints at various places and
@@ -1010,14 +1010,14 @@ proc mi_run_cmd_full {use_mi_command args} {
 # -exec-continue, as appropriate.  ARGS are passed verbatim to
 # mi_run_cmd_full.
 proc mi_run_cmd {args} {
-    return [eval mi_run_cmd_full 1 $args]
+    return [mi_run_cmd_full 1 {*}$args]
 }
 
 # A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and
 # 'continue', as appropriate.  ARGS are passed verbatim to
 # mi_run_cmd_full.
 proc mi_run_with_cli {args} {
-    return [eval mi_run_cmd_full 0 $args]
+    return [mi_run_cmd_full 0 {*}$args]
 }
 
 # Starts fresh GDB binary and loads an optional executable into GDB.
@@ -1397,7 +1397,7 @@ proc mi_continue_to {func} {
 # returns the breakpoint regexp from that procedure.
 
 proc mi_create_breakpoint {location test args} {
-    set bp [eval mi_make_breakpoint $args]
+    set bp [mi_make_breakpoint {*}$args]
     mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
     return $bp
 }
@@ -1406,7 +1406,7 @@ proc mi_create_breakpoint {location test args} {
 # locations using mi_make_breakpoint_multi instead.
 
 proc mi_create_breakpoint_multi {location test args} {
-    set bp [eval mi_make_breakpoint_multi $args]
+    set bp [mi_make_breakpoint_multi {*}$args]
     mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
     return $bp
 }
@@ -1414,7 +1414,7 @@ proc mi_create_breakpoint_multi {location test args} {
 # Like mi_create_breakpoint, but creates a pending breakpoint.
 
 proc mi_create_breakpoint_pending {location test args} {
-    set bp [eval mi_make_breakpoint_pending $args]
+    set bp [mi_make_breakpoint_pending {*}$args]
     mi_gdb_test "222-break-insert $location" ".*\r\n222\\^done,$bp" $test
     return $bp
 }
@@ -2686,7 +2686,7 @@ proc mi_make_info_frame_regexp {args} {
 proc mi_info_frame { test args } {
     parse_some_args {{frame ""} {thread ""}}
 
-    set re [eval mi_make_info_frame_regexp $args]
+    set re [mi_make_info_frame_regexp {*}$args]
 
     set cmd "235-stack-info-frame"
     if {$frame ne ""} {
index a8d0699ce54edb0b4d9db7da0f63ef6f3db64096..8543de322782a59b093b155181f20e6742ac18ef 100644 (file)
@@ -219,14 +219,14 @@ proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
 # gdb_trace_setactions_command.
 #
 proc gdb_trace_setactions { testname tracepoint args } {
-    eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
+    gdb_trace_setactions_command "actions" $testname $tracepoint {*}$args
 }
 
 # Define actions for a tracepoint, using the "commands" command.  See
 # gdb_trace_setactions_command.
 #
 proc gdb_trace_setcommands { testname tracepoint args } {
-    eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
+    gdb_trace_setactions_command "commands" $testname $tracepoint {*}$args
 }
 
 #
index 97017c779e69a9cde531eab90dbfb355282e0e2e..68fd6777b7c86474843bfb26f1d611385592821d 100644 (file)
@@ -1046,7 +1046,7 @@ proc Term::accept_gdb_output { {warn 1} } {
            scan $expect_out(1,string) %c val
            set hexval [format "%02x" $val]
            set cmd $expect_out(2,string)
-           eval _esc_0x${hexval}_$cmd
+           _esc_0x${hexval}_$cmd
        }
        -re "^(\[=>\])" {
            scan $expect_out(1,string) %c val
@@ -1081,13 +1081,13 @@ proc Term::accept_gdb_output { {warn 1} } {
        -re "^($re_csi_cmd)" {
            set cmd $expect_out(1,string)
            _log "wait_for: _csi_$cmd"
-           eval _csi_$cmd
+           _csi_$cmd
        }
        -re "^($re_csi_args*)($re_csi_cmd)" {
            set params [split $expect_out(1,string) ";"]
            set cmd $expect_out(2,string)
            _log "wait_for: _csi_$cmd <<<$params>>>"
-           eval _csi_$cmd $params
+           _csi_$cmd {*}$params
        }
        -re "^($re_csi_prefix?)($re_csi_args*)($re_csi_cmd)" {
            set prefix $expect_out(1,string)
@@ -1096,7 +1096,7 @@ proc Term::accept_gdb_output { {warn 1} } {
            scan $prefix %c val
            set hexval [format "%02x" $val]
            _log "wait_for: _csi_0x${hexval}_$cmd <<<$expect_out(1,string)>>>"
-           eval _csi_0x${hexval}_$cmd $params
+           _csi_0x${hexval}_$cmd {*}$params
        }
 
        timeout {