[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
Fri Aug 12 00:43:12 PDT 2022


Michael137 updated this revision to Diff 452098.
Michael137 added a comment.

- Skip Windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131693/new/

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,51 @@
+"""
+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):
+
+    @skipIfWindows
+    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.452098.patch
Type: text/x-patch
Size: 3533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220812/65c265fd/attachment.bin>


More information about the lldb-commits mailing list