diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
commit | 74a628f776edb588bff8f8f5cc16eac947c9d631 (patch) | |
tree | dc32e010ac4902621e5a279bfeb48628f7f0e166 /packages/Python/lldbsuite/test/python_api | |
parent | afed7be32164a598f8172282c249af7266c48b46 (diff) |
Notes
Diffstat (limited to 'packages/Python/lldbsuite/test/python_api')
7 files changed, 181 insertions, 9 deletions
diff --git a/packages/Python/lldbsuite/test/python_api/breakpoint/TestBreakpointAPI.py b/packages/Python/lldbsuite/test/python_api/breakpoint/TestBreakpointAPI.py index 39975632dcb61..4bd4781c7ef51 100644 --- a/packages/Python/lldbsuite/test/python_api/breakpoint/TestBreakpointAPI.py +++ b/packages/Python/lldbsuite/test/python_api/breakpoint/TestBreakpointAPI.py @@ -17,6 +17,7 @@ from lldbsuite.test import lldbutil class BreakpointAPITestCase(TestBase): mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True @add_test_categories(['pyapi']) def test_breakpoint_is_valid(self): @@ -49,3 +50,28 @@ class BreakpointAPITestCase(TestBase): self.assertTrue( not breakpoint, "Breakpoint we deleted is no longer valid.") + + @add_test_categories(['pyapi']) + def test_target_delete(self): + """Make sure that if an SBTarget gets deleted the associated + Breakpoint's IsValid returns false.""" + + self.build() + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Now create a breakpoint on main.c by name 'AFunction'. + breakpoint = target.BreakpointCreateByName('AFunction', 'a.out') + #print("breakpoint:", breakpoint) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() == 1, + VALID_BREAKPOINT) + location = breakpoint.GetLocationAtIndex(0) + self.assertTrue(location.IsValid()) + + self.assertTrue(self.dbg.DeleteTarget(target)) + self.assertFalse(breakpoint.IsValid()) + self.assertFalse(location.IsValid()) diff --git a/packages/Python/lldbsuite/test/python_api/name_lookup/Makefile b/packages/Python/lldbsuite/test/python_api/name_lookup/Makefile new file mode 100644 index 0000000000000..8a7102e347af2 --- /dev/null +++ b/packages/Python/lldbsuite/test/python_api/name_lookup/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/python_api/name_lookup/TestNameLookup.py b/packages/Python/lldbsuite/test/python_api/name_lookup/TestNameLookup.py new file mode 100644 index 0000000000000..b7a683f25f623 --- /dev/null +++ b/packages/Python/lldbsuite/test/python_api/name_lookup/TestNameLookup.py @@ -0,0 +1,66 @@ +""" +Test SBTarget APIs. +""" + +from __future__ import print_function + + +import unittest2 +import os +import time +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestNameLookup(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + def test_target(self): + """Exercise SBTarget.FindFunctions() with various name masks. + + A previous regression caused mangled names to not be able to be looked up. + This test verifies that using a mangled name with eFunctionNameTypeFull works + and that using a function basename with eFunctionNameTypeFull works for all + C++ functions that are at the global namespace level.""" + self.build(); + exe = os.path.join(os.getcwd(), 'a.out') + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + exe_module = target.FindModule(target.GetExecutable()) + + c_name_to_symbol = {} + cpp_name_to_symbol = {} + mangled_to_symbol = {} + num_symbols = exe_module.GetNumSymbols(); + for i in range(num_symbols): + symbol = exe_module.GetSymbolAtIndex(i); + name = symbol.GetName() + if name and 'unique_function_name' in name and '__PRETTY_FUNCTION__' not in name: + mangled = symbol.GetMangledName() + if mangled: + mangled_to_symbol[mangled] = symbol + if name: + cpp_name_to_symbol[name] = symbol + elif name: + c_name_to_symbol[name] = symbol + + # Make sure each mangled name turns up exactly one match when looking up + # functions by full name and using the mangled name as the name in the + # lookup + self.assertGreaterEqual(len(mangled_to_symbol), 6) + for mangled in mangled_to_symbol.keys(): + symbol_contexts = target.FindFunctions(mangled, lldb.eFunctionNameTypeFull) + self.assertTrue(symbol_contexts.GetSize() == 1) + for symbol_context in symbol_contexts: + self.assertTrue(symbol_context.GetFunction().IsValid()) + self.assertTrue(symbol_context.GetSymbol().IsValid()) + + diff --git a/packages/Python/lldbsuite/test/python_api/name_lookup/main.cpp b/packages/Python/lldbsuite/test/python_api/name_lookup/main.cpp new file mode 100644 index 0000000000000..79aa2d0452f48 --- /dev/null +++ b/packages/Python/lldbsuite/test/python_api/name_lookup/main.cpp @@ -0,0 +1,54 @@ +#include <stdio.h> + +extern "C" int unique_function_name(int i) +{ + return puts(__PRETTY_FUNCTION__); +} + +int unique_function_name() +{ + return puts(__PRETTY_FUNCTION__); +} + +int unique_function_name(float f) +{ + return puts(__PRETTY_FUNCTION__); +} + +namespace e +{ + int unique_function_name() + { + return puts(__PRETTY_FUNCTION__); + } + + namespace g + { + int unique_function_name() + { + return puts(__PRETTY_FUNCTION__); + } + } +} + +class g +{ +public: + int unique_function_name() + { + return puts(__PRETTY_FUNCTION__); + } + + int unique_function_name(int i) + { + return puts(__PRETTY_FUNCTION__); + } +}; + +int main (int argc, char const *argv[]) +{ + g g; + g.unique_function_name(); + g.unique_function_name(argc); + return 0; +}
\ No newline at end of file diff --git a/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py b/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py index e853d6567e73c..0560ac502dcf7 100644 --- a/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py +++ b/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py @@ -22,6 +22,26 @@ class SBDataAPICase(TestBase): self.line = line_number('main.cpp', '// set breakpoint here') @add_test_categories(['pyapi']) + def test_byte_order_and_address_byte_size(self): + """Test the SBData::SetData() to ensure the byte order and address + byte size are obeyed""" + addr_data = '\x11\x22\x33\x44\x55\x66\x77\x88' + error = lldb.SBError() + data = lldb.SBData() + data.SetData(error, addr_data, lldb.eByteOrderBig, 4) + addr = data.GetAddress(error, 0) + self.assertTrue(addr == 0x11223344); + data.SetData(error, addr_data, lldb.eByteOrderBig, 8) + addr = data.GetAddress(error, 0) + self.assertTrue(addr == 0x1122334455667788); + data.SetData(error, addr_data, lldb.eByteOrderLittle, 4) + addr = data.GetAddress(error, 0) + self.assertTrue(addr == 0x44332211); + data.SetData(error, addr_data, lldb.eByteOrderLittle, 8) + addr = data.GetAddress(error, 0) + self.assertTrue(addr == 0x8877665544332211); + + @add_test_categories(['pyapi']) def test_with_run_command(self): """Test the SBData APIs.""" self.build() diff --git a/packages/Python/lldbsuite/test/python_api/watchpoint/TestSetWatchpoint.py b/packages/Python/lldbsuite/test/python_api/watchpoint/TestSetWatchpoint.py index e4f2c5c7a1828..bc925ee693d49 100644 --- a/packages/Python/lldbsuite/test/python_api/watchpoint/TestSetWatchpoint.py +++ b/packages/Python/lldbsuite/test/python_api/watchpoint/TestSetWatchpoint.py @@ -108,3 +108,6 @@ class SetWatchpointAPITestCase(TestBase): self.assertTrue( process.GetState() == lldb.eStateExited, PROCESS_EXITED) + + self.dbg.DeleteTarget(target) + self.assertFalse(watchpoint.IsValid()) diff --git a/packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py b/packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py index 1bef9968b4abd..2685ef819cad0 100644 --- a/packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py +++ b/packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py @@ -56,7 +56,7 @@ class WatchpointIgnoreCountTestCase(TestBase): # We should be stopped due to the breakpoint. Get frame #0. process = target.GetProcess() - self.assertTrue(process.GetState() == lldb.eStateStopped, + self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) thread = lldbutil.get_stopped_thread( process, lldb.eStopReasonBreakpoint) @@ -75,12 +75,12 @@ class WatchpointIgnoreCountTestCase(TestBase): self.HideStdout() # There should be only 1 watchpoint location under the target. - self.assertTrue(target.GetNumWatchpoints() == 1) + self.assertEqual(target.GetNumWatchpoints(), 1) watchpoint = target.GetWatchpointAtIndex(0) self.assertTrue(watchpoint.IsEnabled()) - self.assertTrue(watchpoint.GetIgnoreCount() == 0) + self.assertEqual(watchpoint.GetIgnoreCount(), 0) watch_id = watchpoint.GetID() - self.assertTrue(watch_id != 0) + self.assertNotEqual(watch_id, 0) print(watchpoint) # Now immediately set the ignore count to 2. When we continue, expect the @@ -90,12 +90,10 @@ class WatchpointIgnoreCountTestCase(TestBase): process.Continue() # At this point, the inferior process should have exited. - self.assertTrue( - process.GetState() == lldb.eStateExited, - PROCESS_EXITED) + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) # Verify some vital statistics. self.assertTrue(watchpoint) - self.assertTrue(watchpoint.GetWatchSize() == 4) - self.assertTrue(watchpoint.GetHitCount() == 2) + self.assertEqual(watchpoint.GetWatchSize(), 4) + self.assertEqual(watchpoint.GetHitCount(), 2) print(watchpoint) |