[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:36 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions c,h,cpp -- lldb/include/lldb/Interpreter/Interfaces/ScriptedSymbolLocatorInterface.h lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.cpp lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.h lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.h lldb/test/API/functionalities/scripted_symbol_locator/main.c lldb/include/lldb/API/SBFileSpec.h lldb/include/lldb/API/SBTarget.h lldb/include/lldb/Core/PluginManager.h lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/include/lldb/Symbol/LineEntry.h lldb/include/lldb/Target/Target.h lldb/include/lldb/lldb-forward.h lldb/include/lldb/lldb-private-interfaces.h lldb/source/API/SBTarget.cpp lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Core/Module.cpp lldb/source/Core/PluginManager.cpp lldb/source/Interpreter/ScriptInterpreter.cpp lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.cpp lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptInterpreterPythonInterfaces.h lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp lldb/source/Symbol/LineEntry.cpp lldb/source/Target/StackFrame.cpp lldb/source/Target/StackFrameList.cpp lldb/source/Target/Target.cpp lldb/source/Target/ThreadPlanStepRange.cpp lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp --diff_from_common_commit
``````````
: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 clang-format here.
</summary>
``````````diff
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 1d4490058..a9c28cf4e 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -1013,7 +1013,7 @@ public:
/// \return
/// An SBError indicating success or failure.
lldb::SBError RegisterScriptedSymbolLocator(const char *class_name,
- lldb::SBStructuredData &args);
+ lldb::SBStructuredData &args);
/// Clear the scripted symbol locator for this target.
void ClearScriptedSymbolLocator();
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 97d42be72..1105dd759 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -34,8 +34,8 @@
#include "lldb/Interpreter/Interfaces/ScriptedFrameProviderInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"
-#include "lldb/Interpreter/Interfaces/ScriptedThreadInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedSymbolLocatorInterface.h"
+#include "lldb/Interpreter/Interfaces/ScriptedThreadInterface.h"
#include "lldb/Interpreter/ScriptObject.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Utility/Broadcaster.h"
@@ -547,7 +547,8 @@ public:
return {};
}
- virtual lldb::ScriptedSymbolLocatorInterfaceSP CreateScriptedSymbolLocatorInterface() {
+ virtual lldb::ScriptedSymbolLocatorInterfaceSP
+ CreateScriptedSymbolLocatorInterface() {
return {};
}
@@ -612,8 +613,7 @@ public:
lldb::ExecutionContextRefSP GetOpaqueTypeFromSBExecutionContext(
const lldb::SBExecutionContext &exe_ctx) const;
- FileSpec
- GetOpaqueTypeFromSBFileSpec(const lldb::SBFileSpec &file_spec) const;
+ FileSpec GetOpaqueTypeFromSBFileSpec(const lldb::SBFileSpec &file_spec) const;
lldb::StackFrameListSP
GetOpaqueTypeFromSBFrameList(const lldb::SBFrameList &exe_ctx) const;
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index cf85d832a..d591f1cbc 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1717,8 +1717,8 @@ public:
/// Look up a previously cached source file resolution result.
/// Returns true if a cached entry exists (even if the result is nullopt).
- bool LookupScriptedSourceFileCache(
- const std::string &key, std::optional<FileSpec> &result) const;
+ bool LookupScriptedSourceFileCache(const std::string &key,
+ std::optional<FileSpec> &result) const;
void InsertScriptedSourceFileCache(const std::string &key,
const std::optional<FileSpec> &result);
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 101445ef0..8fe6ea813 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -2432,8 +2432,9 @@ lldb::SBTrace SBTarget::CreateTrace(lldb::SBError &error) {
return SBTrace();
}
-lldb::SBError SBTarget::RegisterScriptedSymbolLocator(
- const char *class_name, lldb::SBStructuredData &args) {
+lldb::SBError
+SBTarget::RegisterScriptedSymbolLocator(const char *class_name,
+ lldb::SBStructuredData &args) {
LLDB_INSTRUMENT_VA(this, class_name, args);
lldb::SBError sb_error;
@@ -2448,8 +2449,7 @@ lldb::SBError SBTarget::RegisterScriptedSymbolLocator(
if (obj_sp && obj_sp->GetType() == lldb::eStructuredDataTypeDictionary)
args_sp = std::static_pointer_cast<StructuredData::Dictionary>(obj_sp);
- Status error =
- target_sp->RegisterScriptedSymbolLocator(class_name, args_sp);
+ Status error = target_sp->RegisterScriptedSymbolLocator(class_name, args_sp);
if (error.Fail())
sb_error.SetErrorString(error.AsCString());
return sb_error;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index b3dbd4476..99dab64b4 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4782,14 +4782,13 @@ public:
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetTarget();
- llvm::StringRef class_name =
- target.GetScriptedSymbolLocatorClassName();
+ llvm::StringRef class_name = target.GetScriptedSymbolLocatorClassName();
if (class_name.empty()) {
result.AppendMessageWithFormat(
"No scripted symbol locator registered for this target.\n");
} else {
- result.AppendMessageWithFormat(
- "Scripted symbol locator: %s\n", class_name.str().c_str());
+ result.AppendMessageWithFormat("Scripted symbol locator: %s\n",
+ class_name.str().c_str());
}
result.SetStatus(eReturnStatusSuccessFinishResult);
}
@@ -4809,13 +4808,11 @@ public:
CommandObjectSP(
new CommandObjectTargetSymbolsScriptedRegister(interpreter)));
LoadSubCommand(
- "clear",
- CommandObjectSP(
- new CommandObjectTargetSymbolsScriptedClear(interpreter)));
+ "clear", CommandObjectSP(
+ new CommandObjectTargetSymbolsScriptedClear(interpreter)));
LoadSubCommand(
- "info",
- CommandObjectSP(
- new CommandObjectTargetSymbolsScriptedInfo(interpreter)));
+ "info", CommandObjectSP(
+ new CommandObjectTargetSymbolsScriptedInfo(interpreter)));
}
~CommandObjectTargetSymbolsScripted() override = default;
@@ -4837,8 +4834,7 @@ public:
"add", CommandObjectSP(new CommandObjectTargetSymbolsAdd(interpreter)));
LoadSubCommand(
"scripted",
- CommandObjectSP(
- new CommandObjectTargetSymbolsScripted(interpreter)));
+ CommandObjectSP(new CommandObjectTargetSymbolsScripted(interpreter)));
}
~CommandObjectTargetSymbols() override = default;
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index 5e6bfe343..5b8bcc7cc 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -1511,8 +1511,7 @@ bool PluginManager::RegisterPlugin(
return GetSymbolLocatorInstances().RegisterPlugin(
name, description, create_callback, locate_executable_object_file,
locate_executable_symbol_file, download_object_symbol_file,
- find_symbol_file_in_bundle, locate_source_file,
- debugger_init_callback);
+ find_symbol_file_in_bundle, locate_source_file, debugger_init_callback);
}
bool PluginManager::UnregisterPlugin(
@@ -1596,9 +1595,8 @@ FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
return {};
}
-FileSpec PluginManager::LocateSourceFile(
- const lldb::ModuleSP &module_sp,
- const FileSpec &original_source_file) {
+FileSpec PluginManager::LocateSourceFile(const lldb::ModuleSP &module_sp,
+ const FileSpec &original_source_file) {
auto instances = GetSymbolLocatorInstances().GetSnapshot();
for (auto &instance : instances) {
if (instance.locate_source_file) {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 76b0d969d..2874d22d2 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -17,12 +17,12 @@
#include <type_traits>
#include <utility>
+#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterface.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/FileSpecList.h"
-#include "lldb/Core/ModuleSpec.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBModuleSpec.h"
@@ -714,10 +714,9 @@ protected:
python::PythonList py_list(arg.GetSize());
for (size_t i = 0; i < arg.GetSize(); i++) {
const FileSpec &fs = arg.GetFileSpecAtIndex(i);
- py_list.SetItemAtIndex(
- i, python::SWIGBridge::ToSWIGWrapper(
- std::make_unique<lldb::SBFileSpec>(fs.GetPath().c_str(),
- false)));
+ py_list.SetItemAtIndex(i, python::SWIGBridge::ToSWIGWrapper(
+ std::make_unique<lldb::SBFileSpec>(
+ fs.GetPath().c_str(), false)));
}
return py_list;
}
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.cpp
index d77620f69..d913615c7 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Host/Config.h"
#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"
@@ -64,13 +64,12 @@ ScriptedSymbolLocatorPythonInterface::LocateExecutableObjectFile(
std::optional<FileSpec>
ScriptedSymbolLocatorPythonInterface::LocateExecutableSymbolFile(
- const ModuleSpec &module_spec,
- const FileSpecList &default_search_paths, Status &error) {
+ const ModuleSpec &module_spec, const FileSpecList &default_search_paths,
+ Status &error) {
ModuleSpec ms_copy(module_spec);
FileSpecList fsl_copy(default_search_paths);
StructuredData::ObjectSP obj =
- Dispatch("locate_executable_symbol_file", error, ms_copy,
- fsl_copy);
+ Dispatch("locate_executable_symbol_file", error, ms_copy, fsl_copy);
if (!obj || error.Fail())
return {};
@@ -97,8 +96,7 @@ bool ScriptedSymbolLocatorPythonInterface::DownloadObjectAndSymbolFile(
return obj->GetBooleanValue();
}
-std::optional<FileSpec>
-ScriptedSymbolLocatorPythonInterface::LocateSourceFile(
+std::optional<FileSpec> ScriptedSymbolLocatorPythonInterface::LocateSourceFile(
const lldb::ModuleSP &module_sp, const FileSpec &original_source_file,
Status &error) {
std::string source_path = original_source_file.GetPath();
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.h
index f0f42d205..24d22f354 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedSymbolLocatorPythonInterface.h
@@ -52,10 +52,9 @@ public:
bool force_lookup,
bool copy_executable) override;
- std::optional<FileSpec>
- LocateSourceFile(const lldb::ModuleSP &module_sp,
- const FileSpec &original_source_file,
- Status &error) override;
+ std::optional<FileSpec> LocateSourceFile(const lldb::ModuleSP &module_sp,
+ const FileSpec &original_source_file,
+ Status &error) override;
static void Initialize();
static void Terminate();
diff --git a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp
index cc6856a48..c3784ccbf 100644
--- a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp
+++ b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp
@@ -116,9 +116,10 @@ std::optional<FileSpec> SymbolLocatorScripted::LocateExecutableSymbolFile(
return result;
}
-bool SymbolLocatorScripted::DownloadObjectAndSymbolFile(
- ModuleSpec &module_spec, Status &error, bool force_lookup,
- bool copy_executable) {
+bool SymbolLocatorScripted::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
+ Status &error,
+ bool force_lookup,
+ bool copy_executable) {
bool result = false;
ForEachScriptedTarget(
[&](Target &target,
@@ -134,8 +135,9 @@ bool SymbolLocatorScripted::DownloadObjectAndSymbolFile(
return result;
}
-std::optional<FileSpec> SymbolLocatorScripted::LocateSourceFile(
- const lldb::ModuleSP &module_sp, const FileSpec &original_source_file) {
+std::optional<FileSpec>
+SymbolLocatorScripted::LocateSourceFile(const lldb::ModuleSP &module_sp,
+ const FileSpec &original_source_file) {
if (!module_sp)
return {};
@@ -170,8 +172,8 @@ std::optional<FileSpec> SymbolLocatorScripted::LocateSourceFile(
// Cache resolved source files to avoid repeated Python calls for the same
// (module, source_file) pair.
- std::string cache_key = module_sp->GetUUID().GetAsString() + ":" +
- original_source_file.GetPath();
+ std::string cache_key =
+ module_sp->GetUUID().GetAsString() + ":" + original_source_file.GetPath();
std::optional<FileSpec> cached;
if (owning_target->LookupScriptedSourceFileCache(cache_key, cached))
diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp
index a8649a0eb..b46916a9a 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -562,7 +562,8 @@ bool StackFrameList::FetchFramesUpTo(uint32_t end_idx,
while (unwind_sc.GetParentOfInlinedScope(
curr_frame_address, next_frame_sc, next_frame_address)) {
- next_frame_sc.line_entry.ApplyFileMappings(target_sp, curr_frame_address);
+ next_frame_sc.line_entry.ApplyFileMappings(target_sp,
+ curr_frame_address);
behaves_like_zeroth_frame = false;
StackFrameSP frame_sp(new StackFrame(
m_thread.shared_from_this(), m_frames.size(), idx,
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 70d9eec19..04b6290d0 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3427,8 +3427,9 @@ void Target::SaveScriptedLaunchInfo(lldb_private::ProcessInfo &process_info) {
}
}
-Status Target::RegisterScriptedSymbolLocator(
- llvm::StringRef class_name, StructuredData::DictionarySP args_sp) {
+Status
+Target::RegisterScriptedSymbolLocator(llvm::StringRef class_name,
+ StructuredData::DictionarySP args_sp) {
if (class_name.empty())
return Status::FromErrorString(
"class name must not be empty; use ClearScriptedSymbolLocator() to "
@@ -3479,8 +3480,7 @@ void Target::ClearScriptedSymbolLocator() {
m_scripted_source_file_cache.clear();
}
-ScriptedSymbolLocatorInterfaceSP
-Target::GetScriptedSymbolLocatorInterface() {
+ScriptedSymbolLocatorInterfaceSP Target::GetScriptedSymbolLocatorInterface() {
return m_scripted_symbol_locator_interface_sp;
}
diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp
index 0675977d0..c75bd68d2 100644
--- a/lldb/source/Target/ThreadPlanStepRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepRange.cpp
@@ -432,8 +432,8 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
std::make_shared<SupportFile>(call_site_file_spec);
top_most_line_entry.range = range;
top_most_line_entry.file_sp = std::make_shared<SupportFile>();
- top_most_line_entry.ApplyFileMappings(
- GetThread().CalculateTarget(), range.GetBaseAddress());
+ top_most_line_entry.ApplyFileMappings(GetThread().CalculateTarget(),
+ range.GetBaseAddress());
if (!top_most_line_entry.file_sp->GetSpecOnly())
top_most_line_entry.file_sp =
top_most_line_entry.original_file_sp;
diff --git a/lldb/test/API/functionalities/scripted_symbol_locator/main.c b/lldb/test/API/functionalities/scripted_symbol_locator/main.c
index beef03096..71a79cd90 100644
--- a/lldb/test/API/functionalities/scripted_symbol_locator/main.c
+++ b/lldb/test/API/functionalities/scripted_symbol_locator/main.c
@@ -2,6 +2,4 @@ int func(int argc) {
return argc + 1; // break here
}
-int main(int argc, const char *argv[]) {
- return func(argc);
-}
+int main(int argc, const char *argv[]) { return func(argc); }
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index a339378b9..400da1107 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -171,8 +171,8 @@ lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFrameList(PyObject *data) {
return nullptr;
}
-void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFileSpec(
- PyObject *data) {
+void *
+lldb_private::python::LLDBSWIGPython_CastPyObjectToSBFileSpec(PyObject *data) {
return nullptr;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/181341
More information about the cfe-commits
mailing list