[Lldb-commits] [PATCH] D131693: [lldb][Breakpoint] Prevent crash when resolving regex breakpoint on functions with asm declaration
Michael Buch via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 11 09:43:47 PDT 2022
Michael137 created this revision.
Michael137 added a reviewer: jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Currently, a function whose mangled name got
changed using an `asm()` statement on its
declaration will cause lldb to crash when
resolving restricted regex breakpoints.
The crash occurs because we previously assumed
that all functions in the SymbolContext will
cleanly demangle into a function name that we
can compare against the restrictions list.
However, with the `asm()` attribute applied
the mangled name may not conform to the
supported mangling schemes and we return
a nullptr.
The fix is to use the fallback parameter to
`ConstString::AsCString()`.
**Testing**
- Added API test
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131693
Files:
lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp
lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/Makefile
lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/TestSourceRegexBreakpointsWithAsm.py
lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/main.cpp
Index: lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/main.cpp
@@ -0,0 +1,8 @@
+int func_with_asm(void) asm("NonStandardMangling");
+
+int func_with_asm(void) { return 10; }
+
+int main() {
+ func_with_asm();
+ return 0;
+}
Index: lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/TestSourceRegexBreakpointsWithAsm.py
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/TestSourceRegexBreakpointsWithAsm.py
@@ -0,0 +1,50 @@
+"""
+Test lldb breakpoint setting by source regular expression.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestSourceRegexBreakpointsWithAsm(TestBase):
+
+ def test_restrictions(self):
+ self.build()
+ self.source_regex_restrictions()
+
+ def source_regex_restrictions(self):
+ """ Test restricting source expressions to to functions with non-standard mangling."""
+ # Create a target by the debugger.
+ exe = self.getBuildArtifact("a.out")
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ asm_tag = "NonStandardMangling"
+
+ # Sanity check that we can set breakpoint on non-standard mangled name
+ main_break = target.BreakpointCreateByName(asm_tag)
+
+ expected_num_locations = 1
+ num_locations = main_break.GetNumLocations()
+ self.assertEqual(
+ num_locations, expected_num_locations,
+ "We should have gotten %d matches, got %d." %
+ (expected_num_locations, num_locations))
+
+ # Check regex on asm tag restricted to function names
+ func_names = lldb.SBStringList()
+ func_names.AppendString('main')
+ func_names.AppendString('func')
+ func_names.AppendString('""')
+ func_names.AppendString('NonStandardMangling')
+
+ main_break = target.BreakpointCreateBySourceRegex(
+ asm_tag, lldb.SBFileSpecList(), lldb.SBFileSpecList(), func_names)
+
+ expected_num_locations = 0
+ num_locations = main_break.GetNumLocations()
+ self.assertEqual(
+ num_locations, expected_num_locations,
+ "We should have gotten %d matches, got %d." %
+ (expected_num_locations, num_locations))
Index: lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/breakpoint/source_regexp_with_asm/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp
+++ lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp
@@ -122,8 +122,9 @@
sc_ctx
.GetFunctionName(
Mangled::NamePreference::ePreferDemangledWithoutArguments)
- .AsCString());
- if (!m_function_names.count(name)) {
+ .AsCString(""));
+
+ if (name.empty() || !m_function_names.count(name)) {
sc_to_remove.push_back(i);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131693.451889.patch
Type: text/x-patch
Size: 3515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220811/68d2a7f7/attachment-0001.bin>
More information about the lldb-commits
mailing list