This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Test user-defined gdb commands and arguments stack


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ec835369f121c11d6e9484ed8c6c11097ad545c5

commit ec835369f121c11d6e9484ed8c6c11097ad545c5
Author: Pedro Alves <palves@redhat.com>
Date:   Fri Dec 2 19:17:13 2016 +0000

    Test user-defined gdb commands and arguments stack
    
    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:
    2016-12-02  Pedro Alves  <palves@redhat.com>
    
    	* gdb.base/commands.exp (user_defined_command_args_stack_test):
    	New procedure.
    	(top level): Call it.

Diff:
---
 gdb/testsuite/ChangeLog             |  6 ++++
 gdb/testsuite/gdb.base/commands.exp | 59 +++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c6ee462..bfae18b 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,11 @@
 2016-12-02  Pedro Alves  <palves@redhat.com>
 
+	* gdb.base/commands.exp (user_defined_command_args_stack_test):
+	New procedure.
+	(top level): Call it.
+
+2016-12-02  Pedro Alves  <palves@redhat.com>
+
 	PR cli/20559
 	* gdb.base/commands.exp (user_defined_command_args_eval): New
 	procedure.
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 3308a9b..ed85ee2 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -382,6 +382,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
 
@@ -913,6 +971,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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]