diff options
author | dim <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
commit | 78b9749c0a4ea980a8b934645da6ae98fcc665e8 (patch) | |
tree | dd2a1ddf0476664c2b823409c36cbccd52662ca7 /packages/Python/lldbsuite/test/tools/lldb-mi/stack | |
parent | 60cb593f9d55fa5ca7a5372b731f2330345b4b9a (diff) | |
download | FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.zip FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.tar.gz |
Vendor import of lldb trunk r256945:
https://llvm.org/svn/llvm-project/lldb/trunk@256945
Diffstat (limited to 'packages/Python/lldbsuite/test/tools/lldb-mi/stack')
3 files changed, 611 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/stack/Makefile b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/Makefile new file mode 100644 index 0000000..314f1cb --- /dev/null +++ b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py new file mode 100644 index 0000000..14dab38 --- /dev/null +++ b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/TestMiStack.py @@ -0,0 +1,479 @@ +""" +Test lldb-mi -stack-xxx commands. +""" + +from __future__ import print_function + + + +import lldbmi_testcase +from lldbsuite.test.lldbtest import * + +class MiStackTestCase(lldbmi_testcase.MiTestCaseBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_list_arguments(self): + """Test that 'lldb-mi --interpreter' can shows arguments.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test that -stack-list-arguments lists empty stack arguments if range is empty + self.runCmd("-stack-list-arguments 0 1 0") + self.expect("\^done,stack-args=\[\]") + + # Test that -stack-list-arguments lists stack arguments without values + # (and that low-frame and high-frame are optional) + self.runCmd("-stack-list-arguments 0") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[name=\"argc\",name=\"argv\"\]}") + self.runCmd("-stack-list-arguments --no-values") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[name=\"argc\",name=\"argv\"\]}") + + # Test that -stack-list-arguments lists stack arguments with all values + self.runCmd("-stack-list-arguments 1 0 0") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\".*\"}\]}\]") + self.runCmd("-stack-list-arguments --all-values 0 0") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\".*\"}\]}\]") + + # Test that -stack-list-arguments lists stack arguments with simple values + self.runCmd("-stack-list-arguments 2 0 1") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[{name=\"argc\",type=\"int\",value=\"1\"},{name=\"argv\",type=\"const char \*\*\",value=\".*\"}\]}") + self.runCmd("-stack-list-arguments --simple-values 0 1") + self.expect("\^done,stack-args=\[frame={level=\"0\",args=\[{name=\"argc\",type=\"int\",value=\"1\"},{name=\"argv\",type=\"const char \*\*\",value=\".*\"}\]}") + + # Test that an invalid low-frame is handled + # FIXME: -1 is treated as unsigned int + self.runCmd("-stack-list-arguments 0 -1 0") + #self.expect("\^error") + self.runCmd("-stack-list-arguments 0 0") + self.expect("\^error,msg=\"Command 'stack-list-arguments'\. Thread frame range invalid\"") + + # Test that an invalid high-frame is handled + # FIXME: -1 is treated as unsigned int + self.runCmd("-stack-list-arguments 0 0 -1") + #self.expect("\^error") + + # Test that a missing low-frame or high-frame is handled + self.runCmd("-stack-list-arguments 0 0") + self.expect("\^error,msg=\"Command 'stack-list-arguments'\. Thread frame range invalid\"") + + # Test that an invalid low-frame is handled + self.runCmd("-stack-list-arguments 0 0") + self.expect("\^error,msg=\"Command 'stack-list-arguments'\. Thread frame range invalid\"") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_list_locals(self): + """Test that 'lldb-mi --interpreter' can shows local variables.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test int local variables: + # Run to BP_local_int_test + line = line_number('main.cpp', '// BP_local_int_test') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"2\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-locals: use 0 or --no-values + self.runCmd("-stack-list-locals 0") + self.expect("\^done,locals=\[name=\"a\",name=\"b\"\]") + self.runCmd("-stack-list-locals --no-values") + self.expect("\^done,locals=\[name=\"a\",name=\"b\"\]") + + # Test -stack-list-locals: use 1 or --all-values + self.runCmd("-stack-list-locals 1") + self.expect("\^done,locals=\[{name=\"a\",value=\"10\"},{name=\"b\",value=\"20\"}\]") + self.runCmd("-stack-list-locals --all-values") + self.expect("\^done,locals=\[{name=\"a\",value=\"10\"},{name=\"b\",value=\"20\"}\]") + + # Test -stack-list-locals: use 2 or --simple-values + self.runCmd("-stack-list-locals 2") + self.expect("\^done,locals=\[{name=\"a\",type=\"int\",value=\"10\"},{name=\"b\",type=\"int\",value=\"20\"}\]") + self.runCmd("-stack-list-locals --simple-values") + self.expect("\^done,locals=\[{name=\"a\",type=\"int\",value=\"10\"},{name=\"b\",type=\"int\",value=\"20\"}\]") + + # Test struct local variable: + # Run to BP_local_struct_test + line = line_number('main.cpp', '// BP_local_struct_test') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"3\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-locals: use 0 or --no-values + self.runCmd("-stack-list-locals 0") + self.expect("\^done,locals=\[name=\"var_c\"\]") + self.runCmd("-stack-list-locals --no-values") + self.expect("\^done,locals=\[name=\"var_c\"\]") + + # Test -stack-list-locals: use 1 or --all-values + self.runCmd("-stack-list-locals 1") + self.expect("\^done,locals=\[{name=\"var_c\",value=\"{var_a = 10, var_b = 97 'a', inner_ = {var_d = 30}}\"}\]") + self.runCmd("-stack-list-locals --all-values") + self.expect("\^done,locals=\[{name=\"var_c\",value=\"{var_a = 10, var_b = 97 'a', inner_ = {var_d = 30}}\"}\]") + + # Test -stack-list-locals: use 2 or --simple-values + self.runCmd("-stack-list-locals 2") + self.expect("\^done,locals=\[{name=\"var_c\",type=\"my_type\"}\]") + self.runCmd("-stack-list-locals --simple-values") + self.expect("\^done,locals=\[{name=\"var_c\",type=\"my_type\"}\]") + + # Test array local variable: + # Run to BP_local_array_test + line = line_number('main.cpp', '// BP_local_array_test') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"4\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-locals: use 0 or --no-values + self.runCmd("-stack-list-locals 0") + self.expect("\^done,locals=\[name=\"array\"\]") + self.runCmd("-stack-list-locals --no-values") + self.expect("\^done,locals=\[name=\"array\"\]") + + # Test -stack-list-locals: use 1 or --all-values + self.runCmd("-stack-list-locals 1") + self.expect("\^done,locals=\[{name=\"array\",value=\"{\[0\] = 100, \[1\] = 200, \[2\] = 300}\"}\]") + self.runCmd("-stack-list-locals --all-values") + self.expect("\^done,locals=\[{name=\"array\",value=\"{\[0\] = 100, \[1\] = 200, \[2\] = 300}\"}\]") + + # Test -stack-list-locals: use 2 or --simple-values + self.runCmd("-stack-list-locals 2") + self.expect("\^done,locals=\[{name=\"array\",type=\"int \[3\]\"}\]") + self.runCmd("-stack-list-locals --simple-values") + self.expect("\^done,locals=\[{name=\"array\",type=\"int \[3\]\"}\]") + + # Test pointers as local variable: + # Run to BP_local_pointer_test + line = line_number('main.cpp', '// BP_local_pointer_test') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"5\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-locals: use 0 or --no-values + self.runCmd("-stack-list-locals 0") + self.expect("\^done,locals=\[name=\"test_str\",name=\"var_e\",name=\"ptr\"\]") + self.runCmd("-stack-list-locals --no-values") + self.expect("\^done,locals=\[name=\"test_str\",name=\"var_e\",name=\"ptr\"\]") + + # Test -stack-list-locals: use 1 or --all-values + self.runCmd("-stack-list-locals 1") + self.expect("\^done,locals=\[{name=\"test_str\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",value=\"24\"},{name=\"ptr\",value=\".*?\"}\]") + self.runCmd("-stack-list-locals --all-values") + self.expect("\^done,locals=\[{name=\"test_str\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",value=\"24\"},{name=\"ptr\",value=\".*?\"}\]") + + # Test -stack-list-locals: use 2 or --simple-values + self.runCmd("-stack-list-locals 2") + self.expect("\^done,locals=\[{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") + self.runCmd("-stack-list-locals --simple-values") + self.expect("\^done,locals=\[{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_list_variables(self): + """Test that 'lldb-mi --interpreter' can shows local variables and arguments.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test int local variables: + # Run to BP_local_int_test + line = line_number('main.cpp', '// BP_local_int_test_with_args') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"2\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-variables: use 0 or --no-values + self.runCmd("-stack-list-variables 0") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\"},{arg=\"1\",name=\"d\"},{name=\"a\"},{name=\"b\"}\]") + self.runCmd("-stack-list-variables --no-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\"},{arg=\"1\",name=\"d\"},{name=\"a\"},{name=\"b\"}\]") + + # Test -stack-list-variables: use 1 or --all-values + self.runCmd("-stack-list-variables 1") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\",value=\"30\"},{arg=\"1\",name=\"d\",value=\"40\"},{name=\"a\",value=\"10\"},{name=\"b\",value=\"20\"}\]") + self.runCmd("-stack-list-variables --all-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\",value=\"30\"},{arg=\"1\",name=\"d\",value=\"40\"},{name=\"a\",value=\"10\"},{name=\"b\",value=\"20\"}\]") + + # Test -stack-list-variables: use 2 or --simple-values + self.runCmd("-stack-list-variables 2") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\",type=\"int\",value=\"30\"},{arg=\"1\",name=\"d\",type=\"int\",value=\"40\"},{name=\"a\",type=\"int\",value=\"10\"},{name=\"b\",type=\"int\",value=\"20\"}\]") + self.runCmd("-stack-list-variables --simple-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"c\",type=\"int\",value=\"30\"},{arg=\"1\",name=\"d\",type=\"int\",value=\"40\"},{name=\"a\",type=\"int\",value=\"10\"},{name=\"b\",type=\"int\",value=\"20\"}\]") + + # Test struct local variable: + # Run to BP_local_struct_test + line = line_number('main.cpp', '// BP_local_struct_test_with_args') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"3\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-variables: use 0 or --no-values + self.runCmd("-stack-list-variables 0") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\"},{name=\"var_c\"}\]") + self.runCmd("-stack-list-variables --no-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\"},{name=\"var_c\"}\]") + + # Test -stack-list-variables: use 1 or --all-values + self.runCmd("-stack-list-variables 1") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\",value=\"{var_a = 20, var_b = 98 'b', inner_ = {var_d = 40}}\"},{name=\"var_c\",value=\"{var_a = 10, var_b = 97 'a', inner_ = {var_d = 30}}\"}\]") + self.runCmd("-stack-list-variables --all-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\",value=\"{var_a = 20, var_b = 98 'b', inner_ = {var_d = 40}}\"},{name=\"var_c\",value=\"{var_a = 10, var_b = 97 'a', inner_ = {var_d = 30}}\"}\]") + + # Test -stack-list-variables: use 2 or --simple-values + self.runCmd("-stack-list-variables 2") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\",type=\"my_type\"},{name=\"var_c\",type=\"my_type\"}\]") + self.runCmd("-stack-list-variables --simple-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"var_e\",type=\"my_type\"},{name=\"var_c\",type=\"my_type\"}\]") + + # Test array local variable: + # Run to BP_local_array_test + line = line_number('main.cpp', '// BP_local_array_test_with_args') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"4\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-variables: use 0 or --no-values + self.runCmd("-stack-list-variables 0") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\"},{name=\"array\"}\]") + self.runCmd("-stack-list-variables --no-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\"},{name=\"array\"}\]") + + # Test -stack-list-variables: use 1 or --all-values + self.runCmd("-stack-list-variables 1") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\",value=\".*?\"},{name=\"array\",value=\"{\[0\] = 100, \[1\] = 200, \[2\] = 300}\"}\]") + self.runCmd("-stack-list-variables --all-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\",value=\".*?\"},{name=\"array\",value=\"{\[0\] = 100, \[1\] = 200, \[2\] = 300}\"}\]") + + # Test -stack-list-variables: use 2 or --simple-values + self.runCmd("-stack-list-variables 2") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\",type=\"int \*\",value=\".*?\"},{name=\"array\",type=\"int \[3\]\"}\]") + self.runCmd("-stack-list-variables --simple-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"other_array\",type=\"int \*\",value=\".*?\"},{name=\"array\",type=\"int \[3\]\"}\]") + + # Test pointers as local variable: + # Run to BP_local_pointer_test + line = line_number('main.cpp', '// BP_local_pointer_test_with_args') + self.runCmd("-break-insert --file main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"5\"") + self.runCmd("-exec-continue") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test -stack-list-variables: use 0 or --no-values + self.runCmd("-stack-list-variables 0") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\"},{arg=\"1\",name=\"arg_ptr\"},{name=\"test_str\"},{name=\"var_e\"},{name=\"ptr\"}\]") + self.runCmd("-stack-list-variables --no-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\"},{arg=\"1\",name=\"arg_ptr\"},{name=\"test_str\"},{name=\"var_e\"},{name=\"ptr\"}\]") + + # Test -stack-list-variables: use 1 or --all-values + self.runCmd("-stack-list-variables 1") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\",value=\".*?String.*?\"},{arg=\"1\",name=\"arg_ptr\",value=\".*?\"},{name=\"test_str\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",value=\"24\"},{name=\"ptr\",value=\".*?\"}\]") + self.runCmd("-stack-list-variables --all-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\",value=\".*?String.*?\"},{arg=\"1\",name=\"arg_ptr\",value=\".*?\"},{name=\"test_str\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",value=\"24\"},{name=\"ptr\",value=\".*?\"}\]") + + # Test -stack-list-variables: use 2 or --simple-values + self.runCmd("-stack-list-variables 2") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\",type=\"const char \*\",value=\".*?String.*?\"},{arg=\"1\",name=\"arg_ptr\",type=\"int \*\",value=\".*?\"},{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") + self.runCmd("-stack-list-variables --simple-values") + self.expect("\^done,variables=\[{arg=\"1\",name=\"arg_str\",type=\"const char \*\",value=\".*?String.*?\"},{arg=\"1\",name=\"arg_ptr\",type=\"int \*\",value=\".*?\"},{name=\"test_str\",type=\"const char \*\",value=\".*?Rakaposhi.*?\"},{name=\"var_e\",type=\"int\",value=\"24\"},{name=\"ptr\",type=\"int \*\",value=\".*?\"}\]") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_info_depth(self): + """Test that 'lldb-mi --interpreter' can shows depth of the stack.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test that -stack-info-depth works + # (and that max-depth is optional) + self.runCmd("-stack-info-depth") + self.expect("\^done,depth=\"[1-9]\"") + + # Test that max-depth restricts check of stack depth + #FIXME: max-depth argument is ignored + self.runCmd("-stack-info-depth 1") + #self.expect("\^done,depth=\"1\"") + + # Test that invalid max-depth argument is handled + #FIXME: max-depth argument is ignored + self.runCmd("-stack-info-depth -1") + #self.expect("\^error") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + @skipUnlessDarwin + def test_lldbmi_stack_info_frame(self): + """Test that 'lldb-mi --interpreter' can show information about current frame.""" + + self.spawnLldbMi(args = None) + + # Test that -stack-info-frame fails when program isn't running + self.runCmd("-stack-info-frame") + self.expect("\^error,msg=\"Command 'stack-info-frame'\. Invalid process during debug session\"") + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test that -stack-info-frame works when program was stopped on BP + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\"\}") + + # Select frame #1 + self.runCmd("-stack-select-frame 1") + self.expect("\^done") + + # Test that -stack-info-frame works when specified frame was selected + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"1\",addr=\"0x[0-9a-f]+\",func=\".+?\",file=\"\?\?\",fullname=\"\?\?\",line=\"-1\"\}") + + # Test that -stack-info-frame fails when an argument is specified + #FIXME: unknown argument is ignored + self.runCmd("-stack-info-frame unknown_arg") + #self.expect("\^error") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_list_frames(self): + """Test that 'lldb-mi --interpreter' can lists the frames on the stack.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test stack frame: get frame #0 info + self.runCmd("-stack-list-frames 0 0") + self.expect("\^done,stack=\[frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\"\}\]") + + @skipIfWindows #llvm.org/pr24452: Get lldb-mi tests working on Windows + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_stack_select_frame(self): + """Test that 'lldb-mi --interpreter' can choose current frame.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f main") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Test that -stack-select-frame requires 1 mandatory argument + self.runCmd("-stack-select-frame") + self.expect("\^error,msg=\"Command 'stack-select-frame'\. Command Args\. Validation failed. Mandatory args not found: frame_id\"") + + # Test that -stack-select-frame fails on invalid frame number + self.runCmd("-stack-select-frame 99") + self.expect("\^error,msg=\"Command 'stack-select-frame'\. Frame ID invalid\"") + + # Test that current frame is #0 + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\"\}") + + # Test that -stack-select-frame can select the selected frame + self.runCmd("-stack-select-frame 0") + self.expect("\^done") + + # Test that current frame is still #0 + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\"\}") + + # Test that -stack-select-frame can select frame #1 (parent frame) + self.runCmd("-stack-select-frame 1") + self.expect("\^done") + + # Test that current frame is #1 + # Note that message is different in Darwin and Linux: + # Darwin: "^done,frame={level=\"1\",addr=\"0x[0-9a-f]+\",func=\"start\",file=\"??\",fullname=\"??\",line=\"-1\"}" + # Linux: "^done,frame={level=\"1\",addr=\"0x[0-9a-f]+\",func=\".+\",file=\".+\",fullname=\".+\",line=\"\d+\"}" + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"1\",addr=\"0x[0-9a-f]+\",func=\".+?\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\"\}") + + # Test that -stack-select-frame can select frame #0 (child frame) + self.runCmd("-stack-select-frame 0") + self.expect("\^done") + + # Test that current frame is #0 and it has the same information + self.runCmd("-stack-info-frame") + self.expect("\^done,frame=\{level=\"0\",addr=\"0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\"\}") diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp new file mode 100644 index 0000000..e11f83e --- /dev/null +++ b/packages/Python/lldbsuite/test/tools/lldb-mi/stack/main.cpp @@ -0,0 +1,127 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +struct inner +{ + int var_d; +}; + +struct my_type +{ + int var_a; + char var_b; + struct inner inner_; +}; + +int +local_int_test(void) +{ + int a = 10, b = 20; + return 0; // BP_local_int_test +} + +int +local_int_test_with_args(int c, int d) +{ + int a = 10, b = 20; + return 0; // BP_local_int_test_with_args +} + +int +local_struct_test(void) +{ + struct my_type var_c; + var_c.var_a = 10; + var_c.var_b = 'a'; + var_c.inner_.var_d = 30; + return 0; // BP_local_struct_test +} + +int local_struct_test_with_args(struct my_type var_e) +{ + struct my_type var_c; + var_c.var_a = 10; + var_c.var_b = 'a'; + var_c.inner_.var_d = 30; + return 0; // BP_local_struct_test_with_args +} + +int +local_array_test(void) +{ + int array[3]; + array[0] = 100; + array[1] = 200; + array[2] = 300; + return 0; // BP_local_array_test +} + +int +local_array_test_with_args(int* other_array) +{ + int array[3]; + array[0] = 100; + array[1] = 200; + array[2] = 300; + return 0; // BP_local_array_test_with_args +} + +int +local_pointer_test(void) +{ + const char *test_str = "Rakaposhi"; + int var_e = 24; + int *ptr = &var_e; + return 0; // BP_local_pointer_test +} + +int +local_pointer_test_with_args(const char *arg_str, int *arg_ptr) +{ + const char *test_str = "Rakaposhi"; + int var_e = 24; + int *ptr = &var_e; + return 0; // BP_local_pointer_test_with_args +} + +int do_tests_with_args() +{ + local_int_test_with_args(30, 40); + + struct my_type var_e; + var_e.var_a = 20; + var_e.var_b = 'b'; + var_e.inner_.var_d = 40; + local_struct_test_with_args(var_e); + + int array[3]; + array[0] = 400; + array[1] = 500; + array[2] = 600; + local_array_test_with_args(array); + + const char *test_str = "String"; + int var_z = 25; + int *ptr = &var_z; + local_pointer_test_with_args(test_str, ptr); + + return 0; +} + +int +main(int argc, char const *argv[]) +{ + local_int_test(); + local_struct_test(); + local_array_test(); + local_pointer_test(); + + do_tests_with_args(); + return 0; +} |