diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context')
8 files changed, 281 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/Makefile new file mode 100644 index 00000000000..10495940055 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py new file mode 100644 index 00000000000..0c1ad83c84d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py @@ -0,0 +1,107 @@ +""" +Test SBSymbolContext APIs. +""" + +from __future__ import print_function + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SymbolContextAPITestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to of function 'c'. + self.line = line_number( + 'main.c', '// Find the line number of function "c" here.') + + @add_test_categories(['pyapi']) + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") + def test(self): + """Exercise SBSymbolContext API extensively.""" + self.build() + exe = self.getBuildArtifact("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 'c'. + breakpoint = target.BreakpointCreateByName('c', 'a.out') + #print("breakpoint:", breakpoint) + self.assertTrue(breakpoint and + breakpoint.GetNumLocations() == 1, + 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) + + # Frame #0 should be on self.line. + from lldbsuite.test.lldbutil import get_stopped_thread + thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint") + frame0 = thread.GetFrameAtIndex(0) + self.assertTrue(frame0.GetLineEntry().GetLine() == self.line) + + # Now get the SBSymbolContext from this frame. We want everything. :-) + context = frame0.GetSymbolContext(lldb.eSymbolContextEverything) + self.assertTrue(context) + + # Get the description of this module. + module = context.GetModule() + desc = lldbutil.get_description(module) + self.expect(desc, "The module should match", exe=False, + substrs=[self.getBuildArtifact("a.out")]) + + compileUnit = context.GetCompileUnit() + self.expect( + str(compileUnit), + "The compile unit should match", + exe=False, + substrs=[self.getSourcePath('main.c')]) + + function = context.GetFunction() + self.assertTrue(function) + #print("function:", function) + + block = context.GetBlock() + self.assertTrue(block) + #print("block:", block) + + lineEntry = context.GetLineEntry() + #print("line entry:", lineEntry) + self.expect( + lineEntry.GetFileSpec().GetDirectory(), + "The line entry should have the correct directory", + exe=False, + substrs=[self.mydir]) + self.expect( + lineEntry.GetFileSpec().GetFilename(), + "The line entry should have the correct filename", + exe=False, + substrs=['main.c']) + self.assertTrue(lineEntry.GetLine() == self.line, + "The line entry's line number should match ") + + symbol = context.GetSymbol() + self.assertTrue( + function.GetName() == symbol.GetName() and symbol.GetName() == 'c', + "The symbol name should be 'c'") + + sc_list = lldb.SBSymbolContextList() + sc_list.Append(context) + self.assertEqual(len(sc_list), 1) + for sc in sc_list: + self.assertEqual(lineEntry, sc.GetLineEntry()) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/main.c new file mode 100644 index 00000000000..4e68fb764b8 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/main.c @@ -0,0 +1,50 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include <stdio.h> + +// This simple program is to test the lldb Python API SBSymbolContext. +// When stopped on a frame, we can get the symbol context using the SBFrame API +// SBFrame.GetSymbolContext(). + +int a(int); +int b(int); +int c(int); + +int a(int val) +{ + if (val <= 1) + return b(val); + else if (val >= 3) + return c(val); + + return val; +} + +int b(int val) +{ + return c(val); +} + +int c(int val) +{ + return val + 3; // Find the line number of function "c" here. +} + +int main (int argc, char const *argv[]) +{ + int A1 = a(1); // a(1) -> b(1) -> c(1) + printf("a(1) returns %d\n", A1); + + int B2 = b(2); // b(2) -> c(2) + printf("b(2) returns %d\n", B2); + + int A3 = a(3); // a(3) -> c(3) + printf("a(3) returns %d\n", A3); + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/Makefile new file mode 100644 index 00000000000..ccaa0edcf5f --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := file1.cpp file2.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/TestSymbolContextTwoFiles.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/TestSymbolContextTwoFiles.py new file mode 100644 index 00000000000..27d1b60a507 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/TestSymbolContextTwoFiles.py @@ -0,0 +1,79 @@ +""" +Test SBSymbolContext APIs. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SymbolContextTwoFilesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @expectedFailureAll(oslist=["windows"]) + def test_lookup_by_address(self): + """Test lookup by address in a module with multiple compilation units""" + self.build() + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + module = target.GetModuleAtIndex(0) + self.assertTrue(module.IsValid()) + for symbol_name in ["struct1::f()", "struct2::f()"]: + sc_list = module.FindFunctions(symbol_name, lldb.eSymbolTypeCode) + self.assertTrue(1, sc_list.GetSize()) + symbol_address = sc_list.GetContextAtIndex( + 0).GetSymbol().GetStartAddress() + self.assertTrue(symbol_address.IsValid()) + sc_by_address = module.ResolveSymbolContextForAddress( + symbol_address, lldb.eSymbolContextFunction) + self.assertEqual(symbol_name, + sc_by_address.GetFunction().GetName()) + + @add_test_categories(['pyapi']) + def test_ranges_in_multiple_compile_unit(self): + """This test verifies that we correctly handle the case when multiple + compile unit contains DW_AT_ranges and DW_AT_ranges_base attributes.""" + self.build() + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + source1 = "file1.cpp" + line1 = line_number(source1, '// Break1') + breakpoint1 = target.BreakpointCreateByLocation(source1, line1) + self.assertIsNotNone(breakpoint1) + self.assertTrue(breakpoint1.IsValid()) + + source2 = "file2.cpp" + line2 = line_number(source2, '// Break2') + breakpoint2 = target.BreakpointCreateByLocation(source2, line2) + self.assertIsNotNone(breakpoint2) + self.assertTrue(breakpoint2.IsValid()) + + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertIsNotNone(process, PROCESS_IS_VALID) + + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint2) + self.assertEqual(len(threads), 1) + frame = threads[0].GetFrameAtIndex(0) + value = frame.FindVariable("x") + self.assertTrue(value.IsValid()) + + process.Continue() + + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, breakpoint1) + self.assertEqual(len(threads), 1) + frame = threads[0].GetFrameAtIndex(0) + value = frame.FindVariable("x") + self.assertTrue(value.IsValid()) + + process.Continue() diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/decls.h b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/decls.h new file mode 100644 index 00000000000..7c804584206 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/decls.h @@ -0,0 +1,11 @@ +struct struct1 { + ~struct1(); + static void f(); +}; + +struct struct2 { + ~struct2(); + static void f(); +}; + +int g(); diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file1.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file1.cpp new file mode 100644 index 00000000000..327d0fb7718 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file1.cpp @@ -0,0 +1,21 @@ +#include "decls.h" + +int g() { + return 1; +} + +struct1::~struct1() { + int x = g(); // Break1 +} + +void struct1::f() {} + +int main() { + struct1::f(); + struct2::f(); + + struct1 s1; + struct2 s2; + + return 0; +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file2.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file2.cpp new file mode 100644 index 00000000000..109e01572ed --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/symbol-context/two-files/file2.cpp @@ -0,0 +1,7 @@ +#include "decls.h" + +struct2::~struct2() { + int x = g(); // Break2 +} + +void struct2::f() {} |