[clang-tools-extra] [lldb] [lldb] Add Python base class for ScriptedSymbolLocator (PR #181341)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 10:56:34 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r origin/main...HEAD lldb/examples/python/templates/scripted_symbol_locator.py lldb/test/API/functionalities/scripted_symbol_locator/TestScriptedSymbolLocator.py lldb/test/API/functionalities/scripted_symbol_locator/source_locator.py
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- examples/python/templates/scripted_symbol_locator.py 2026-02-13 18:53:53.000000 +0000
+++ examples/python/templates/scripted_symbol_locator.py 2026-02-13 18:55:40.540011 +0000
@@ -103,12 +103,13 @@
str: The path to the located symbol file, or None to fall
through to LLDB's default search.
"""
return None
- def download_object_and_symbol_file(self, module_spec, force_lookup,
- copy_executable):
+ def download_object_and_symbol_file(
+ self, module_spec, force_lookup, copy_executable
+ ):
"""Download both the object file and symbol file for a module.
Called when LLDB needs to download a binary and its debug symbols
from a remote source (e.g., a symbol server, build artifact
store, or cloud storage). This is the last method called in the
@@ -197,26 +198,22 @@
return None
def locate_executable_object_file(self, module_spec):
"""Look up executables under ``<cache_dir>/<uuid>/``."""
uuid_str = module_spec.GetUUIDString()
- filename = os.path.basename(
- module_spec.GetFileSpec().GetFilename() or ""
- )
+ filename = os.path.basename(module_spec.GetFileSpec().GetFilename() or "")
if not filename:
return None
path = self._get_cache_path(uuid_str, filename)
if path and os.path.exists(path):
return path
return None
def locate_executable_symbol_file(self, module_spec, default_search_paths):
"""Look up debug symbol files under ``<cache_dir>/<uuid>/``."""
uuid_str = module_spec.GetUUIDString()
- filename = os.path.basename(
- module_spec.GetFileSpec().GetFilename() or ""
- )
+ filename = os.path.basename(module_spec.GetFileSpec().GetFilename() or "")
if not filename:
return None
debug_path = self._get_cache_path(uuid_str, filename + ".debug")
if debug_path and os.path.exists(debug_path):
return debug_path
--- test/API/functionalities/scripted_symbol_locator/TestScriptedSymbolLocator.py 2026-02-13 18:53:53.000000 +0000
+++ test/API/functionalities/scripted_symbol_locator/TestScriptedSymbolLocator.py 2026-02-13 18:55:40.594326 +0000
@@ -36,13 +36,11 @@
def script(self, expr):
"""Execute a Python expression in LLDB's script interpreter and return
the result as a string."""
ret = lldb.SBCommandReturnObject()
- self.dbg.GetCommandInterpreter().HandleCommand(
- "script " + expr, ret
- )
+ self.dbg.GetCommandInterpreter().HandleCommand("script " + expr, ret)
return ret.GetOutput().strip() if ret.Succeeded() else ""
def test_locate_source_file(self):
"""Test that the scripted locator resolves source files and receives
an SBModule with a valid UUID."""
--- test/API/functionalities/scripted_symbol_locator/source_locator.py 2026-02-13 18:53:53.000000 +0000
+++ test/API/functionalities/scripted_symbol_locator/source_locator.py 2026-02-13 18:55:40.619871 +0000
@@ -5,52 +5,70 @@
class SourceLocator:
"""Test locator that records calls and returns a configured resolved path."""
- def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData) -> None:
+ def __init__(
+ self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
+ ) -> None:
self.calls: list = []
self.resolved_dir: Optional[str] = None
if args.IsValid():
resolved_dir_val = args.GetValueForKey("resolved_dir")
if resolved_dir_val and resolved_dir_val.IsValid():
val = resolved_dir_val.GetStringValue(4096)
if val:
self.resolved_dir = val
- def locate_source_file(self, module: lldb.SBModule, original_source_file: str) -> Optional[str]:
+ def locate_source_file(
+ self, module: lldb.SBModule, original_source_file: str
+ ) -> Optional[str]:
uuid = module.GetUUIDString()
self.calls.append((uuid, original_source_file))
if self.resolved_dir:
basename = os.path.basename(original_source_file)
return os.path.join(self.resolved_dir, basename)
return None
- def locate_executable_object_file(self, module_spec: lldb.SBModuleSpec) -> Optional[str]:
+ def locate_executable_object_file(
+ self, module_spec: lldb.SBModuleSpec
+ ) -> Optional[str]:
return None
- def locate_executable_symbol_file(self, module_spec: lldb.SBModuleSpec, default_search_paths: list) -> Optional[str]:
+ def locate_executable_symbol_file(
+ self, module_spec: lldb.SBModuleSpec, default_search_paths: list
+ ) -> Optional[str]:
return None
- def download_object_and_symbol_file(self, module_spec: lldb.SBModuleSpec, force_lookup: bool,
- copy_executable: bool) -> bool:
+ def download_object_and_symbol_file(
+ self, module_spec: lldb.SBModuleSpec, force_lookup: bool, copy_executable: bool
+ ) -> bool:
return False
class NoneLocator:
"""Locator that always returns None."""
- def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData) -> None:
+ def __init__(
+ self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
+ ) -> None:
pass
- def locate_source_file(self, module: lldb.SBModule, original_source_file: str) -> Optional[str]:
+ def locate_source_file(
+ self, module: lldb.SBModule, original_source_file: str
+ ) -> Optional[str]:
return None
- def locate_executable_object_file(self, module_spec: lldb.SBModuleSpec) -> Optional[str]:
+ def locate_executable_object_file(
+ self, module_spec: lldb.SBModuleSpec
+ ) -> Optional[str]:
return None
- def locate_executable_symbol_file(self, module_spec: lldb.SBModuleSpec, default_search_paths: list) -> Optional[str]:
+ def locate_executable_symbol_file(
+ self, module_spec: lldb.SBModuleSpec, default_search_paths: list
+ ) -> Optional[str]:
return None
- def download_object_and_symbol_file(self, module_spec: lldb.SBModuleSpec, force_lookup: bool,
- copy_executable: bool) -> bool:
+ def download_object_and_symbol_file(
+ self, module_spec: lldb.SBModuleSpec, force_lookup: bool, copy_executable: bool
+ ) -> bool:
return False
``````````
</details>
https://github.com/llvm/llvm-project/pull/181341
More information about the cfe-commits
mailing list