Skip to content

Commit 73daaea

Browse files
Merge pull request #10462 from jimingham/loaded-into-target
Add a new affordance that the Python module in a dSYM
2 parents 7965a49 + fdd9045 commit 73daaea

File tree

15 files changed

+180
-11
lines changed

15 files changed

+180
-11
lines changed

lldb/bindings/python/python-wrapper.swig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,28 @@ bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
10511051
return true;
10521052
}
10531053

1054+
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
1055+
const char *python_module_name, const char *session_dictionary_name,
1056+
lldb::TargetSP target_sp) {
1057+
std::string python_function_name_string = python_module_name;
1058+
python_function_name_string += ".__lldb_module_added_to_target";
1059+
const char *python_function_name = python_function_name_string.c_str();
1060+
1061+
PyErr_Cleaner py_err_cleaner(true);
1062+
1063+
auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
1064+
session_dictionary_name);
1065+
auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
1066+
python_function_name, dict);
1067+
1068+
if (!pfunc.IsAllocated())
1069+
return true;
1070+
1071+
pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict);
1072+
1073+
return true;
1074+
}
1075+
10541076
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
10551077
const char *python_module_name, const char *session_dictionary_name,
10561078
lldb::DebuggerSP debugger) {

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,6 +5863,28 @@ bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
58635863
return true;
58645864
}
58655865

5866+
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
5867+
const char *python_module_name, const char *session_dictionary_name,
5868+
lldb::TargetSP target_sp) {
5869+
std::string python_function_name_string = python_module_name;
5870+
python_function_name_string += ".__lldb_module_added_to_target";
5871+
const char *python_function_name = python_function_name_string.c_str();
5872+
5873+
PyErr_Cleaner py_err_cleaner(true);
5874+
5875+
auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
5876+
session_dictionary_name);
5877+
auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
5878+
python_function_name, dict);
5879+
5880+
if (!pfunc.IsAllocated())
5881+
return true;
5882+
5883+
pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict);
5884+
5885+
return true;
5886+
}
5887+
58665888
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
58675889
const char *python_module_name, const char *session_dictionary_name,
58685890
lldb::DebuggerSP debugger) {

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ class ScriptInterpreter : public PluginInterface {
539539
LoadScriptingModule(const char *filename, const LoadScriptOptions &options,
540540
lldb_private::Status &error,
541541
StructuredData::ObjectSP *module_sp = nullptr,
542-
FileSpec extra_search_dir = {});
542+
FileSpec extra_search_dir = {},
543+
lldb::TargetSP loaded_into_target_sp = {});
543544

544545
virtual bool IsReservedWord(const char *word) { return false; }
545546

lldb/source/Core/Module.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,9 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
16241624
scripting_fspec.Dump(scripting_stream.AsRawOstream());
16251625
LoadScriptOptions options;
16261626
bool did_load = script_interpreter->LoadScriptingModule(
1627-
scripting_stream.GetData(), options, error);
1627+
scripting_stream.GetData(), options, error,
1628+
/*module_sp*/ nullptr, /*extra_path*/ {},
1629+
target->shared_from_this());
16281630
if (!did_load)
16291631
return false;
16301632
}

lldb/source/Interpreter/ScriptInterpreter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ StructuredData::DictionarySP ScriptInterpreter::GetInterpreterInfo() {
4848
return nullptr;
4949
}
5050

51-
bool ScriptInterpreter::LoadScriptingModule(const char *filename,
52-
const LoadScriptOptions &options,
53-
lldb_private::Status &error,
54-
StructuredData::ObjectSP *module_sp,
55-
FileSpec extra_search_dir) {
51+
bool ScriptInterpreter::LoadScriptingModule(
52+
const char *filename, const LoadScriptOptions &options,
53+
lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
54+
FileSpec extra_search_dir, lldb::TargetSP loaded_into_target_sp) {
5655
error = Status::FromErrorString(
5756
"This script interpreter does not support importing modules.");
5857
return false;

lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void ScriptInterpreterLua::ExecuteInterpreterLoop() {
228228
bool ScriptInterpreterLua::LoadScriptingModule(
229229
const char *filename, const LoadScriptOptions &options,
230230
lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
231-
FileSpec extra_search_dir) {
231+
FileSpec extra_search_dir, lldb::TargetSP loaded_into_target_sp) {
232232

233233
if (llvm::Error e = m_lua->LoadModule(filename)) {
234234
error = Status::FromErrorStringWithFormatv(

lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ScriptInterpreterLua : public ScriptInterpreter {
4747
const LoadScriptOptions &options,
4848
lldb_private::Status &error,
4949
StructuredData::ObjectSP *module_sp = nullptr,
50-
FileSpec extra_search_dir = {}) override;
50+
FileSpec extra_search_dir = {},
51+
lldb::TargetSP loaded_into_target_sp = {}) override;
5152

5253
StructuredData::DictionarySP GetInterpreterInfo() override;
5354

lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ class SWIGBridge {
224224
const char *session_dictionary_name,
225225
lldb::DebuggerSP debugger);
226226

227+
static bool
228+
LLDBSwigPythonCallModuleNewTarget(const char *python_module_name,
229+
const char *session_dictionary_name,
230+
lldb::TargetSP target);
231+
227232
static python::PythonObject
228233
LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
229234
const char *session_dictionary_name,

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ uint64_t replace_all(std::string &str, const std::string &oldStr,
23812381
bool ScriptInterpreterPythonImpl::LoadScriptingModule(
23822382
const char *pathname, const LoadScriptOptions &options,
23832383
lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
2384-
FileSpec extra_search_dir) {
2384+
FileSpec extra_search_dir, lldb::TargetSP target_sp) {
23852385
namespace fs = llvm::sys::fs;
23862386
namespace path = llvm::sys::path;
23872387

@@ -2559,6 +2559,12 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
25592559
PyRefType::Owned, static_cast<PyObject *>(module_pyobj)));
25602560
}
25612561

2562+
// Finally, if we got a target passed in, then we should tell the new module
2563+
// about this target:
2564+
if (target_sp)
2565+
return SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
2566+
module_name.c_str(), m_dictionary_name.c_str(), target_sp);
2567+
25622568
return true;
25632569
}
25642570

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
252252
const LoadScriptOptions &options,
253253
lldb_private::Status &error,
254254
StructuredData::ObjectSP *module_sp = nullptr,
255-
FileSpec extra_search_dir = {}) override;
255+
FileSpec extra_search_dir = {},
256+
lldb::TargetSP loaded_into_target_sp = {}) override;
256257

257258
bool IsReservedWord(const char *word) override;
258259

0 commit comments

Comments
 (0)