public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: pedro@palves.net, Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/2] gdb/testsuite: add mi_info_frame helper proc (and use it)
Date: Tue,  8 Aug 2023 15:45:51 +0100	[thread overview]
Message-ID: <58ef6e8eb1a094927b600c1649f6ebc281a93272.1691505844.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1691505844.git.aburgess@redhat.com>

New helper proc mi_info_frame which takes care of running the MI
-stack-info-frame command and matching its output.

Like the breakpoint helper procs, this new proc takes a name/value
argument list and uses this to build the expected result regexp.  This
means that we can now write something like:

  mi_info_frame "test name here" \
    -level 0 -func name -line 123

Instead of the current equivalent:

  mi_gdb_test "235-stack-info-frame" \
    "235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"name\",file=\".*\",fullname=\".*\",line=\"123\",arch=\".*\"\}" \
    "test name here"

There's also a helper proc mi_make_info_frame_regexp which is
responsible for building the 'frame={...}' part of the pattern.

I've update the two existing tests that use -stack-info-frame and
expect the command to succeed.  There is another test that runs
-stack-info-frame and expects the command to fail -- the helper proc
doesn't help with this case, so that test is not changed.
---
 gdb/testsuite/gdb.mi/mi-cmd-user-context.exp | 12 ++---
 gdb/testsuite/gdb.mi/mi-stack.exp            |  7 +--
 gdb/testsuite/lib/mi-support.exp             | 52 ++++++++++++++++++++
 3 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp b/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
index 6abdb94addd..b6877b6e0cd 100644
--- a/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
+++ b/gdb/testsuite/gdb.mi/mi-cmd-user-context.exp
@@ -84,9 +84,9 @@ mi_gdb_test "frame" \
 
 # Ask about a different frame in the current thread, the current frame
 # should not change.
-mi_gdb_test "-stack-info-frame --thread 2 --frame 1" \
-    "\\^done,frame=\{level=\"1\".*" \
-    "-stack-info-frame 1"
+mi_info_frame "-stack-info-frame 1" \
+    -thread 2 -frame 1 \
+    -level 1
 
 mi_gdb_test "thread" \
     ".*Current thread is 2.*" \
@@ -99,9 +99,9 @@ mi_gdb_test "frame" \
 
 # Ask about a different frame in a different thread.  After this the
 # current thread and frame should not have changed.
-mi_gdb_test "-stack-info-frame --thread 3 --frame 1" \
-    "\\^done,frame=\{level=\"1\".*" \
-    "-stack-info-frame 2"
+mi_info_frame "-stack-info-frame 2" \
+    -thread 3 -frame 1 \
+    -level 1
 
 mi_gdb_test "thread" \
     ".*Current thread is 2.*" \
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index 777a425894f..592a3cfaba4 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -65,9 +65,10 @@ proc test_stack_frame_listing {} {
 	"234\\^error,msg=\"-stack-list-frames: Usage.*FRAME_LOW FRAME_HIGH.*\"" \
 	"stack frame listing wrong"
 
-    mi_gdb_test "235-stack-info-frame" \
-	"235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$callee4_begin\",arch=\"$any\"\}" \
-	"selected frame listing"
+    mi_info_frame "selected frame listing" \
+	-level 0 -addr $hex -func callee4 -file ".*${srcfile}" \
+	-fullname "${fullname_syntax}${srcfile}" -line $callee4_begin \
+	-arch $any
 
     mi_gdb_test "236-stack-list-frames 1 300" \
 	"236\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 49d5e2ef272..a1dbefe2e8d 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -2629,6 +2629,58 @@ proc mi_make_breakpoint_1 {attr_list thread cond evaluated-by times \
 }
 
 
+# Construct a regexp to match against a frame description as returned by
+# -stack-info-frame.  Take a list of name value pairs.  Valid names are
+# -level, -addr, -func, -file, -fullname, line, and -arch, each takes a
+# regexp which is matched against the corresponding field in the
+# -stack-info-frame output.
+
+proc mi_make_info_frame_regexp {args} {
+    parse_args [list [list level "$::decimal"] [list addr "$::hex"] \
+		    {func .*} {file .*} {fullname .*} \
+		    [list line "$::decimal"] {arch .*}]
+
+    set attr_list {}
+    foreach attr {level addr func file fullname line arch} {
+	lappend attr_list $attr [set $attr]
+    }
+
+    set result "frame=\\\{"
+    append result [mi_build_kv_pairs $attr_list]
+    append result "\\\}"
+    return $result
+}
+
+# Run the -stack-info-frame command and match the result, return true if the
+# test passes, otherwise, return false.
+#
+# TEST is the name used for this test.
+#
+# ARGS is an optional list of name value pairs, the names -frame and -thread
+# if present, expect a decimal argument and control the frame and thread for
+# which -stack-info-frame is run.  If -frame is not given then the
+# -stack-info-frame will operate on the current frame.  If -thread is not
+# given then -stack-info-frame will operate on the current thread.
+#
+# The remaining arguments are passed to mi_make_frame_regexp and are used to
+# build the regexp for matching against the -stack-info-frame output.
+
+proc mi_info_frame { test args } {
+    parse_args {{frame ""} {thread ""}}
+
+    set re [eval mi_make_info_frame_regexp $args]
+
+    set cmd "235-stack-info-frame"
+    if {$frame ne ""} {
+	append cmd " --frame ${frame}"
+    }
+    if {$thread ne ""} {
+	append cmd " --thread ${thread}"
+    }
+
+    return [mi_gdb_test $cmd "235\\^done,$re" $test]
+}
+
 # Construct a breakpoint regexp, for a breakpoint with multiple
 # locations.  This may be used to test the output of -break-insert,
 # -dprintf-insert, or -break-info with breakpoints with multiple
-- 
2.25.4


  reply	other threads:[~2023-08-08 14:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 14:45 [PATCH 0/2] Stop notifications when unwindonsignal is on Andrew Burgess
2023-08-08 14:45 ` Andrew Burgess [this message]
2023-08-08 14:45 ` [PATCH 2/2] gdb: MI stopped events " Andrew Burgess
2023-08-10 15:06   ` Thiago Jung Bauermann
2023-08-14 14:50     ` Andrew Burgess
2023-08-15  0:32       ` Thiago Jung Bauermann
2023-08-16 14:28         ` Andrew Burgess
2023-08-18 21:56           ` Thiago Jung Bauermann
2023-08-23  9:33             ` Andrew Burgess
2023-08-29 16:37   ` Simon Marchi
2023-09-08  8:54     ` Andrew Burgess
2023-09-08 10:03     ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58ef6e8eb1a094927b600c1649f6ebc281a93272.1691505844.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).