aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp94
1 files changed, 54 insertions, 40 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index 6f087e8390ce..019924fa1971 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -7,15 +7,17 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/Config.h"
+#if LLDB_ENABLE_PYTHON
+// LLDB Python header must be included first
+#include "lldb-python.h"
+#endif
+#include "lldb/Target/Process.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"
#if LLDB_ENABLE_PYTHON
-// LLDB Python header must be included first
-#include "lldb-python.h"
-
#include "SWIGPythonBridge.h"
#include "ScriptInterpreterPythonImpl.h"
#include "ScriptedProcessPythonInterface.h"
@@ -46,7 +48,7 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
lldb::ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);
- PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
+ PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
class_name.str().c_str(), m_interpreter.GetDictionaryName(),
exe_ctx_ref_sp, args_impl, error_string);
@@ -56,26 +58,31 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
return m_object_instance_sp;
}
-Status ScriptedProcessPythonInterface::Launch() {
- return GetStatusFromMethod("launch");
-}
-
-Status ScriptedProcessPythonInterface::Resume() {
- return GetStatusFromMethod("resume");
-}
-
-bool ScriptedProcessPythonInterface::ShouldStop() {
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetCapabilities() {
Status error;
- StructuredData::ObjectSP obj = Dispatch("is_alive", error);
+ StructuredData::DictionarySP dict =
+ Dispatch<StructuredData::DictionarySP>("get_capabilities", error);
- if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
+ if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
return {};
- return obj->GetBooleanValue();
+ return dict;
+}
+
+Status
+ScriptedProcessPythonInterface::Attach(const ProcessAttachInfo &attach_info) {
+ lldb::ProcessAttachInfoSP attach_info_sp =
+ std::make_shared<ProcessAttachInfo>(attach_info);
+ return GetStatusFromMethod("attach", attach_info_sp);
+}
+
+Status ScriptedProcessPythonInterface::Launch() {
+ return GetStatusFromMethod("launch");
}
-Status ScriptedProcessPythonInterface::Stop() {
- return GetStatusFromMethod("stop");
+Status ScriptedProcessPythonInterface::Resume() {
+ // When calling ScriptedProcess.Resume from lldb we should always stop.
+ return GetStatusFromMethod("resume", /*should_stop=*/true);
}
std::optional<MemoryRegionInfo>
@@ -103,23 +110,20 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
return dict;
}
-StructuredData::DictionarySP
-ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
- Status error;
- StructuredData::ObjectSP obj = Dispatch("get_thread_with_id", error, tid);
+bool ScriptedProcessPythonInterface::CreateBreakpoint(lldb::addr_t addr,
+ Status &error) {
+ Status py_error;
+ StructuredData::ObjectSP obj =
+ Dispatch("create_breakpoint", py_error, addr, error);
+
+ // If there was an error on the python call, surface it to the user.
+ if (py_error.Fail())
+ error = py_error;
if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
return {};
- StructuredData::DictionarySP dict{obj->GetAsDictionary()};
-
- return dict;
-}
-
-StructuredData::DictionarySP
-ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) {
- // TODO: Implement
- return {};
+ return obj->GetBooleanValue();
}
lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress(
@@ -135,19 +139,29 @@ lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress(
return data_sp;
}
+lldb::offset_t ScriptedProcessPythonInterface::WriteMemoryAtAddress(
+ lldb::addr_t addr, lldb::DataExtractorSP data_sp, Status &error) {
+ Status py_error;
+ StructuredData::ObjectSP obj =
+ Dispatch("write_memory_at_address", py_error, addr, data_sp, error);
+
+ if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
+ return LLDB_INVALID_OFFSET;
+
+ // If there was an error on the python call, surface it to the user.
+ if (py_error.Fail())
+ error = py_error;
+
+ return obj->GetUnsignedIntegerValue(LLDB_INVALID_OFFSET);
+}
+
StructuredData::ArraySP ScriptedProcessPythonInterface::GetLoadedImages() {
Status error;
StructuredData::ArraySP array =
Dispatch<StructuredData::ArraySP>("get_loaded_images", error);
- if (!array || !array->IsValid() || error.Fail()) {
- return ScriptedInterface::ErrorWithMessage<StructuredData::ArraySP>(
- LLVM_PRETTY_FUNCTION,
- llvm::Twine("Null or invalid object (" +
- llvm::Twine(error.AsCString()) + llvm::Twine(")."))
- .str(),
- error);
- }
+ if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, array, error))
+ return {};
return array;
}
@@ -159,7 +173,7 @@ lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() {
if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
return LLDB_INVALID_PROCESS_ID;
- return obj->GetIntegerValue(LLDB_INVALID_PROCESS_ID);
+ return obj->GetUnsignedIntegerValue(LLDB_INVALID_PROCESS_ID);
}
bool ScriptedProcessPythonInterface::IsAlive() {