[Lldb-commits] [lldb] [LLDB] Run API tests with PDB too (PR #149305)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 5 08:16:37 PDT 2025
https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/149305
>From 31a047eeb95e066fc4f287413b39aa0b692f90e5 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Tue, 5 Aug 2025 17:00:23 +0200
Subject: [PATCH] [LLDB] Run API tests with PDB too
---
.../Python/lldbsuite/test/builders/builder.py | 2 +
.../Python/lldbsuite/test/lldbtest.py | 42 +++++++++++++++----
.../Python/lldbsuite/test/test_categories.py | 17 +++++++-
lldb/test/API/lit.cfg.py | 2 +
lldb/test/API/lit.site.cfg.py.in | 3 ++
lldb/test/API/test_utils/pdb/Makefile | 3 ++
lldb/test/API/test_utils/pdb/TestPdb.py | 20 +++++++++
lldb/test/API/test_utils/pdb/main.cpp | 1 +
8 files changed, 81 insertions(+), 9 deletions(-)
create mode 100644 lldb/test/API/test_utils/pdb/Makefile
create mode 100644 lldb/test/API/test_utils/pdb/TestPdb.py
create mode 100644 lldb/test/API/test_utils/pdb/main.cpp
diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 96c7b3987d8a1..37ba96ad4f55a 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -258,6 +258,8 @@ def _getDebugInfoArgs(self, debug_info):
"gmodules": {"MAKE_DSYM": "NO", "MAKE_GMODULES": "YES"},
"debug_names": {"MAKE_DEBUG_NAMES": "YES"},
"dwp": {"MAKE_DSYM": "NO", "MAKE_DWP": "YES"},
+ "native-pdb": {"DEBUG_INFO_FLAG": "-g"},
+ "dia-pdb": {"DEBUG_INFO_FLAG": "-g"},
}
# Collect all flags, with later options overriding earlier ones
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 0fc85fcc4d2d6..0da82aa492801 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -804,6 +804,13 @@ def setUpCommands(cls):
)
return commands
+ def getDebugInfoSetupCommands(self):
+ if self.getDebugInfo() == "native-pdb":
+ return ["settings set plugin.symbol-file.pdb.reader native"]
+ if self.getDebugInfo() == "dia-pdb":
+ return ["settings set plugin.symbol-file.pdb.reader dia"]
+ return []
+
def setUp(self):
"""Fixture for unittest test case setup.
@@ -828,13 +835,6 @@ def setUp(self):
else:
self.lldbDAPExec = None
- self.lldbOption = " ".join("-o '" + s + "'" for s in self.setUpCommands())
-
- # If we spawn an lldb process for test (via pexpect), do not load the
- # init file unless told otherwise.
- if os.environ.get("NO_LLDBINIT") != "NO":
- self.lldbOption += " --no-lldbinit"
-
# Assign the test method name to self.testMethodName.
#
# For an example of the use of this attribute, look at test/types dir.
@@ -843,6 +843,14 @@ def setUp(self):
# used for all the test cases.
self.testMethodName = self._testMethodName
+ setUpCommands = self.setUpCommands() + self.getDebugInfoSetupCommands()
+ self.lldbOption = " ".join("-o '" + s + "'" for s in setUpCommands)
+
+ # If we spawn an lldb process for test (via pexpect), do not load the
+ # init file unless told otherwise.
+ if os.environ.get("NO_LLDBINIT") != "NO":
+ self.lldbOption += " --no-lldbinit"
+
# This is for the case of directly spawning 'lldb'/'gdb' and interacting
# with it using pexpect.
self.child = None
@@ -1792,6 +1800,12 @@ def no_reason(_):
if can_replicate
]
+ # PDB is off by default, because it has a lot of failures right now.
+ # See llvm.org/pr149498
+ if original_testcase.TEST_WITH_PDB_DEBUG_INFO:
+ dbginfo_categories.append("native-pdb")
+ dbginfo_categories.append("dia-pdb")
+
xfail_for_debug_info_cat_fn = getattr(
attrvalue, "__xfail_for_debug_info_cat_fn__", no_reason
)
@@ -1879,6 +1893,14 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory):
# test multiple times with various debug info types.
NO_DEBUG_INFO_TESTCASE = False
+ TEST_WITH_PDB_DEBUG_INFO = False
+ """
+ Subclasses can set this to True to test with both native and DIA PDB in addition to
+ the other debug info types. This id off by default because many tests will
+ fail due to missing functionality in PDB.
+ See llvm.org/pr149498.
+ """
+
def generateSource(self, source):
template = source + ".template"
temp = os.path.join(self.getSourceDir(), template)
@@ -1918,6 +1940,8 @@ def setUp(self):
for s in self.setUpCommands():
self.runCmd(s)
+ for s in self.getDebugInfoSetupCommands():
+ self.runCmd(s)
# We want our debugger to be synchronous.
self.dbg.SetAsync(False)
@@ -2264,7 +2288,9 @@ def completions_match(self, command, completions, max_completions=-1):
given list of completions"""
interp = self.dbg.GetCommandInterpreter()
match_strings = lldb.SBStringList()
- interp.HandleCompletion(command, len(command), 0, max_completions, match_strings)
+ interp.HandleCompletion(
+ command, len(command), 0, max_completions, match_strings
+ )
# match_strings is a 1-indexed list, so we have to slice...
self.assertCountEqual(
completions, list(match_strings)[1:], "List of returned completion is wrong"
diff --git a/lldb/packages/Python/lldbsuite/test/test_categories.py b/lldb/packages/Python/lldbsuite/test/test_categories.py
index 1f6e8a78e0c0d..8a0d284d1906e 100644
--- a/lldb/packages/Python/lldbsuite/test/test_categories.py
+++ b/lldb/packages/Python/lldbsuite/test/test_categories.py
@@ -4,21 +4,31 @@
# System modules
import sys
+import os
# Third-party modules
# LLDB modules
from lldbsuite.support import gmodules
+from . import configuration
# Key: Category name
# Value: should be used in lldbtest's debug-info replication
-debug_info_categories = {"dwarf": True, "dwo": True, "dsym": True, "gmodules": False}
+debug_info_categories = {
+ "dwarf": True,
+ "dwo": True,
+ "dsym": True,
+ "native-pdb": False,
+ "dia-pdb": False,
+ "gmodules": False,
+}
all_categories = {
"basic_process": "Basic process execution sniff tests.",
"cmdline": "Tests related to the LLDB command-line interface",
"dataformatters": "Tests related to the type command and the data formatters subsystem",
"debugserver": "Debugserver tests",
+ "dia-pdb": "Tests that can be run with PDB debug information using the DIA PDB plugin",
"dsym": "Tests that can be run with DSYM debug information",
"dwarf": "Tests that can be run with DWARF debug information",
"dwo": "Tests that can be run with DWO debug information",
@@ -34,6 +44,7 @@
"lldb-dap": "Tests for the Debug Adapter Protocol with lldb-dap",
"llgs": "Tests for the gdb-server functionality of lldb-server",
"msvcstl": "Test for MSVC STL data formatters",
+ "native-pdb": "Tests that can be run with PDB debug information using the native PDB plugin",
"pexpect": "Tests requiring the pexpect library to be available",
"objc": "Tests related to the Objective-C programming language support",
"pyapi": "Tests related to the Python API",
@@ -65,6 +76,10 @@ def is_supported_on_platform(category, platform, compiler_path):
if platform not in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]:
return False
return gmodules.is_compiler_clang_with_gmodules(compiler_path)
+ elif category == "native-pdb":
+ return platform == "windows"
+ elif category == "dia-pdb":
+ return os.environ.get("LLVM_ENABLE_DIA_SDK", None) == "1"
return True
diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index 7ab9749f6266d..d6f215ffd53fb 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -349,6 +349,8 @@ def delete_module_cache(path):
for v in ["SystemDrive"]:
if v in os.environ:
config.environment[v] = os.environ[v]
+ if config.llvm_enable_dia_sdk:
+ config.environment["LLVM_ENABLE_DIA_SDK"] = "1"
# Some steps required to initialize the tests dynamically link with python.dll
# and need to know the location of the Python libraries. This ensures that we
diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index c4e4352fe7915..d21e94b8795dd 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -1,5 +1,7 @@
@LIT_SITE_CFG_IN_HEADER@
+import lit.util
+
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
@@ -7,6 +9,7 @@ config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
config.llvm_include_dir = lit_config.substitute("@LLVM_INCLUDE_DIR@")
config.llvm_shlib_dir = lit_config.substitute("@SHLIBDIR@")
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
+config.llvm_enable_dia_sdk = lit.util.pythonize_bool("@LLVM_ENABLE_DIA_SDK@")
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
config.lldb_obj_root = lit_config.substitute("@LLDB_BINARY_DIR@")
config.lldb_src_root = "@LLDB_SOURCE_DIR@"
diff --git a/lldb/test/API/test_utils/pdb/Makefile b/lldb/test/API/test_utils/pdb/Makefile
new file mode 100644
index 0000000000000..99998b20bcb05
--- /dev/null
+++ b/lldb/test/API/test_utils/pdb/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/test_utils/pdb/TestPdb.py b/lldb/test/API/test_utils/pdb/TestPdb.py
new file mode 100644
index 0000000000000..584d8ad2807e4
--- /dev/null
+++ b/lldb/test/API/test_utils/pdb/TestPdb.py
@@ -0,0 +1,20 @@
+"""
+Test PDB enabled tests
+"""
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestBuildMethod(TestBase):
+ TEST_WITH_PDB_DEBUG_INFO = True
+
+ def test(self):
+ self.build()
+ self.assertTrue(self.dbg.CreateTarget(self.getBuildArtifact()))
+ if self.getDebugInfo() == "native-pdb":
+ self.expect(
+ "target modules dump symfile", substrs=["SymbolFile native-pdb"]
+ )
+ if self.getDebugInfo() == "dia-pdb":
+ self.expect("target modules dump symfile", substrs=["SymbolFile pdb"])
diff --git a/lldb/test/API/test_utils/pdb/main.cpp b/lldb/test/API/test_utils/pdb/main.cpp
new file mode 100644
index 0000000000000..76e8197013aab
--- /dev/null
+++ b/lldb/test/API/test_utils/pdb/main.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
More information about the lldb-commits
mailing list