diff options
| author | Greg Clayton <gclayton@apple.com> | 2014-07-19 00:12:57 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2014-07-19 00:12:57 +0000 |
| commit | 759e7441af95cbd11c65a5f21de00a99cd2a2bed (patch) | |
| tree | a5475944cafb901cf1d46ad513420be45d9505ec /lldb/test/lang/cpp | |
| parent | cfd17dd2be3dbb7f7fba9585d5c814c6f75add07 (diff) | |
| download | bcm5719-llvm-759e7441af95cbd11c65a5f21de00a99cd2a2bed.tar.gz bcm5719-llvm-759e7441af95cbd11c65a5f21de00a99cd2a2bed.zip | |
LLDB now correctly handles virtual inheritance.
Test case added as well.
<rdar://problem/16785904>
llvm-svn: 213433
Diffstat (limited to 'lldb/test/lang/cpp')
| -rw-r--r-- | lldb/test/lang/cpp/diamond/Makefile | 5 | ||||
| -rw-r--r-- | lldb/test/lang/cpp/diamond/TestDiamond.py | 63 | ||||
| -rw-r--r-- | lldb/test/lang/cpp/diamond/main.cpp | 85 |
3 files changed, 153 insertions, 0 deletions
diff --git a/lldb/test/lang/cpp/diamond/Makefile b/lldb/test/lang/cpp/diamond/Makefile new file mode 100644 index 00000000000..314f1cb2f07 --- /dev/null +++ b/lldb/test/lang/cpp/diamond/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/lang/cpp/diamond/TestDiamond.py b/lldb/test/lang/cpp/diamond/TestDiamond.py new file mode 100644 index 00000000000..247da482a19 --- /dev/null +++ b/lldb/test/lang/cpp/diamond/TestDiamond.py @@ -0,0 +1,63 @@ +""" +Tests that bool types work +""" +import lldb +from lldbtest import * +import lldbutil + +class CPPTestDiamondInheritance(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @dsym_test + def test_with_dsym_and_run_command(self): + """Test that virtual base classes work in when SBValue objects are used to explore the variable value""" + self.buildDsym() + self.diamong_inheritace() + + @dwarf_test + def test_with_dwarf_and_run_command(self): + """Test that virtual base classes work in when SBValue objects are used to explore the variable value""" + self.buildDwarf() + self.diamong_inheritace() + + def setUp(self): + TestBase.setUp(self) + + def set_breakpoint(self, line): + # Some compilers (for example GCC 4.4.7 and 4.6.1) emit multiple locations for the statement with the ternary + # operator in the test program, while others emit only 1. + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=-1, loc_exact=False) + + def diamong_inheritace(self): + """Test that virtual base classes work in when SBValue objects are used to explore the variable value""" + + exe = os.path.join(os.getcwd(), "a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + self.set_breakpoint(line_number('main.cpp', '// breakpoint 1')) + self.set_breakpoint(line_number('main.cpp', '// breakpoint 2')) + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + thread = process.GetThreadAtIndex(0) + frame = thread.GetFrameAtIndex(0) + j1 = frame.FindVariable("j1") + j1_Derived1 = j1.GetChildAtIndex(0) + j1_Derived2 = j1.GetChildAtIndex(1) + j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0) + j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0) + j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0) + j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0) + self.assertTrue(j1_Derived1_VBase.GetLoadAddress() == j1_Derived2_VBase.GetLoadAddress(), "ensure virtual base class is the same between Derived1 and Derived2") + self.assertTrue(j1_Derived1_VBase_m_value.GetValueAsUnsigned(1) == j1_Derived2_VBase_m_value.GetValueAsUnsigned(2), "ensure m_value in VBase is the same") + self.assertTrue(frame.FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned(0) == 12345, "ensure Derived2 from j1 is correct"); + thread.StepOver() + self.assertTrue(frame.FindVariable("d").GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned(0) == 12346, "ensure Derived2 from j2 is correct"); + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/lang/cpp/diamond/main.cpp b/lldb/test/lang/cpp/diamond/main.cpp new file mode 100644 index 00000000000..bfe098a089f --- /dev/null +++ b/lldb/test/lang/cpp/diamond/main.cpp @@ -0,0 +1,85 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include <stdio.h> + +static int g_next_value = 12345; + +class VBase +{ +public: + VBase() : m_value(g_next_value++) {} + virtual ~VBase() {} + void Print() + { + printf("%p: %s\n%p: m_value = 0x%8.8x\n", this, __PRETTY_FUNCTION__, &m_value, m_value); + } + int m_value; +}; + +class Derived1 : public virtual VBase +{ +public: + Derived1() {}; + void Print () + { + printf("%p: %s\n", this, __PRETTY_FUNCTION__); + VBase::Print(); + } + +}; + +class Derived2 : public virtual VBase +{ +public: + Derived2() {}; + + void Print () + { + printf("%p: %s\n", this, __PRETTY_FUNCTION__); + VBase::Print(); + } +}; + +class Joiner1 : public Derived1, public Derived2 +{ +public: + Joiner1() : + m_joiner1(3456), + m_joiner2(6789) {} + void Print () + { + printf("%p: %s \n%p: m_joiner1 = 0x%8.8x\n%p: m_joiner2 = 0x%8.8x\n", + this, + __PRETTY_FUNCTION__, + &m_joiner1, + m_joiner1, + &m_joiner2, + m_joiner2); + Derived1::Print(); + Derived2::Print(); + } + int m_joiner1; + int m_joiner2; +}; + +class Joiner2 : public Derived2 +{ + int m_stuff[32]; +}; + +int main(int argc, const char * argv[]) +{ + Joiner1 j1; + Joiner2 j2; + j1.Print(); + j2.Print(); + Derived2 *d = &j1; + d = &j2; // breakpoint 1 + return 0; // breakpoint 2 +} |

