[Lldb-commits] [lldb] [lldb][Module][NFC] Extract script loading logic into helper (PR #188712)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 26 02:36:44 PDT 2026


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/188712

Planning on re-using this within the same function. Extracting into helper makes that slightly more readable.

>From d6ca024c3923c662547ab64e7b4b89d80e2c7ab1 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 26 Mar 2026 09:33:42 +0000
Subject: [PATCH] [lldb][Module][NFC] Extract script loading logic into helper

Planning on re-using this within the same function. Extracting into helper makes that slightly more readable.
---
 lldb/source/Core/Module.cpp | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index df73872c83685..3d33a5011fb5e 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1420,6 +1420,19 @@ bool Module::IsLoadedInTarget(Target *target) {
   return false;
 }
 
+static bool LoadScriptingModule(const FileSpec &scripting_fspec,
+                                ScriptInterpreter &script_interpreter,
+                                Target &target, Status &error) {
+  assert(scripting_fspec);
+
+  StreamString scripting_stream;
+  scripting_fspec.Dump(scripting_stream.AsRawOstream());
+  LoadScriptOptions options;
+  return script_interpreter.LoadScriptingModule(
+      scripting_stream.GetData(), options, error,
+      /*module_sp*/ nullptr, /*extra_path*/ {}, target.shared_from_this());
+}
+
 bool Module::LoadScriptingResourceInTarget(Target *target, Status &error) {
   if (!target) {
     error = Status::FromErrorString("invalid destination Target");
@@ -1489,13 +1502,8 @@ To run all discovered debug scripts in this session:
     LLDB_LOG(GetLog(LLDBLog::Modules), "Auto-loading {0}",
              scripting_fspec.GetPath());
 
-    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)
+    if (!LoadScriptingModule(scripting_fspec, *script_interpreter, *target,
+                             error))
       return false;
   }
 



More information about the lldb-commits mailing list