From 2a062d693693f92d80656cb2b334b7dc8e08121f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 28 Aug 2025 19:10:52 -0700 Subject: [lldb] Add SBFunction::GetBaseName() & SBSymbol::GetBaseName() (#155939) When you are trying for instance to set a breakpoint on a function by name, but the SBFunction or SBSymbol are returning demangled names with argument lists, that match can be tedious to do. Internally, the base name of a symbol is something we handle all the time, so it's reasonable that there should be a way to get that info from the API as well. rdar://159318791 --- lldb/test/API/python_api/basename/Makefile | 3 ++ .../API/python_api/basename/TestGetBaseName.py | 36 ++++++++++++++++++++++ lldb/test/API/python_api/basename/main.cpp | 16 ++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lldb/test/API/python_api/basename/Makefile create mode 100644 lldb/test/API/python_api/basename/TestGetBaseName.py create mode 100644 lldb/test/API/python_api/basename/main.cpp (limited to 'lldb/test/API/python_api') diff --git a/lldb/test/API/python_api/basename/Makefile b/lldb/test/API/python_api/basename/Makefile new file mode 100644 index 0000000..99998b2 --- /dev/null +++ b/lldb/test/API/python_api/basename/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/python_api/basename/TestGetBaseName.py b/lldb/test/API/python_api/basename/TestGetBaseName.py new file mode 100644 index 0000000..bd91acd --- /dev/null +++ b/lldb/test/API/python_api/basename/TestGetBaseName.py @@ -0,0 +1,36 @@ +""" +Test SBFunction::GetBaseName() and SBSymbol::GetBaseName() APIs. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class GetBaseNameTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + TestBase.setUp(self) + self.main_source_file = lldb.SBFileSpec("main.cpp") + + def test(self): + """Test SBFunction.GetBaseName() and SBSymbol.GetBaseName()""" + self.build() + _, _, thread, _ = lldbutil.run_to_source_breakpoint( + self, "Set a breakpoint here", self.main_source_file + ) + + frame0 = thread.GetFrameAtIndex(0) + + # Get both function and symbol + function = frame0.GetFunction() + symbol = frame0.GetSymbol() + + # Test consistency between function and symbol basename + function_basename = function.GetBaseName() + symbol_basename = symbol.GetBaseName() + + self.assertEqual(function_basename, "templateFunc") + self.assertEqual(symbol_basename, "templateFunc") diff --git a/lldb/test/API/python_api/basename/main.cpp b/lldb/test/API/python_api/basename/main.cpp new file mode 100644 index 0000000..9b41409 --- /dev/null +++ b/lldb/test/API/python_api/basename/main.cpp @@ -0,0 +1,16 @@ +#include + +namespace ns { +template class MyClass { +public: + void templateFunc() { + std::cout << "In templateFunc" << std::endl; // Set a breakpoint here + } +}; +} // namespace ns + +int main() { + ns::MyClass obj; + obj.templateFunc(); + return 0; +} -- cgit v1.1