Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 4/5] Test user-defined gdb commands and arguments stack
Date: Wed, 09 Nov 2016 00:26:00 -0000	[thread overview]
Message-ID: <1478650771-24430-5-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1478650771-24430-1-git-send-email-palves@redhat.com>

We're missing a test that makes sure that arguments to user-defined
commands are handled correctly when a user-defined command calls
another user-defined command / recurses.

The following patch changes that code, so add such a test first so we
can be confident won't be breaking this use case.

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* gdb.base/commands.exp (user_defined_command_args_stack_test):
	New procedure.
	(top level): Call it.
---
 gdb/testsuite/gdb.base/commands.exp | 59 +++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 0ac2267..a8f777f 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -370,6 +370,64 @@ proc_with_prefix user_defined_command_args_eval {} {
     gdb_test "command_args_eval 1 2 3" "argc = 3, 1 2 3" "execute command"
 }
 
+# Test that the $argc/$argN variables are pushed on/popped from the
+# args stack correctly when a user-defined command calls another
+# user-defined command (or in this case, recurses).
+
+proc_with_prefix user_defined_command_args_stack_test {} {
+    global gdb_prompt
+
+    gdb_test_multiple "define args_stack_command" \
+	"define args_stack_command" {
+	    -re "End with"  {
+		pass "define"
+	    }
+	}
+
+    # Make a command that refers to $argc/$argN before and after
+    # recursing.  Also, vary the number of arguments passed to each
+    # recursion point.
+    gdb_test \
+	[multi_line \
+	     {printf "before, argc = %d,", $argc} \
+	     {set $i = 0} \
+	     {while $i < $argc} \
+	     {  eval "printf \" %%d\", $arg%d", $i} \
+	     {  set $i = $i + 1} \
+	     {end} \
+	     {printf "\n"} \
+	     {} \
+	     {} \
+	     {if $argc == 3} \
+	     {  args_stack_command 21 22} \
+	     {end} \
+	     {if $argc == 2} \
+	     {  args_stack_command 11} \
+	     {end} \
+	     {} \
+	     {} \
+	     {printf "after, argc = %d,", $argc} \
+	     {set $i = 0} \
+	     {while $i < $argc} \
+	     {  eval "printf \" %%d\", $arg%d", $i} \
+	     {  set $i = $i + 1} \
+	     {end} \
+	     {printf "\n"} \
+	     {end}] \
+	"" \
+	"enter commands"
+
+    set expected \
+	[multi_line \
+	     "before, argc = 3, 31 32 33" \
+	     "before, argc = 2, 21 22" \
+	     "before, argc = 1, 11" \
+	     "after, argc = 1, 11" \
+	     "after, argc = 2, 21 22" \
+	     "after, argc = 3, 31 32 33"]
+    gdb_test "args_stack_command 31 32 33" $expected "execute command"
+}
+
 proc_with_prefix watchpoint_command_test {} {
     global gdb_prompt
 
@@ -891,6 +949,7 @@ infrun_breakpoint_command_test
 breakpoint_command_test
 user_defined_command_test
 user_defined_command_args_eval
+user_defined_command_args_stack_test
 watchpoint_command_test
 test_command_prompt_position
 deprecated_command_test
-- 
2.5.5


      parent reply	other threads:[~2016-11-09  0:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-09  0:19 [PATCH v2 0/5] Support an "unlimited" number of user-defined arguments Pedro Alves
2016-11-09  0:19 ` [PATCH v2 2/5] Further cleanup/modernization of gdb.base/commands.exp Pedro Alves
2016-11-09  3:02   ` Simon Marchi
2016-11-09 15:56     ` Pedro Alves
2016-11-09 15:59       ` Pedro Alves
2016-11-09 16:09         ` Simon Marchi
2016-11-09 16:16           ` Pedro Alves
2016-11-09 16:25             ` Simon Marchi
2016-11-09 18:51               ` Pedro Alves
2016-11-09 16:22           ` Pedro Alves
2016-11-09 16:37             ` Pedro Alves
2016-11-09 16:41               ` Pedro Alves
2016-11-09  0:19 ` [PATCH v2 1/5] gdb/testsuite: Introduce "proc_with_prefix" Pedro Alves
2016-11-09  1:56   ` Simon Marchi
2016-11-09  3:10   ` [PATCH] Make gdb.mi/user-selected-context-sync.exp use proc_with_prefix Simon Marchi
2016-11-09 15:15     ` Pedro Alves
2016-11-09 15:57       ` Simon Marchi
2016-11-09 11:50   ` [PATCH v2 1/5] gdb/testsuite: Introduce "proc_with_prefix" Yao Qi
2016-11-09  0:19 ` [PATCH v2 3/5] Fix PR 20559 - "eval" command and $arg0...$arg9/$argc substitution Pedro Alves
2016-11-09  0:25 ` [PATCH v2 5/5] Support an "unlimited" number of user-defined arguments Pedro Alves
2016-11-09  0:26 ` Pedro Alves [this message]

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=1478650771-24430-5-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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