diff options
| author | Enrico Granata <egranata@apple.com> | 2014-09-12 18:45:43 +0000 |
|---|---|---|
| committer | Enrico Granata <egranata@apple.com> | 2014-09-12 18:45:43 +0000 |
| commit | 190064ad0d122e68caca080014b2640ee883f3b6 (patch) | |
| tree | 7529505668d216501ef37c36ee834b31031a588d /lldb/test/python_api/class_members | |
| parent | ab4fe98b4a0a8290efa07bd44d207750016c3c47 (diff) | |
| download | bcm5719-llvm-190064ad0d122e68caca080014b2640ee883f3b6.tar.gz bcm5719-llvm-190064ad0d122e68caca080014b2640ee883f3b6.zip | |
Add logic to LLDB to figure out the types of member functions of C++ classes. Add plumbing for that all the way up to the SB layer
llvm-svn: 217701
Diffstat (limited to 'lldb/test/python_api/class_members')
| -rw-r--r-- | lldb/test/python_api/class_members/Makefile | 5 | ||||
| -rw-r--r-- | lldb/test/python_api/class_members/TestSBTypeClassMembers.py | 81 | ||||
| -rw-r--r-- | lldb/test/python_api/class_members/main.cpp | 28 |
3 files changed, 114 insertions, 0 deletions
diff --git a/lldb/test/python_api/class_members/Makefile b/lldb/test/python_api/class_members/Makefile new file mode 100644 index 00000000000..8a7102e347a --- /dev/null +++ b/lldb/test/python_api/class_members/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/python_api/class_members/TestSBTypeClassMembers.py b/lldb/test/python_api/class_members/TestSBTypeClassMembers.py new file mode 100644 index 00000000000..e286df9d57a --- /dev/null +++ b/lldb/test/python_api/class_members/TestSBTypeClassMembers.py @@ -0,0 +1,81 @@ +""" +Test SBType and SBTypeList API. +""" + +import os, time +import re +import unittest2 +import lldb, lldbutil +from lldbtest import * + +class TypeAndTypeListTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + @dsym_test + def test_with_dsym(self): + """Exercise SBType and SBTypeList API.""" + d = {'EXE': self.exe_name} + self.buildDsym(dictionary=d) + self.setTearDownCleanup(dictionary=d) + self.type_api(self.exe_name) + + @python_api_test + @dwarf_test + def test_with_dwarf(self): + """Exercise SBType and SBTypeList API.""" + d = {'EXE': self.exe_name} + self.buildDwarf(dictionary=d) + self.setTearDownCleanup(dictionary=d) + self.type_api(self.exe_name) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # We'll use the test method name as the exe_name. + self.exe_name = self.testMethodName + # Find the line number to break at. + self.source = 'main.cpp' + self.line = line_number(self.source, '// set breakpoint here') + + def type_api(self, exe_name): + """Exercise SBType and SBTypeList API.""" + exe = os.path.join(os.getcwd(), exe_name) + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Create the breakpoint inside function 'main'. + breakpoint = target.BreakpointCreateByLocation(self.source, self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # Get Frame #0. + self.assertTrue(process.GetState() == lldb.eStateStopped) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") + frame0 = thread.GetFrameAtIndex(0) + + variable = frame0.FindVariable("d") + Derived = variable.GetType() + Base = Derived.GetDirectBaseClassAtIndex(0).GetType() + + self.assertTrue(Derived.GetNumberOfMemberFunctions() == 2, "Derived declares two methods") + self.assertTrue(Derived.GetMemberFunctionAtIndex(0).GetFunctionReturnType().GetName() == "int", "Derived::dImpl returns int") + + self.assertTrue(Base.GetNumberOfMemberFunctions() == 4, "Base declares three methods") + self.assertTrue(Base.GetMemberFunctionAtIndex(3).GetFunctionArgumentTypes().GetSize() == 3, "Base::sfunc takes three arguments") + self.assertTrue(Base.GetMemberFunctionAtIndex(2).GetFunctionArgumentTypes().GetSize() == 0, "Base::dat takes no arguments") + self.assertTrue(Base.GetMemberFunctionAtIndex(1).GetFunctionArgumentTypes().GetTypeAtIndex(1).GetName() == "char", "Base::bar takes a second 'char' argument") + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/python_api/class_members/main.cpp b/lldb/test/python_api/class_members/main.cpp new file mode 100644 index 00000000000..86392a219cc --- /dev/null +++ b/lldb/test/python_api/class_members/main.cpp @@ -0,0 +1,28 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +class Base { +public: + int foo(int x, int y) { return 1; } + char bar(int x, char y) { return 2; } + void dat() {} + static int sfunc(char, int, float) { return 3; } +}; + +class Derived: public Base { +protected: + int dImpl() { return 1; } +public: + float baz(float b) { return b + 1.0; } +}; + +int main() { + Derived d; + return 0; // set breakpoint here +} |

