From c1fb7bd33e4ec2bdb52f8a89cc3792a10384e410 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Wed, 2 Apr 2014 18:55:29 +0000 Subject: [PATCH] rdar://16424649 Clean up the DynamicValueTestCase Namely, I split off the part of the test that validates child counts to a separate test llvm-svn: 205450 --- .../dynamic_value_child_count/Makefile | 5 + .../TestDynamicValueChildCount.py | 94 +++++++++++++++++++ .../pass-to-base.cpp | 36 +++++++ .../cpp/dynamic-value/TestDynamicValue.py | 32 ------- .../lang/cpp/dynamic-value/pass-to-base.cpp | 28 ------ 5 files changed, 135 insertions(+), 60 deletions(-) create mode 100644 lldb/test/functionalities/dynamic_value_child_count/Makefile create mode 100644 lldb/test/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py create mode 100644 lldb/test/functionalities/dynamic_value_child_count/pass-to-base.cpp diff --git a/lldb/test/functionalities/dynamic_value_child_count/Makefile b/lldb/test/functionalities/dynamic_value_child_count/Makefile new file mode 100644 index 000000000000..ceb406ee2eab --- /dev/null +++ b/lldb/test/functionalities/dynamic_value_child_count/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := pass-to-base.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py b/lldb/test/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py new file mode 100644 index 000000000000..2de3b999d13b --- /dev/null +++ b/lldb/test/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py @@ -0,0 +1,94 @@ +""" +Test that dynamic values update their child count correctly +""" + +import os, time +import re +import unittest2 +import lldb, lldbutil +from lldbtest import * + +class DynamicValueChildCountTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + @dsym_test + @expectedFailurei386("to be figured out") + def test_get_dynamic_vals_with_dsym(self): + """Test fetching C++ dynamic values from pointers & references.""" + self.buildDsym(dictionary=self.getBuildFlags()) + self.do_get_dynamic_vals() + + @expectedFailureLinux # FIXME: This needs to be root-caused. It looks like the DWARF info is anticipating the derived class assignment. + @python_api_test + @dwarf_test + @expectedFailurei386("to be figured out") + def test_get_dynamic_vals_with_dwarf(self): + """Test fetching C++ dynamic values from pointers & references.""" + self.buildDwarf(dictionary=self.getBuildFlags()) + self.do_get_dynamic_vals() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + # Find the line number to break for main.c. + + self.main_third_call_line = line_number('pass-to-base.cpp', + '// Break here and check b has 0 children') + self.main_fourth_call_line = line_number('pass-to-base.cpp', + '// Break here and check b still has 0 children') + self.main_fifth_call_line = line_number('pass-to-base.cpp', + '// Break here and check b has one child now') + self.main_sixth_call_line = line_number('pass-to-base.cpp', + '// Break here and check b has 0 children again') + + + + + def do_get_dynamic_vals(self): + """Get argument vals for the call stack when stopped on a breakpoint.""" + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target from the debugger. + + target = self.dbg.CreateTarget (exe) + self.assertTrue(target, VALID_TARGET) + + # Set up our breakpoints: + + third_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_third_call_line) + self.assertTrue(third_call_bpt, + VALID_BREAKPOINT) + fourth_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_fourth_call_line) + self.assertTrue(fourth_call_bpt, + VALID_BREAKPOINT) + fifth_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_fifth_call_line) + self.assertTrue(fifth_call_bpt, + VALID_BREAKPOINT) + sixth_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_sixth_call_line) + self.assertTrue(sixth_call_bpt, + VALID_BREAKPOINT) + + # Now launch the process, and do not stop at the entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + b = self.frame().FindVariable("b").GetDynamicValue(lldb.eDynamicCanRunTarget) + self.assertTrue(b.GetNumChildren() == 0, "b has 0 children") + self.runCmd("continue") + self.assertTrue(b.GetNumChildren() == 0, "b still has 0 children") + self.runCmd("continue") + self.assertTrue(b.GetNumChildren() != 0, "b now has 1 child") + self.runCmd("continue") + self.assertTrue(b.GetNumChildren() == 0, "b didn't go back to 0 children") + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/functionalities/dynamic_value_child_count/pass-to-base.cpp b/lldb/test/functionalities/dynamic_value_child_count/pass-to-base.cpp new file mode 100644 index 000000000000..d9dd3529821e --- /dev/null +++ b/lldb/test/functionalities/dynamic_value_child_count/pass-to-base.cpp @@ -0,0 +1,36 @@ +#include +#include + +class BaseClass +{ +public: + BaseClass(); + virtual ~BaseClass() { } +}; + +class DerivedClass : public BaseClass +{ +public: + DerivedClass(); + virtual ~DerivedClass() { } +protected: + int mem; +}; + +BaseClass::BaseClass() +{ +} + +DerivedClass::DerivedClass() : BaseClass() +{ + mem = 101; +} + +int +main (int argc, char **argv) +{ + BaseClass *b = nullptr; // Break here and check b has 0 children + b = new DerivedClass(); // Break here and check b still has 0 children + b = nullptr; // Break here and check b has one child now + return 0; // Break here and check b has 0 children again +} diff --git a/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py b/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py index 43853945a259..84cf6a5935a1 100644 --- a/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py +++ b/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py @@ -40,15 +40,6 @@ class DynamicValueTestCase(TestBase): self.main_second_call_line = line_number('pass-to-base.cpp', '// Break here and get real address of reallyA.') - self.main_third_call_line = line_number('pass-to-base.cpp', - '// Break here and check b has 0 children') - self.main_fourth_call_line = line_number('pass-to-base.cpp', - '// Break here and check b still has 0 children') - self.main_fifth_call_line = line_number('pass-to-base.cpp', - '// Break here and check b has one child now') - - - def examine_value_object_of_this_ptr (self, this_static, this_dynamic, dynamic_location): @@ -129,15 +120,6 @@ class DynamicValueTestCase(TestBase): second_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_second_call_line) self.assertTrue(second_call_bpt, VALID_BREAKPOINT) - third_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_third_call_line) - self.assertTrue(third_call_bpt, - VALID_BREAKPOINT) - fourth_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_fourth_call_line) - self.assertTrue(fourth_call_bpt, - VALID_BREAKPOINT) - fifth_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_fifth_call_line) - self.assertTrue(fifth_call_bpt, - VALID_BREAKPOINT) # Now launch the process, and do not stop at the entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) @@ -251,20 +233,6 @@ class DynamicValueTestCase(TestBase): self.assertTrue (anotherA_loc == reallyA_loc) self.assertTrue (anotherA_value.GetTypeName().find ('B') == -1) - self.runCmd("continue") -# self.runCmd("frame select 0") -# self.runCmd("frame variable") - b = self.frame().FindVariable("b").GetDynamicValue(lldb.eDynamicCanRunTarget) - self.assertTrue(b.GetNumChildren() == 0, "b has 0 children") - self.runCmd("continue") -# self.runCmd("frame select 0") -# self.runCmd("frame variable") - self.assertTrue(b.GetNumChildren() == 0, "b still has 0 children") - self.runCmd("continue") -# self.runCmd("frame select 0") -# self.runCmd("frame variable") - self.assertTrue(b.GetNumChildren() != 0, "b now has 1 child") - if __name__ == '__main__': import atexit lldb.SBDebugger.Initialize() diff --git a/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp b/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp index 79ea332444b7..2bccf3303823 100644 --- a/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp +++ b/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp @@ -52,31 +52,6 @@ private: static A* my_global_A_ptr; -class BaseClass -{ -public: - BaseClass(); - virtual ~BaseClass() { } -}; - -class DerivedClass : public BaseClass -{ -public: - DerivedClass(); - virtual ~DerivedClass() { } -protected: - int mem; -}; - -BaseClass::BaseClass() -{ -} - -DerivedClass::DerivedClass() : BaseClass() -{ - mem = 101; -} - int main (int argc, char **argv) { @@ -90,8 +65,5 @@ main (int argc, char **argv) A reallyA (500); myB.doSomething (reallyA); // Break here and get real address of reallyA. - BaseClass *b = nullptr; // Break here and check b has 0 children - b = new DerivedClass(); // Break here and check b still has 0 children - b = nullptr; // Break here and check b has one child now return 0; }