[Lldb-commits] [lldb] 1dd9e20 - [lldb] Fix UbSan decorator (#177964)

via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 29 03:29:06 PST 2026


Author: Ebuka Ezike
Date: 2026-01-29T11:29:01Z
New Revision: 1dd9e200469262ffa5ab658d10143ef4f93d9adf

URL: https://github.com/llvm/llvm-project/commit/1dd9e200469262ffa5ab658d10143ef4f93d9adf
DIFF: https://github.com/llvm/llvm-project/commit/1dd9e200469262ffa5ab658d10143ef4f93d9adf.diff

LOG: [lldb] Fix UbSan decorator (#177964)

the ubsan decorator previously assumes the platform is macOS.

macOS has an extra underscore in symbols names match two or more.
uses the llvm-nm that is built instead of the system's nm.

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/configuration.py
    lldb/packages/Python/lldbsuite/test/decorators.py
    lldb/packages/Python/lldbsuite/test/dotest.py
    lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py
index c2c46b94454a5..f96fd31b17a37 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -12,6 +12,7 @@
 
 
 # Third-party modules
+from typing import Optional
 import unittest
 
 # LLDB Modules
@@ -61,6 +62,9 @@
 # Path to the FileCheck testing tool. Not optional.
 filecheck = None
 
+# Path to the nm tool.
+nm: Optional[str] = None
+
 # Path to the yaml2obj tool. Not optional.
 yaml2obj = None
 
@@ -171,6 +175,14 @@ def get_filecheck_path():
         return filecheck
 
 
+def get_nm_path():
+    """
+    Get the path to the nm tool.
+    """
+    if nm and os.path.lexists(nm):
+        return nm
+
+
 def get_yaml2obj_path():
     """
     Get the path to the yaml2obj tool.

diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index e80384fa818ce..df0b2cba4c573 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -1039,36 +1039,18 @@ def is_compiler_clang_with_ubsan():
                 outputf,
             ):
                 return "Compiler cannot compile with -fsanitize=undefined"
+            if not outputf.path:
+                return "Cannot create Temp file path."
+
+            nm_bin = configuration.get_nm_path()
+            if not nm_bin:
+                return "No llvm-nm or nm binary."
 
             # Check that we actually see ubsan instrumentation in the binary.
-            cmd = "nm %s" % outputf.path
-            with os.popen(cmd) as nm_output:
-                if "___ubsan_handle_divrem_overflow" not in nm_output.read():
-                    return "Division by zero instrumentation is missing"
-
-        # Find the ubsan dylib.
-        # FIXME: This check should go away once compiler-rt gains support for __ubsan_on_report.
-        cmd = (
-            "%s -fsanitize=undefined -x c - -o - -### 2>&1"
-            % lldbplatformutil.getCompiler()
-        )
-        with os.popen(cmd) as cc_output:
-            driver_jobs = cc_output.read()
-            m = re.search(r'"([^"]+libclang_rt.ubsan_osx_dynamic.dylib)"', driver_jobs)
-            if not m:
-                return "Could not find the ubsan dylib used by the driver"
-            ubsan_dylib = m.group(1)
-
-        # Check that the ubsan dylib has special monitor hooks.
-        cmd = "nm -gU %s" % ubsan_dylib
-        with os.popen(cmd) as nm_output:
-            syms = nm_output.read()
-            if "___ubsan_on_report" not in syms:
-                return "Missing ___ubsan_on_report"
-            if "___ubsan_get_current_report_data" not in syms:
-                return "Missing ___ubsan_get_current_report_data"
-
-        # OK, this dylib + compiler works for us.
+            nm_output = subprocess.check_output([nm_bin, outputf.path], text=True)
+            if "__ubsan_handle_divrem_overflow" not in nm_output:
+                return "Division by zero instrumentation is missing"
+
         return None
 
     return skipTestIfFn(is_compiler_clang_with_ubsan)(func)

diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 84490d86c7e7f..533be0a065e3a 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -280,6 +280,9 @@ def parseOptionsAndInitTestdirs():
         configuration.llvm_tools_dir = args.llvm_tools_dir
         configuration.filecheck = shutil.which("FileCheck", path=args.llvm_tools_dir)
         configuration.yaml2obj = shutil.which("yaml2obj", path=args.llvm_tools_dir)
+        configuration.nm = shutil.which(
+            "llvm-nm", path=args.llvm_tools_dir
+        ) or shutil.which("nm", path=args.llvm_tools_dir)
 
     if not configuration.get_filecheck_path():
         logging.warning("No valid FileCheck executable; some tests may fail...")

diff  --git a/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py b/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
index 9e9ea2114196e..8a98fdbb309f7 100644
--- a/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
+++ b/lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
@@ -52,11 +52,11 @@ def ubsan_tests(self):
             substrs=["1 match found"],
         )
 
+        # FIXME: Check on non macOS platform we land don't
+        # stop on __ubsan_on_report instead we stop on main.
         if self.platformIsDarwin():
             # We should not be stopped in the sanitizer library.
             self.assertIn("main", frame.GetFunctionName())
-        else:
-            self.assertIn("__ubsan_on_report", frame.GetFunctionName())
 
         # The stopped thread backtrace should contain either 'align line'
         found = False


        


More information about the lldb-commits mailing list