Skip to content

Commit a518056

Browse files
committed
[LLDB] Run API tests with PDB too
1 parent 34c2ea3 commit a518056

File tree

8 files changed

+80
-9
lines changed

8 files changed

+80
-9
lines changed

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ def _getDebugInfoArgs(self, debug_info):
258258
"gmodules": {"MAKE_DSYM": "NO", "MAKE_GMODULES": "YES"},
259259
"debug_names": {"MAKE_DEBUG_NAMES": "YES"},
260260
"dwp": {"MAKE_DSYM": "NO", "MAKE_DWP": "YES"},
261+
"native-pdb": {"DEBUG_INFO_FLAG": "-g"},
262+
"dia-pdb": {"DEBUG_INFO_FLAG": "-g"},
261263
}
262264

263265
# Collect all flags, with later options overriding earlier ones

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,13 @@ def setUpCommands(cls):
804804
)
805805
return commands
806806

807+
def getDebugInfoSetupCommands(self):
808+
if self.getDebugInfo() == "native-pdb":
809+
return ["settings set plugin.symbol-file.pdb.reader native"]
810+
if self.getDebugInfo() == "dia-pdb":
811+
return ["settings set plugin.symbol-file.pdb.reader dia"]
812+
return []
813+
807814
def setUp(self):
808815
"""Fixture for unittest test case setup.
809816
@@ -828,13 +835,6 @@ def setUp(self):
828835
else:
829836
self.lldbDAPExec = None
830837

831-
self.lldbOption = " ".join("-o '" + s + "'" for s in self.setUpCommands())
832-
833-
# If we spawn an lldb process for test (via pexpect), do not load the
834-
# init file unless told otherwise.
835-
if os.environ.get("NO_LLDBINIT") != "NO":
836-
self.lldbOption += " --no-lldbinit"
837-
838838
# Assign the test method name to self.testMethodName.
839839
#
840840
# For an example of the use of this attribute, look at test/types dir.
@@ -843,6 +843,14 @@ def setUp(self):
843843
# used for all the test cases.
844844
self.testMethodName = self._testMethodName
845845

846+
setUpCommands = self.setUpCommands() + self.getDebugInfoSetupCommands()
847+
self.lldbOption = " ".join("-o '" + s + "'" for s in setUpCommands)
848+
849+
# If we spawn an lldb process for test (via pexpect), do not load the
850+
# init file unless told otherwise.
851+
if os.environ.get("NO_LLDBINIT") != "NO":
852+
self.lldbOption += " --no-lldbinit"
853+
846854
# This is for the case of directly spawning 'lldb'/'gdb' and interacting
847855
# with it using pexpect.
848856
self.child = None
@@ -1792,6 +1800,12 @@ def no_reason(_):
17921800
if can_replicate
17931801
]
17941802

1803+
# PDB is off by default, because it has a lot of failures right now.
1804+
# See llvm.org/pr149498
1805+
if original_testcase.TEST_WITH_PDB_DEBUG_INFO:
1806+
dbginfo_categories.append("native-pdb")
1807+
dbginfo_categories.append("dia-pdb")
1808+
17951809
xfail_for_debug_info_cat_fn = getattr(
17961810
attrvalue, "__xfail_for_debug_info_cat_fn__", no_reason
17971811
)
@@ -1879,6 +1893,14 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory):
18791893
# test multiple times with various debug info types.
18801894
NO_DEBUG_INFO_TESTCASE = False
18811895

1896+
TEST_WITH_PDB_DEBUG_INFO = False
1897+
"""
1898+
Subclasses can set this to True to test with both native and DIA PDB in addition to
1899+
the other debug info types. This id off by default because many tests will
1900+
fail due to missing functionality in PDB.
1901+
See llvm.org/pr149498.
1902+
"""
1903+
18821904
def generateSource(self, source):
18831905
template = source + ".template"
18841906
temp = os.path.join(self.getSourceDir(), template)
@@ -1918,6 +1940,8 @@ def setUp(self):
19181940

19191941
for s in self.setUpCommands():
19201942
self.runCmd(s)
1943+
for s in self.getDebugInfoSetupCommands():
1944+
self.runCmd(s)
19211945

19221946
# We want our debugger to be synchronous.
19231947
self.dbg.SetAsync(False)
@@ -2264,7 +2288,9 @@ def completions_match(self, command, completions, max_completions=-1):
22642288
given list of completions"""
22652289
interp = self.dbg.GetCommandInterpreter()
22662290
match_strings = lldb.SBStringList()
2267-
interp.HandleCompletion(command, len(command), 0, max_completions, match_strings)
2291+
interp.HandleCompletion(
2292+
command, len(command), 0, max_completions, match_strings
2293+
)
22682294
# match_strings is a 1-indexed list, so we have to slice...
22692295
self.assertCountEqual(
22702296
completions, list(match_strings)[1:], "List of returned completion is wrong"

lldb/packages/Python/lldbsuite/test/test_categories.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# System modules
66
import sys
7+
import os
78

89
# Third-party modules
910

@@ -12,13 +13,21 @@
1213

1314
# Key: Category name
1415
# Value: should be used in lldbtest's debug-info replication
15-
debug_info_categories = {"dwarf": True, "dwo": True, "dsym": True, "gmodules": False}
16+
debug_info_categories = {
17+
"dwarf": True,
18+
"dwo": True,
19+
"dsym": True,
20+
"native-pdb": False,
21+
"dia-pdb": False,
22+
"gmodules": False,
23+
}
1624

1725
all_categories = {
1826
"basic_process": "Basic process execution sniff tests.",
1927
"cmdline": "Tests related to the LLDB command-line interface",
2028
"dataformatters": "Tests related to the type command and the data formatters subsystem",
2129
"debugserver": "Debugserver tests",
30+
"dia-pdb": "Tests that can be run with PDB debug information using the DIA PDB plugin",
2231
"dsym": "Tests that can be run with DSYM debug information",
2332
"dwarf": "Tests that can be run with DWARF debug information",
2433
"dwo": "Tests that can be run with DWO debug information",
@@ -34,6 +43,7 @@
3443
"lldb-dap": "Tests for the Debug Adapter Protocol with lldb-dap",
3544
"llgs": "Tests for the gdb-server functionality of lldb-server",
3645
"msvcstl": "Test for MSVC STL data formatters",
46+
"native-pdb": "Tests that can be run with PDB debug information using the native PDB plugin",
3747
"pexpect": "Tests requiring the pexpect library to be available",
3848
"objc": "Tests related to the Objective-C programming language support",
3949
"pyapi": "Tests related to the Python API",
@@ -65,6 +75,10 @@ def is_supported_on_platform(category, platform, compiler_path):
6575
if platform not in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]:
6676
return False
6777
return gmodules.is_compiler_clang_with_gmodules(compiler_path)
78+
elif category == "native-pdb":
79+
return platform == "windows"
80+
elif category == "dia-pdb":
81+
return os.environ.get("LLVM_ENABLE_DIA_SDK", None) == "1"
6882
return True
6983

7084

lldb/test/API/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def delete_module_cache(path):
349349
for v in ["SystemDrive"]:
350350
if v in os.environ:
351351
config.environment[v] = os.environ[v]
352+
if config.llvm_enable_dia_sdk:
353+
config.environment["LLVM_ENABLE_DIA_SDK"] = "1"
352354

353355
# Some steps required to initialize the tests dynamically link with python.dll
354356
# and need to know the location of the Python libraries. This ensures that we

lldb/test/API/lit.site.cfg.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
import lit.util
4+
35
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
46
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
57
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
68
config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
79
config.llvm_include_dir = lit_config.substitute("@LLVM_INCLUDE_DIR@")
810
config.llvm_shlib_dir = lit_config.substitute("@SHLIBDIR@")
911
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
12+
config.llvm_enable_dia_sdk = lit.util.pythonize_bool("@LLVM_ENABLE_DIA_SDK@")
1013
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
1114
config.lldb_obj_root = lit_config.substitute("@LLDB_BINARY_DIR@")
1215
config.lldb_src_root = "@LLDB_SOURCE_DIR@"

lldb/test/API/test_utils/pdb/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Test PDB enabled tests
3+
"""
4+
5+
from lldbsuite.test.decorators import *
6+
from lldbsuite.test.lldbtest import *
7+
8+
9+
class TestBuildMethod(TestBase):
10+
TEST_WITH_PDB_DEBUG_INFO = True
11+
12+
def test(self):
13+
self.build()
14+
self.assertTrue(self.dbg.CreateTarget(self.getBuildArtifact()))
15+
if self.getDebugInfo() == "native-pdb":
16+
self.expect(
17+
"target modules dump symfile", substrs=["SymbolFile native-pdb"]
18+
)
19+
if self.getDebugInfo() == "dia-pdb":
20+
self.expect("target modules dump symfile", substrs=["SymbolFile pdb"])

lldb/test/API/test_utils/pdb/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main() { return 0; }

0 commit comments

Comments
 (0)