Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lldb/bindings/python/python-wrapper.swig
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,18 @@ void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject * data
return sb_ptr;
}

void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValueList(PyObject * data) {
lldb::SBValueList *sb_ptr = NULL;

int valid_cast =
SWIG_ConvertPtr(data, (void **)&sb_ptr, SWIGTYPE_p_lldb__SBValueList, 0);

if (valid_cast == -1)
return NULL;

return sb_ptr;
}

void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *
data) {
lldb::SBMemoryRegionInfo *sb_ptr = NULL;
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/API/SBValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ class LLDB_API SBValue {
void SetSP(const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic,
bool use_synthetic, const char *name);

protected:
friend class lldb_private::ScriptInterpreter;

private:
typedef std::shared_ptr<lldb_private::ValueImpl> ValueImplSP;
ValueImplSP m_opaque_sp;
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Interpreter/ScriptInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ class ScriptInterpreter : public PluginInterface {
lldb::StackFrameListSP
GetOpaqueTypeFromSBFrameList(const lldb::SBFrameList &exe_ctx) const;

lldb::ValueObjectSP
GetOpaqueTypeFromSBValue(const lldb::SBValue &value) const;

protected:
Debugger &m_debugger;
lldb::ScriptLanguage m_script_lang;
Expand Down
10 changes: 10 additions & 0 deletions lldb/source/Interpreter/ScriptInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "lldb/ValueObject/ValueObject.h"
#if defined(_WIN32)
#include "lldb/Host/windows/ConnectionGenericFileWindows.h"
#endif
Expand Down Expand Up @@ -162,6 +163,15 @@ lldb::StackFrameListSP ScriptInterpreter::GetOpaqueTypeFromSBFrameList(
return frame_list.m_opaque_sp;
}

lldb::ValueObjectSP
ScriptInterpreter::GetOpaqueTypeFromSBValue(const lldb::SBValue &value) const {
if (!value.m_opaque_sp)
return lldb::ValueObjectSP();

lldb_private::ValueLocker locker;
return locker.GetLockedSP(*value.m_opaque_sp);
}

lldb::ScriptLanguage
ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
if (language.equals_insensitive(LanguageToString(eScriptLanguageNone)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPythonInterface.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/ValueObject/ValueObjectList.h"
#include <optional>

using namespace lldb;
Expand Down Expand Up @@ -273,4 +274,41 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StackFrameListSP>(
return m_interpreter.GetOpaqueTypeFromSBFrameList(*sb_frame_list);
}

template <>
lldb::ValueObjectSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectSP>(
python::PythonObject &p, Status &error) {
lldb::SBValue *sb_value = reinterpret_cast<lldb::SBValue *>(
python::LLDBSWIGPython_CastPyObjectToSBValue(p.get()));
if (!sb_value) {
error = Status::FromErrorStringWithFormat(
"couldn't cast lldb::SBValue to lldb::ValueObjectSP");
return {};
}

return m_interpreter.GetOpaqueTypeFromSBValue(*sb_value);
}

template <>
lldb::ValueObjectListSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectListSP>(
python::PythonObject &p, Status &error) {
lldb::SBValueList *sb_value_list = reinterpret_cast<lldb::SBValueList *>(
python::LLDBSWIGPython_CastPyObjectToSBValueList(p.get()));

if (!sb_value_list) {
error = Status::FromErrorStringWithFormat(
"couldn't cast lldb::SBValueList to lldb::ValueObjectListSP");
return {};
}

lldb::ValueObjectListSP out = std::make_shared<ValueObjectList>();
for (uint32_t i = 0, e = sb_value_list->GetSize(); i < e; ++i) {
SBValue value = sb_value_list->GetValueAtIndex(i);
out->Append(m_interpreter.GetOpaqueTypeFromSBValue(value));
}

return out;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
return python::SWIGBridge::ToSWIGWrapper(arg);
}

python::PythonObject Transform(lldb::ValueObjectSP arg) {
return python::SWIGBridge::ToSWIGWrapper(arg);
}

template <typename T, typename U>
void ReverseTransform(T &original_arg, U transformed_arg, Status &error) {
// If U is not a PythonObject, don't touch it!
Expand Down Expand Up @@ -814,6 +818,16 @@ lldb::StackFrameListSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StackFrameListSP>(
python::PythonObject &p, Status &error);

template <>
lldb::ValueObjectSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectSP>(
python::PythonObject &p, Status &error);

template <>
lldb::ValueObjectListSP
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectListSP>(
python::PythonObject &p, Status &error);

} // namespace lldb_private

#endif // LLDB_ENABLE_PYTHON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ void *LLDBSWIGPython_CastPyObjectToSBThread(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBFrame(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBSymbolContext(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBValueList(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBExecutionContext(PyObject *data);
void *LLDBSWIGPython_CastPyObjectToSBFrameList(PyObject *data);
Expand Down
Loading