Skip to content

Commit f030429

Browse files
authored
Merge pull request #6377 from medismailben/stable/20221013
2 parents d8093c5 + 4346461 commit f030429

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1228
-560
lines changed

lldb/bindings/interface/SBAttachInfo.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ public:
112112

113113
void
114114
SetListener (lldb::SBListener &listener);
115+
116+
const char *
117+
GetScriptedProcessClassName() const;
118+
119+
void SetScriptedProcessClassName(const char *class_name);
120+
121+
lldb::SBStructuredData
122+
GetScriptedProcessDictionary() const;
123+
124+
void SetScriptedProcessDictionary(lldb::SBStructuredData dict);
115125
};
116126

117127
} // namespace lldb

lldb/bindings/interface/SBProcess.i

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,18 @@ public:
449449

450450
#ifdef SWIGPYTHON
451451
%pythoncode %{
452+
def WriteMemoryAsCString(self, addr, str, error):
453+
'''
454+
WriteMemoryAsCString(self, addr, str, error):
455+
This functions the same as `WriteMemory` except a null-terminator is appended
456+
to the end of the buffer if it is not there already.
457+
'''
458+
if not str or len(str) == 0:
459+
return 0
460+
if not str[-1] == '\0':
461+
str += '\0'
462+
return self.WriteMemory(addr, str, error)
463+
452464
def __get_is_alive__(self):
453465
'''Returns "True" if the process is currently alive, "False" otherwise'''
454466
s = self.GetState()

lldb/bindings/python/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
106106
FILES
107107
"${LLDB_SOURCE_DIR}/examples/python/scripted_process/scripted_process.py")
108108

109+
create_python_package(
110+
${swig_target}
111+
${lldb_python_target_dir}
112+
"plugins"
113+
FILES
114+
"${LLDB_SOURCE_DIR}/examples/python/scripted_process/scripted_platform.py")
115+
109116
if(APPLE)
110117
create_python_package(
111118
${swig_target}

lldb/bindings/python/python-swigsafecast.swig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ PythonObject ToSWIGWrapper(const SymbolContext &sym_ctx) {
8989
SWIGTYPE_p_lldb__SBSymbolContext);
9090
}
9191

92+
PythonObject ToSWIGWrapper(lldb::ProcessLaunchInfoSP launch_info_sp) {
93+
return ToSWIGHelper(new lldb::ProcessLaunchInfoSP(std::move(launch_info_sp)),
94+
SWIGTYPE_p_lldb__SBLaunchInfo);
95+
}
96+
97+
PythonObject ToSWIGWrapper(lldb::ProcessAttachInfoSP attach_info_sp) {
98+
return ToSWIGHelper(new lldb::ProcessAttachInfoSP(std::move(attach_info_sp)),
99+
SWIGTYPE_p_lldb__SBAttachInfo);
100+
}
101+
102+
PythonObject ToSWIGWrapper(lldb::DataExtractorSP data_sp) {
103+
return ToSWIGHelper(new lldb::DataExtractorSP(std::move(data_sp)),
104+
SWIGTYPE_p_lldb__SBData);
105+
}
106+
92107
ScopedPythonObject<lldb::SBCommandReturnObject>
93108
ToSWIGWrapper(CommandReturnObject &cmd_retobj) {
94109
return ScopedPythonObject<lldb::SBCommandReturnObject>(

lldb/bindings/python/python-typemaps.swig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
if (!$result) {
6262
$result = Py_None;
6363
Py_INCREF(Py_None);
64+
} else {
65+
Py_INCREF($result);
6466
}
6567
}
6668

lldb/bindings/python/python-wrapper.swig

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
203203
return pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
204204
}
205205

206-
PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
206+
PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject(
207207
const char *python_class_name, const char *session_dictionary_name,
208-
const lldb::TargetSP &target_sp,
208+
lldb::ExecutionContextRefSP exe_ctx_sp,
209209
const lldb_private::StructuredDataImpl &args_impl,
210210
std::string &error_string) {
211211
if (python_class_name == NULL || python_class_name[0] == '\0' ||
@@ -225,8 +225,6 @@ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
225225
return PythonObject();
226226
}
227227

228-
PythonObject target_arg = ToSWIGWrapper(target_sp);
229-
230228
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
231229
if (!arg_info) {
232230
llvm::handleAllErrors(
@@ -240,54 +238,14 @@ PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
240238

241239
PythonObject result = {};
242240
if (arg_info.get().max_positional_args == 2) {
243-
result = pfunc(target_arg, ToSWIGWrapper(args_impl));
241+
result = pfunc(ToSWIGWrapper(exe_ctx_sp), ToSWIGWrapper(args_impl));
244242
} else {
245243
error_string.assign("wrong number of arguments in __init__, should be 2 "
246244
"(not including self)");
247245
}
248246
return result;
249247
}
250248

251-
PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
252-
const char *python_class_name, const char *session_dictionary_name,
253-
const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
254-
std::string &error_string) {
255-
if (python_class_name == NULL || python_class_name[0] == '\0' ||
256-
!session_dictionary_name)
257-
return PythonObject();
258-
259-
PyErr_Cleaner py_err_cleaner(true);
260-
261-
auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(
262-
session_dictionary_name);
263-
auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(
264-
python_class_name, dict);
265-
266-
if (!pfunc.IsAllocated()) {
267-
error_string.append("could not find script class: ");
268-
error_string.append(python_class_name);
269-
return PythonObject();
270-
}
271-
272-
llvm::Expected<PythonCallable::ArgInfo> arg_info = pfunc.GetArgInfo();
273-
if (!arg_info) {
274-
llvm::handleAllErrors(
275-
arg_info.takeError(),
276-
[&](PythonException &E) { error_string.append(E.ReadBacktrace()); },
277-
[&](const llvm::ErrorInfoBase &E) {
278-
error_string.append(E.message());
279-
});
280-
return PythonObject();
281-
}
282-
283-
if (arg_info.get().max_positional_args == 2)
284-
return pfunc(ToSWIGWrapper(process_sp), ToSWIGWrapper(args_impl));
285-
286-
error_string.assign("wrong number of arguments in __init__, should be 2 "
287-
"(not including self)");
288-
return PythonObject();
289-
}
290-
291249
PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
292250
const char *python_class_name, const char *session_dictionary_name,
293251
const lldb_private::StructuredDataImpl &args_impl,
@@ -732,6 +690,30 @@ void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject * data) {
732690
return sb_ptr;
733691
}
734692

693+
void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject * data) {
694+
lldb::SBAttachInfo *sb_ptr = nullptr;
695+
696+
int valid_cast =
697+
SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBAttachInfo, 0);
698+
699+
if (valid_cast == -1)
700+
return NULL;
701+
702+
return sb_ptr;
703+
}
704+
705+
void *lldb_private::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject * data) {
706+
lldb::SBLaunchInfo *sb_ptr = nullptr;
707+
708+
int valid_cast =
709+
SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBLaunchInfo, 0);
710+
711+
if (valid_cast == -1)
712+
return NULL;
713+
714+
return sb_ptr;
715+
}
716+
735717
void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject * data) {
736718
lldb::SBError *sb_ptr = nullptr;
737719

0 commit comments

Comments
 (0)