[Lldb-commits] [lldb] [lldb][PlatformDarwin][NFC] Use early-return style in LoadScriptingResourceInTarget (PR #186392)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 13 06:22:40 PDT 2026
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/186392
Planning on adding more to this function/loop soon. Making it early-return style (as suggested by the LLVM style guide makes those changes easier to reason about).
>From b31adddb589fee4c6b48ec720ff4824ba08c5283 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 13 Mar 2026 13:19:01 +0000
Subject: [PATCH] [lldb][PlatformDarwin][NFC] Use early-return style in
LoadScriptingResourceInTarget
Planning on adding more to this function/loop soon. Making it
early-return style (as suggested by the LLVM style guide makes those
changes easier to reason about).
---
lldb/source/Core/Module.cpp | 91 +++++++++++++++++++------------------
1 file changed, 46 insertions(+), 45 deletions(-)
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 863b43e2385f2..2f6876feb597b 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1438,56 +1438,57 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
Debugger &debugger = target->GetDebugger();
const ScriptLanguage script_language = debugger.GetScriptLanguage();
- if (script_language != eScriptLanguageNone) {
+ if (script_language == eScriptLanguageNone)
+ return true;
- PlatformSP platform_sp(target->GetPlatform());
+ PlatformSP platform_sp(target->GetPlatform());
- if (!platform_sp) {
- error = Status::FromErrorString("invalid Platform");
- return false;
- }
+ if (!platform_sp) {
+ error = Status::FromErrorString("invalid Platform");
+ return false;
+ }
- FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
- target, *this, feedback_stream);
-
- const uint32_t num_specs = file_specs.GetSize();
- if (num_specs) {
- ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
- if (script_interpreter) {
- for (uint32_t i = 0; i < num_specs; ++i) {
- FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
- if (scripting_fspec &&
- FileSystem::Instance().Exists(scripting_fspec)) {
- if (should_load == eLoadScriptFromSymFileWarn) {
- feedback_stream.Printf(
- "warning: '%s' contains a debug script. To run this script "
- "in "
- "this debug session:\n\n command script import "
- "\"%s\"\n\n"
- "To run all discovered debug scripts in this session:\n\n"
- " settings set target.load-script-from-symbol-file "
- "true\n",
- GetFileSpec().GetFileNameStrippingExtension().GetCString(),
- scripting_fspec.GetPath().c_str());
- return false;
- }
- StreamString scripting_stream;
- scripting_fspec.Dump(scripting_stream.AsRawOstream());
- LoadScriptOptions options;
- bool did_load = script_interpreter->LoadScriptingModule(
- scripting_stream.GetData(), options, error,
- /*module_sp*/ nullptr, /*extra_path*/ {},
- target->shared_from_this());
- if (!did_load)
- return false;
- }
- }
- } else {
- error = Status::FromErrorString("invalid ScriptInterpreter");
- return false;
- }
+ FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
+ target, *this, feedback_stream);
+
+ const uint32_t num_specs = file_specs.GetSize();
+ if (num_specs == 0)
+ return true;
+
+ ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
+ if (!script_interpreter) {
+ error = Status::FromErrorString("invalid ScriptInterpreter");
+ return false;
+ }
+
+ for (uint32_t i = 0; i < num_specs; ++i) {
+ FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
+ if (!scripting_fspec && !FileSystem::Instance().Exists(scripting_fspec))
+ continue;
+
+ if (should_load == eLoadScriptFromSymFileWarn) {
+ feedback_stream.Printf(
+ "warning: '%s' contains a debug script. To run this script "
+ "in "
+ "this debug session:\n\n command script import "
+ "\"%s\"\n\n"
+ "To run all discovered debug scripts in this session:\n\n"
+ " settings set target.load-script-from-symbol-file "
+ "true\n",
+ GetFileSpec().GetFileNameStrippingExtension().GetCString(),
+ scripting_fspec.GetPath().c_str());
+ return false;
}
+ StreamString scripting_stream;
+ scripting_fspec.Dump(scripting_stream.AsRawOstream());
+ LoadScriptOptions options;
+ bool did_load = script_interpreter->LoadScriptingModule(
+ scripting_stream.GetData(), options, error,
+ /*module_sp*/ nullptr, /*extra_path*/ {}, target->shared_from_this());
+ if (!did_load)
+ return false;
}
+
return true;
}
More information about the lldb-commits
mailing list