gdb/testsuite: make gdb_breakpoint and runto use options

Message ID 20221129213907.108082-1-simon.marchi@efficios.com
State New
Headers
Series gdb/testsuite: make gdb_breakpoint and runto use options |

Commit Message

Simon Marchi Nov. 29, 2022, 9:39 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

Change gdb_breakpoint and runto to use options (parsed with
parse_options) instead of simply looking up keywords in args.  It is
more robust what we generally prefer now, I believe.

runto passes its extra args directly to gdb_breakpoint, so it's easier
to change both at the same time.

Change-Id: Id1017345786bdf5940953521e67b291f065b9966
---
 gdb/testsuite/lib/gdb.exp | 43 +++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 20 deletions(-)


base-commit: 5def3e4501046380eedd7a2580f6d6e0c3b67466
  

Comments

Simon Marchi Nov. 29, 2022, 9:41 p.m. UTC | #1
On 11/29/22 16:39, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> Change gdb_breakpoint and runto to use options (parsed with
> parse_options) instead of simply looking up keywords in args.  It is
> more robust what we generally prefer now, I believe.
> 
> runto passes its extra args directly to gdb_breakpoint, so it's easier
> to change both at the same time.
> 
> Change-Id: Id1017345786bdf5940953521e67b291f065b9966

Please disregard this one.  I sent the wrong patch, this one is part of a series
that isn't ready yet.

Simon
  

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index e22d7f532f5..fb4f9981313 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -597,32 +597,38 @@  proc gdb_starti_cmd { {inferior_args {}} } {
 
 # Set a breakpoint using LINESPEC.
 #
-# If there is an additional argument it is a list of options; the supported
-# options are:
+# OPTIONS may contain the following options, which take no argument:
 #
-#  - allow-pending
-#  - temporary
-#  - qualified
+#  - allow-pending: allow the breakpoint to be defined as pending
+#  - temporary: make the breakpoint temporary
+#  - qualified: pass -qualified to the break command
 #
 # The result is 1 for success, 0 for failure.
 
-proc gdb_breakpoint { linespec args } {
+proc gdb_breakpoint { linespec {options {}} } {
     global gdb_prompt
     global decimal
 
-    set pending_response n
-    if {[lsearch -exact $args allow-pending] != -1} {
-	set pending_response y
+    parse_options {
+        {allow-pending}
+	{temporary}
+	{qualified}
+    }
+
+    if { ${allow-pending} } {
+        set pending_response y
+    } else {
+        set pending_response n
     }
 
     set break_command "break"
     set break_message "Breakpoint"
-    if {[lsearch -exact $args temporary] != -1} {
+    if { $temporary } {
 	set break_command "tbreak"
 	set break_message "Temporary breakpoint"
     }
 
-    if {[lsearch -exact $args qualified] != -1} {
+    if { $qualified } {
 	append break_command " -qualified"
     }
 
@@ -658,27 +664,24 @@  proc gdb_breakpoint { linespec args } {
     return 1
 }    
 
-# Set breakpoint at function and run gdb until it breaks there.
+# Delete existing breakpoints, set breakpoint at LINESPEC and run gdb until it
+# break.
+#
 # Since this is the only breakpoint that will be set, if it stops
 # at a breakpoint, we will assume it is the one we want.  We can't
 # just compare to "function" because it might be a fully qualified,
 # single quoted C++ function specifier.
 #
-# If there are additional arguments, pass them to gdb_breakpoint.
+# OPTIONS is passed to gdb_breakpoint.
 
-proc runto { linespec args } {
+proc runto { linespec {options {}} } {
     global gdb_prompt
     global bkptno_numopt_re
     global decimal
 
     delete_breakpoints
 
-    # We need to use eval here to pass our varargs args to gdb_breakpoint
-    # which is also a varargs function.
-    # But we also have to be careful because $linespec may have multiple
-    # elements, and we don't want Tcl to move the remaining elements after
-    # the first to $args.  That is why $linespec is wrapped in {}.
-    if ![eval gdb_breakpoint {$linespec} $args] {
+    if { ![gdb_breakpoint $linespec $options] } {
 	return 0
     }