[Lldb-commits] [lldb] r245380 - Test chaned function calls and imported namespaces in C++

Paul Herman via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 18 15:43:37 PDT 2015


Author: paulherman
Date: Tue Aug 18 17:43:37 2015
New Revision: 245380

URL: http://llvm.org/viewvc/llvm-project?rev=245380&view=rev
Log:
Test chaned function calls and imported namespaces in C++

Added:
    lldb/trunk/test/lang/cpp/chained-calls/
    lldb/trunk/test/lang/cpp/chained-calls/Makefile
    lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py
    lldb/trunk/test/lang/cpp/chained-calls/main.cpp
    lldb/trunk/test/lang/cpp/nsimport/
    lldb/trunk/test/lang/cpp/nsimport/Makefile
    lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py
    lldb/trunk/test/lang/cpp/nsimport/main.cpp

Added: lldb/trunk/test/lang/cpp/chained-calls/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/chained-calls/Makefile?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/chained-calls/Makefile (added)
+++ lldb/trunk/test/lang/cpp/chained-calls/Makefile Tue Aug 18 17:43:37 2015
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py (added)
+++ lldb/trunk/test/lang/cpp/chained-calls/TestCppChainedCalls.py Tue Aug 18 17:43:37 2015
@@ -0,0 +1,94 @@
+import lldb
+from lldbtest import *
+import lldbutil
+
+class TestCppChainedCalls(TestBase):
+    
+    mydir = TestBase.compute_mydir(__file__)
+    
+    @skipUnlessDarwin
+    @dsym_test
+    def test_with_dsym_and_run_command(self):
+        self.buildDsym()
+        self.check()
+
+    @dwarf_test
+    def test_with_dwarf_and_run_command(self):
+        self.buildDwarf()
+        self.check()
+
+    def setUp(self):
+        TestBase.setUp(self)
+
+    def check(self):
+        # Get main source file
+        src_file = "main.cpp"
+        src_file_spec = lldb.SBFileSpec(src_file)
+        self.assertTrue(src_file_spec.IsValid(), "Main source file")
+        
+        # Get the path of the executable
+        cwd = os.getcwd() 
+        exe_file = "a.out"
+        exe_path  = os.path.join(cwd, exe_file)
+        
+        # Load the executable
+        target = self.dbg.CreateTarget(exe_path)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        # Break on main function
+        main_breakpoint = target.BreakpointCreateBySourceRegex("Break here", src_file_spec)
+        self.assertTrue(main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT)
+
+        # Launch the process
+        args = None
+        env = None
+        process = target.LaunchSimple(args, env, cwd)
+        self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
+
+        # Get the thread of the process
+        self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)
+        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+
+        # Get frame for current thread 
+        frame = thread.GetSelectedFrame()
+        
+        # Test chained calls
+        test_result = frame.EvaluateExpression("g(f(12345))")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 12345, "g(f(12345)) = 12345")
+
+        test_result = frame.EvaluateExpression("q(p()).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 12345678, "q(p()).a = 12345678")
+
+        test_result = frame.EvaluateExpression("(p() + r()).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "(p() + r()).a = 22345678")
+
+        test_result = frame.EvaluateExpression("q(p() + r()).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22345678, "q(p() + r()).a = 22345678")
+
+        test_result = frame.EvaluateExpression("g(f(6700) + f(89))")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 6789, "g(f(6700) + f(89)) = 6789")
+
+        test_result = frame.EvaluateExpression("g(f(g(f(300) + f(40))) + f(5))")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 345, "g(f(g(f(300) + f(40))) + f(5)) = 345")
+
+        test_result = frame.EvaluateExpression("getb(makeb(), 789)")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 789, "getb(makeb(), 789) = 789")
+
+        test_result = frame.EvaluateExpression("(*c).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 5678, "(*c).a = 5678")
+
+        test_result = frame.EvaluateExpression("(*c + *c).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11356, "(*c + *c).a = 11356")
+
+        test_result = frame.EvaluateExpression("q(*c + *c).a")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11356, "q(*c + *c).a = 11356")
+
+        test_result = frame.EvaluateExpression("make_int().get_type()")
+        self.assertTrue(test_result.IsValid() and test_result.GetValue() == "INT", "make_int().get_type() = \"INT\"")
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/lang/cpp/chained-calls/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/chained-calls/main.cpp?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/chained-calls/main.cpp (added)
+++ lldb/trunk/test/lang/cpp/chained-calls/main.cpp Tue Aug 18 17:43:37 2015
@@ -0,0 +1,186 @@
+class S
+{
+public:
+  S () { }
+  S (S &obj);
+
+  S operator+ (const S &s);
+
+  int a;
+};
+
+S::S (S &obj)
+{
+  a = obj.a;
+}
+
+S
+S::operator+ (const S &s)
+{
+  S res;
+
+  res.a = a + s.a;
+
+  return res;
+}
+
+S
+f (int i)
+{
+  S s;
+
+  s.a = i;
+
+  return s;
+}
+
+int
+g (const S &s)
+{
+  return s.a;
+}
+
+class A
+{
+public:
+  A operator+ (const A &);
+  int a;
+};
+
+A
+A::operator+ (const A &obj)
+{
+  A n;
+
+  n.a = a + obj.a;
+
+  return n;
+}
+
+A
+p ()
+{
+  A a;
+  a.a = 12345678;
+  return a;
+}
+
+A
+r ()
+{
+  A a;
+  a.a = 10000000;
+  return a;
+}
+
+A
+q (const A &a)
+{
+  return a;
+}
+
+class B
+{
+public:
+  int b[1024];
+};
+
+B
+makeb ()
+{
+  B b;
+  int i;
+
+  for (i = 0; i < 1024; i++)
+    b.b[i] = i;
+
+  return b;
+}
+
+int
+getb (const B &b, int i)
+{
+  return b.b[i];
+}
+
+class C
+{
+public:
+  C ();
+  ~C ();
+
+  A operator* ();
+
+  A *a_ptr;
+};
+
+C::C ()
+{
+  a_ptr = new A;
+  a_ptr->a = 5678;
+}
+
+C::~C ()
+{
+  delete a_ptr;
+}
+
+A
+C::operator* ()
+{
+  return *a_ptr;
+}
+
+#define TYPE_INDEX 1
+
+enum type
+{
+  INT,
+  CHAR
+};
+
+union U
+{
+public:
+  U (type t);
+  type get_type ();
+
+  int a;
+  char c;
+  type tp[2];
+};
+
+U::U (type t)
+{
+  tp[TYPE_INDEX] = t;
+}
+
+U
+make_int ()
+{
+  return U (INT);
+}
+
+U
+make_char ()
+{
+  return U (CHAR);
+}
+
+type
+U::get_type ()
+{
+  return tp[TYPE_INDEX];
+}
+
+int
+main ()
+{
+  int i = g(f(0));
+  A a = q(p() + r());
+
+  B b = makeb ();
+  C c;
+
+  return i + getb(b, 0);  /* Break here */
+}

Added: lldb/trunk/test/lang/cpp/nsimport/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/nsimport/Makefile?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/nsimport/Makefile (added)
+++ lldb/trunk/test/lang/cpp/nsimport/Makefile Tue Aug 18 17:43:37 2015
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py (added)
+++ lldb/trunk/test/lang/cpp/nsimport/TestCppNsImport.py Tue Aug 18 17:43:37 2015
@@ -0,0 +1,76 @@
+"""
+Tests imported namespaces in C++.
+"""
+import lldb
+from lldbtest import *
+import lldbutil
+
+class TestCppNsImport(TestBase):
+    
+    mydir = TestBase.compute_mydir(__file__)
+    
+    @skipUnlessDarwin
+    @dsym_test
+    def test_with_dsym_and_run_command(self):
+        """Tests imported namespaces in C++."""
+        self.buildDsym()
+        self.check()
+
+    @dwarf_test
+    def test_with_dwarf_and_run_command(self):
+        """Tests imported namespaces in C++."""
+        self.buildDwarf()
+        self.check()
+
+    def setUp(self):
+        TestBase.setUp(self)
+
+    def check(self):
+        """Tests imported namespaces in C++."""
+
+        # Get main source file
+        src_file = "main.cpp"
+        src_file_spec = lldb.SBFileSpec(src_file)
+        self.assertTrue(src_file_spec.IsValid(), "Main source file")
+        
+        # Get the path of the executable
+        cwd = os.getcwd() 
+        exe_file = "a.out"
+        exe_path  = os.path.join(cwd, exe_file)
+        
+        # Load the executable
+        target = self.dbg.CreateTarget(exe_path)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        # Break on main function
+        main_breakpoint = target.BreakpointCreateByName("main")
+        self.assertTrue(main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT)
+
+        # Launch the process
+        args = None
+        env = None
+        process = target.LaunchSimple(args, env, cwd)
+        self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
+
+        # Get the thread of the process
+        self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)
+        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+
+        # Get current fream of the thread at the breakpoint 
+        frame = thread.GetSelectedFrame()
+
+        # Test imported namespaces
+        test_result = frame.EvaluateExpression("x")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 11, "x = 11")
+        
+        test_result = frame.EvaluateExpression("xx")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 22, "xx = 22")
+
+        test_result = frame.EvaluateExpression("xxx")
+        self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 33, "xxx = 33")
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/lang/cpp/nsimport/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/nsimport/main.cpp?rev=245380&view=auto
==============================================================================
--- lldb/trunk/test/lang/cpp/nsimport/main.cpp (added)
+++ lldb/trunk/test/lang/cpp/nsimport/main.cpp Tue Aug 18 17:43:37 2015
@@ -0,0 +1,19 @@
+namespace A {
+    int x = 11;
+    namespace {
+        int xx = 22;
+    }
+}
+
+using namespace A;
+
+namespace {
+    int xxx = 33;
+};
+
+int main() {
+    x;
+    xx;
+    xxx;
+    return 0;
+}




More information about the lldb-commits mailing list