Move C++-related test directories to now reside under lang.

llvm-svn: 133878
diff --git a/lldb/test/lang/cpp/dynamic-value/Makefile b/lldb/test/lang/cpp/dynamic-value/Makefile
new file mode 100644
index 0000000..8770b23
--- /dev/null
+++ b/lldb/test/lang/cpp/dynamic-value/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := pass-to-base.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py b/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py
new file mode 100644
index 0000000..d44f52d
--- /dev/null
+++ b/lldb/test/lang/cpp/dynamic-value/TestDynamicValue.py
@@ -0,0 +1,224 @@
+"""
+Use lldb Python API to test dynamic values in C++
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class DynamicValueTestCase(TestBase):
+
+    mydir = os.path.join("lang", "cpp", "dynamic-value")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_get_dynamic_vals_with_dsym(self):
+        """Test fetching C++ dynamic values from pointers & references."""
+        self.buildDsym()
+        self.do_get_dynamic_vals()
+
+    @python_api_test
+    def test_get_dynamic_vals_with_dwarf(self):
+        """Test fetching C++ dynamic values from pointers & references."""
+        self.buildDwarf()
+        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.do_something_line = line_number('pass-to-base.cpp', '// Break here in doSomething.')
+        self.main_first_call_line = line_number('pass-to-base.cpp',
+                                                 '// Break here and get real addresses of myB and otherB.')
+        self.main_second_call_line = line_number('pass-to-base.cpp',
+                                                       '// Break here and get real address of reallyA.')
+
+    def examine_value_object_of_this_ptr (self, this_static, this_dynamic, dynamic_location):
+
+        # Get "this" as its static value
+        
+        self.assertTrue (this_static)
+        this_static_loc = int (this_static.GetValue(), 16)
+        
+        # Get "this" as its dynamic value
+        
+        self.assertTrue (this_dynamic)
+        this_dynamic_typename = this_dynamic.GetTypeName()
+        self.assertTrue (this_dynamic_typename.find('B') != -1)
+        this_dynamic_loc = int (this_dynamic.GetValue(), 16)
+        
+        # Make sure we got the right address for "this"
+        
+        self.assertTrue (this_dynamic_loc == dynamic_location)
+
+        # And that the static address is greater than the dynamic one
+
+        self.assertTrue (this_static_loc > this_dynamic_loc)
+        
+        # Now read m_b_value which is only in the dynamic value:
+
+        use_dynamic = lldb.eDynamicCanRunTarget
+        no_dynamic  = lldb.eNoDynamicValues
+
+        this_dynamic_m_b_value = this_dynamic.GetChildMemberWithName('m_b_value', use_dynamic)
+        self.assertTrue (this_dynamic_m_b_value)
+        
+        m_b_value = int (this_dynamic_m_b_value.GetValue(), 0)
+        self.assertTrue (m_b_value == 10)
+        
+        # Make sure it is not in the static version
+
+        this_static_m_b_value = this_static.GetChildMemberWithName('m_b_value', no_dynamic)
+        self.assertFalse (this_static_m_b_value)
+
+        # Okay, now let's make sure that we can get the dynamic type of a child element:
+
+        contained_auto_ptr = this_dynamic.GetChildMemberWithName ('m_client_A', use_dynamic)
+        self.assertTrue (contained_auto_ptr)
+        contained_b = contained_auto_ptr.GetChildMemberWithName ('_M_ptr', use_dynamic)
+        self.assertTrue (contained_b)
+        
+        contained_b_static = contained_auto_ptr.GetChildMemberWithName ('_M_ptr', no_dynamic)
+        self.assertTrue (contained_b_static)
+        
+        contained_b_addr = int (contained_b.GetValue(), 16)
+        contained_b_static_addr = int (contained_b_static.GetValue(), 16)
+        
+        self.assertTrue (contained_b_addr < contained_b_static_addr)
+        
+    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:
+
+        do_something_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.do_something_line)
+        self.assertTrue(do_something_bpt,
+                        VALID_BREAKPOINT)
+
+        first_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_first_call_line)
+        self.assertTrue(first_call_bpt,
+                        VALID_BREAKPOINT)
+
+        second_call_bpt = target.BreakpointCreateByLocation('pass-to-base.cpp', self.main_second_call_line)
+        self.assertTrue(second_call_bpt,
+                        VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at the entry point.
+        process = target.LaunchSimple (None, None, os.getcwd())
+
+        self.assertTrue(process.GetState() == lldb.eStateStopped,
+                        PROCESS_STOPPED)
+
+        threads = lldbutil.get_threads_stopped_at_breakpoint (process, first_call_bpt)
+        self.assertTrue (len(threads) == 1)
+        thread = threads[0]
+
+        frame = thread.GetFrameAtIndex(0)
+
+        # Now find the dynamic addresses of myB and otherB so we can compare them
+        # with the dynamic values we get in doSomething:
+
+        use_dynamic = lldb.eDynamicCanRunTarget
+        no_dynamic  = lldb.eNoDynamicValues
+
+        myB = frame.FindVariable ('myB', no_dynamic);
+        self.assertTrue (myB)
+        myB_loc = int (myB.GetLocation(), 16)
+
+        otherB = frame.FindVariable('otherB', no_dynamic)
+        self.assertTrue (otherB)
+        otherB_loc = int (otherB.GetLocation(), 16)
+
+        # Okay now run to doSomething:
+
+        threads = lldbutil.continue_to_breakpoint (process, do_something_bpt)
+        self.assertTrue (len(threads) == 1)
+        thread = threads[0]
+
+        frame = thread.GetFrameAtIndex(0)
+
+        # Get "this" using FindVariable:
+
+        this_static = frame.FindVariable ('this', no_dynamic)
+        this_dynamic = frame.FindVariable ('this', use_dynamic)
+        self.examine_value_object_of_this_ptr (this_static, this_dynamic, myB_loc)
+        
+        # Get "this" using FindValue, make sure that works too:
+        this_static = frame.FindValue ('this', lldb.eValueTypeVariableArgument, no_dynamic)
+        this_dynamic = frame.FindValue ('this', lldb.eValueTypeVariableArgument, use_dynamic)
+        self.examine_value_object_of_this_ptr (this_static, this_dynamic, myB_loc)
+
+        # Get "this" using the EvaluateExpression:
+        # These tests fail for now because EvaluateExpression doesn't currently support dynamic typing...
+        #this_static = frame.EvaluateExpression ('this', False)
+        #this_dynamic = frame.EvaluateExpression ('this', True)
+        #self.examine_value_object_of_this_ptr (this_static, this_dynamic, myB_loc)
+        
+        # The "frame var" code uses another path to get into children, so let's
+        # make sure that works as well:
+
+        self.expect('frame var -d run-target anotherA.m_client_A._M_ptr', 'frame var finds its way into a child member',
+            patterns = ['\(.* B \*\)'])
+
+        # Now make sure we also get it right for a reference as well:
+
+        anotherA_static = frame.FindVariable ('anotherA', False)
+        self.assertTrue (anotherA_static)
+        anotherA_static_addr = int (anotherA_static.GetValue(), 16)
+
+        anotherA_dynamic = frame.FindVariable ('anotherA', True)
+        self.assertTrue (anotherA_dynamic)
+        anotherA_dynamic_addr = int (anotherA_dynamic.GetValue(), 16)
+        anotherA_dynamic_typename = anotherA_dynamic.GetTypeName()
+        self.assertTrue (anotherA_dynamic_typename.find('B') != -1)
+
+        self.assertTrue(anotherA_dynamic_addr < anotherA_static_addr)
+
+        anotherA_m_b_value_dynamic = anotherA_dynamic.GetChildMemberWithName('m_b_value', True)
+        self.assertTrue (anotherA_m_b_value_dynamic)
+        anotherA_m_b_val = int (anotherA_m_b_value_dynamic.GetValue(), 10)
+        self.assertTrue (anotherA_m_b_val == 300)
+
+        anotherA_m_b_value_static = anotherA_static.GetChildMemberWithName('m_b_value', True)
+        self.assertFalse (anotherA_m_b_value_static)
+
+        # Okay, now continue again, and when we hit the second breakpoint in main
+
+        threads = lldbutil.continue_to_breakpoint (process, second_call_bpt)
+        self.assertTrue (len(threads) == 1)
+        thread = threads[0]
+
+        frame = thread.GetFrameAtIndex(0)
+        reallyA_value = frame.FindVariable ('reallyA', False)
+        self.assertTrue(reallyA_value)
+        reallyA_loc = int (reallyA_value.GetLocation(), 16)
+        
+        # Finally continue to doSomething again, and make sure we get the right value for anotherA,
+        # which this time around is just an "A".
+
+        threads = lldbutil.continue_to_breakpoint (process, do_something_bpt)
+        self.assertTrue(len(threads) == 1)
+        thread = threads[0]
+
+        frame = thread.GetFrameAtIndex(0)
+        anotherA_value = frame.FindVariable ('anotherA', True)
+        self.assertTrue(anotherA_value)
+        anotherA_loc = int (anotherA_value.GetValue(), 16)
+        self.assertTrue (anotherA_loc == reallyA_loc)
+        self.assertTrue (anotherA_value.GetTypeName().find ('B') == -1)
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()
diff --git a/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp b/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp
new file mode 100644
index 0000000..a817bad
--- /dev/null
+++ b/lldb/test/lang/cpp/dynamic-value/pass-to-base.cpp
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <memory>
+
+class Extra
+{
+public:
+  Extra (int in_one, int in_two) : m_extra_one(in_one), m_extra_two(in_two) {}
+
+private:
+  int m_extra_one;
+  int m_extra_two;
+};
+
+class A
+{
+public:
+  A(int value) : m_a_value (value) {}
+  A(int value, A* client_A) : m_a_value (value), m_client_A (client_A) {}
+
+  virtual ~A() {}
+
+  virtual void
+  doSomething (A &anotherA)
+  {
+    printf ("In A %p doing something with %d.\n", this, m_a_value);
+    printf ("Also have another A at %p: %d.\n", &anotherA, anotherA.Value()); // Break here in doSomething.
+  }
+
+  int 
+  Value()
+  {
+    return m_a_value;
+  }
+
+private:
+  int m_a_value;
+  std::auto_ptr<A> m_client_A;
+};
+
+class B : public Extra, public virtual A
+{
+public:
+  B (int b_value, int a_value) : Extra(b_value, a_value), A(a_value), m_b_value(b_value) {}
+  B (int b_value, int a_value, A *client_A) : Extra(b_value, a_value), A(a_value, client_A), m_b_value(b_value) {}
+
+  virtual ~B () {}
+
+private:
+  int m_b_value;
+};
+
+static A* my_global_A_ptr;
+
+int
+main (int argc, char **argv)
+{
+  my_global_A_ptr = new B (100, 200);
+  B myB (10, 20, my_global_A_ptr);
+  B *second_fake_A_ptr = new B (150, 250);
+  B otherB (300, 400, second_fake_A_ptr);
+
+  myB.doSomething(otherB); // Break here and get real addresses of myB and otherB.
+
+  A reallyA (500);
+  myB.doSomething (reallyA);  // Break here and get real address of reallyA.
+
+  return 0;
+}
diff --git a/lldb/test/lang/cpp/virtual/Makefile b/lldb/test/lang/cpp/virtual/Makefile
new file mode 100644
index 0000000..314f1cb
--- /dev/null
+++ b/lldb/test/lang/cpp/virtual/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/lang/cpp/virtual/TestVirtual.py b/lldb/test/lang/cpp/virtual/TestVirtual.py
new file mode 100644
index 0000000..9ba7fd6
--- /dev/null
+++ b/lldb/test/lang/cpp/virtual/TestVirtual.py
@@ -0,0 +1,86 @@
+"""
+Test C++ virtual function and virtual inheritance.
+"""
+
+import os, time
+import re
+import lldb
+from lldbtest import *
+
+def Msg(expr, val):
+    return "'expression %s' matches the output (from compiled code): %s" % (expr, val)
+
+class CppVirtualMadness(TestBase):
+
+    mydir = os.path.join("lang", "cpp", "virtual")
+
+    # This is the pattern by design to match the "my_expr = 'value'" output from
+    # printf() stmts (see main.cpp).
+    pattern = re.compile("^([^=]*) = '([^=]*)'$")
+
+    # Assert message.
+    PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly"
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_virtual_madness_dsym(self):
+        """Test that expression works correctly with virtual inheritance as well as virtual function."""
+        self.buildDsym()
+        self.virtual_madness_test()
+
+    def test_virtual_madness_dwarf(self):
+        """Test that expression works correctly with virtual inheritance as well as virtual function."""
+        self.buildDwarf()
+        self.virtual_madness_test()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break for main.cpp.
+        self.line = line_number('main.cpp', '// Set first breakpoint here.')
+
+    def virtual_madness_test(self):
+        """Test that variable expressions with basic types are evaluated correctly."""
+
+        # First, capture the golden output emitted by the oracle, i.e., the
+        # series of printf statements.
+        go = system("./a.out", sender=self)[0]
+        # This golden list contains a list of "my_expr = 'value' pairs extracted
+        # from the golden output.
+        gl = []
+
+        # Scan the golden output line by line, looking for the pattern:
+        #
+        #     my_expr = 'value'
+        #
+        for line in go.split(os.linesep):
+            match = self.pattern.search(line)
+            if match:
+                my_expr, val = match.group(1), match.group(2)
+                gl.append((my_expr, val))
+        #print "golden list:", gl
+
+        # Bring the program to the point where we can issue a series of
+        # 'expression' command to compare against the golden output.
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+        self.runCmd("breakpoint set -f main.cpp -l %d" % self.line)
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # Now iterate through the golden list, comparing against the output from
+        # 'expression var'.
+        for my_expr, val in gl:
+            # Don't overwhelm the expression mechanism.
+            # This slows down the test suite quite a bit, to enable it, define
+            # the environment variable LLDB_TYPES_EXPR_TIME_WAIT.  For example:
+            #
+            #     export LLDB_TYPES_EXPR_TIME_WAIT=0.5
+            #
+            # causes a 0.5 second delay between 'expression' commands.
+            if "LLDB_TYPES_EXPR_TIME_WAIT" in os.environ:
+                time.sleep(float(os.environ["LLDB_TYPES_EXPR_TIME_WAIT"]))
+
+            self.runCmd("expression %s" % my_expr)
+            output = self.res.GetOutput()
+            
+            # The expression output must match the oracle.
+            self.expect(output, Msg(my_expr, val), exe=False,
+                substrs = [val])
diff --git a/lldb/test/lang/cpp/virtual/main.cpp b/lldb/test/lang/cpp/virtual/main.cpp
new file mode 100644
index 0000000..0c3d292
--- /dev/null
+++ b/lldb/test/lang/cpp/virtual/main.cpp
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <stdint.h>
+
+class A
+{
+public:
+    A () : m_pad ('c') {}
+
+    virtual ~A () {}
+    
+    virtual const char * a()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+
+    virtual const char * b()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+
+    virtual const char * c()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+protected:
+    char m_pad;
+};
+
+class AA
+{
+public:
+    AA () : m_pad('A') {}
+    virtual ~AA () {}
+
+    virtual const char * aa()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+  
+protected:
+    char m_pad;
+};
+
+class B : virtual public A, public AA
+{
+public:
+    B () : m_pad ('c')  {}
+
+    virtual ~B () {}
+    
+    virtual const char * a()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+
+    virtual const char * b()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+protected:
+    char m_pad;
+};
+
+class C : public B, virtual public A
+{
+public:
+    C () : m_pad ('c') {}
+
+    virtual ~C () {}
+    
+    virtual const char * a()
+    {
+        return __PRETTY_FUNCTION__;
+    }
+protected:
+    char m_pad;
+};
+
+int main (int argc, char const *argv[], char const *envp[])
+{
+    A *a_as_A = new A();
+    B *b_as_B = new B();
+    A *b_as_A = b_as_B;
+    C *c_as_C = new C();
+    A *c_as_A = c_as_C;
+
+    // Set first breakpoint here.
+    // then evaluate:
+    // expression a_as_A->a()
+    // expression a_as_A->b()
+    // expression a_as_A->c()
+    // expression b_as_A->a()
+    // expression b_as_A->b()
+    // expression b_as_A->c()
+    // expression b_as_B->aa()
+    // expression c_as_A->a()
+    // expression c_as_A->b()
+    // expression c_as_A->c()
+    // expression c_as_C->aa()
+    printf ("a_as_A->a() = '%s'\n", a_as_A->a());
+    printf ("a_as_A->b() = '%s'\n", a_as_A->b());
+    printf ("a_as_A->c() = '%s'\n", a_as_A->c());
+    printf ("b_as_A->a() = '%s'\n", b_as_A->a());
+    printf ("b_as_A->b() = '%s'\n", b_as_A->b());
+    printf ("b_as_A->c() = '%s'\n", b_as_A->c());
+    printf ("b_as_B->aa() = '%s'\n", b_as_B->aa());
+    printf ("c_as_A->a() = '%s'\n", c_as_A->a());
+    printf ("c_as_A->b() = '%s'\n", c_as_A->b());
+    printf ("c_as_A->c() = '%s'\n", c_as_A->c());
+    printf ("c_as_C->aa() = '%s'\n", c_as_C->aa());
+    return 0;
+}