https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/149305
>From a518056df828df3d206d1029875bd576cd9ef568 Mon Sep 17 00:00:00 2001 From: Nerixyz <nerix...@outlook.de> Date: Tue, 5 Aug 2025 17:00:23 +0200 Subject: [PATCH 1/2] [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 | 16 ++++++- 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, 80 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..2c435d2fc27db 100644 --- a/lldb/packages/Python/lldbsuite/test/test_categories.py +++ b/lldb/packages/Python/lldbsuite/test/test_categories.py @@ -4,6 +4,7 @@ # System modules import sys +import os # Third-party modules @@ -12,13 +13,21 @@ # 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 +43,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 +75,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; } >From 82d13d376099de1a17db5dbcf05595ca1e939926 Mon Sep 17 00:00:00 2001 From: Nerixyz <nerix...@outlook.de> Date: Fri, 8 Aug 2025 20:54:41 +0200 Subject: [PATCH 2/2] fix: use single pdb debug info option --- .../Python/lldbsuite/test/builders/builder.py | 3 +- .../Python/lldbsuite/test/lldbtest.py | 36 ++++++------------- .../Python/lldbsuite/test/test_categories.py | 11 ++---- lldb/test/API/lit.cfg.py | 2 -- lldb/test/API/lit.site.cfg.py.in | 3 -- lldb/test/API/test_utils/pdb/TestPdb.py | 6 ++-- 6 files changed, 17 insertions(+), 44 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py index 37ba96ad4f55a..b30d0d027fc70 100644 --- a/lldb/packages/Python/lldbsuite/test/builders/builder.py +++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py @@ -258,8 +258,7 @@ 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"}, + "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 0da82aa492801..0668142e1af83 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -804,13 +804,6 @@ 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. @@ -835,6 +828,13 @@ 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,14 +843,6 @@ 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 @@ -1803,8 +1795,7 @@ def no_reason(_): # 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") + dbginfo_categories.append("pdb") xfail_for_debug_info_cat_fn = getattr( attrvalue, "__xfail_for_debug_info_cat_fn__", no_reason @@ -1895,9 +1886,8 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory): 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. + Subclasses can set this to True to test with 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. """ @@ -1940,8 +1930,6 @@ 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) @@ -2288,9 +2276,7 @@ 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 2c435d2fc27db..b8a764fb3349a 100644 --- a/lldb/packages/Python/lldbsuite/test/test_categories.py +++ b/lldb/packages/Python/lldbsuite/test/test_categories.py @@ -4,7 +4,6 @@ # System modules import sys -import os # Third-party modules @@ -17,8 +16,7 @@ "dwarf": True, "dwo": True, "dsym": True, - "native-pdb": False, - "dia-pdb": False, + "pdb": False, "gmodules": False, } @@ -27,7 +25,6 @@ "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", @@ -43,7 +40,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", + "pdb": "Tests that can be run with PDB debug information", "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", @@ -75,10 +72,8 @@ 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": + elif category == "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 d6f215ffd53fb..7ab9749f6266d 100644 --- a/lldb/test/API/lit.cfg.py +++ b/lldb/test/API/lit.cfg.py @@ -349,8 +349,6 @@ 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 d21e94b8795dd..c4e4352fe7915 100644 --- a/lldb/test/API/lit.site.cfg.py.in +++ b/lldb/test/API/lit.site.cfg.py.in @@ -1,7 +1,5 @@ @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@") @@ -9,7 +7,6 @@ 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/TestPdb.py b/lldb/test/API/test_utils/pdb/TestPdb.py index 584d8ad2807e4..bd3a9d0c34ab3 100644 --- a/lldb/test/API/test_utils/pdb/TestPdb.py +++ b/lldb/test/API/test_utils/pdb/TestPdb.py @@ -12,9 +12,7 @@ class TestBuildMethod(TestBase): def test(self): self.build() self.assertTrue(self.dbg.CreateTarget(self.getBuildArtifact())) - if self.getDebugInfo() == "native-pdb": + if self.getDebugInfo() == "pdb": self.expect( - "target modules dump symfile", substrs=["SymbolFile native-pdb"] + "target modules dump symfile", patterns=["SymbolFile (native-)?pdb"] ) - if self.getDebugInfo() == "dia-pdb": - self.expect("target modules dump symfile", substrs=["SymbolFile pdb"]) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits