[lldb] Convert script native types to StructuredData counterpart
This patch adds the ability to pass native types from the script
interpreter to methods that use a {SB,}StructuredData argument.
To do so, this patch changes the `ScriptedObject` struture that holds
the pointer to the script object as well as the originating script
interpreter language. It also exposes that to the SB API via a new class
called `SBScriptObject`.
This structure allows the debugger to parse the script object and
convert it to a StructuredData object. If the type is not compatible
with the StructuredData types, we will store its pointer in a
`StructuredData::Generic` object.
This patch also adds some SWIG typemaps that checks the input argument to
ensure it's either an SBStructuredData object, in which case it just
passes it throught, or a python object that is NOT another SB type, to
provide some guardrails for the user.
rdar://111467140
Differential Revision: https://reviews.llvm.org/D155161
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
This commit is contained in:
1 parent
aa34b34e93
commit
57bd882343
21 files changed
+376
-9
No files matched your search
@@ -0,0 +1,84 @@
|
||||
//===-- SBScriptObject.cpp ------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/API/SBScriptObject.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include "lldb/Interpreter/ScriptObject.h"
|
||||
#include "lldb/Utility/Instrumentation.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
||||
SBScriptObject::SBScriptObject(const ScriptObjectPtr ptr,
|
||||
lldb::ScriptLanguage lang)
|
||||
: m_opaque_up(std::make_unique<lldb_private::ScriptObject>(ptr, lang)) {
|
||||
LLDB_INSTRUMENT_VA(this, ptr, lang);
|
||||
}
|
||||
|
||||
SBScriptObject::SBScriptObject(const SBScriptObject &rhs)
|
||||
: m_opaque_up(new ScriptObject(nullptr, eScriptLanguageNone)) {
|
||||
LLDB_INSTRUMENT_VA(this, rhs);
|
||||
|
||||
m_opaque_up = clone(rhs.m_opaque_up);
|
||||
}
|
||||
SBScriptObject::~SBScriptObject() = default;
|
||||
|
||||
const SBScriptObject &SBScriptObject::operator=(const SBScriptObject &rhs) {
|
||||
LLDB_INSTRUMENT_VA(this, rhs);
|
||||
|
||||
if (this != &rhs)
|
||||
m_opaque_up = clone(rhs.m_opaque_up);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool SBScriptObject::operator!=(const SBScriptObject &rhs) const {
|
||||
LLDB_INSTRUMENT_VA(this, rhs);
|
||||
|
||||
return !(m_opaque_up == rhs.m_opaque_up);
|
||||
}
|
||||
|
||||
bool SBScriptObject::IsValid() const {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
return this->operator bool();
|
||||
}
|
||||
|
||||
SBScriptObject::operator bool() const {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
return m_opaque_up != nullptr && m_opaque_up->operator bool();
|
||||
}
|
||||
|
||||
lldb::ScriptObjectPtr SBScriptObject::GetPointer() const {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
return m_opaque_up ? const_cast<void *>(m_opaque_up->GetPointer()) : nullptr;
|
||||
}
|
||||
|
||||
lldb::ScriptLanguage SBScriptObject::GetLanguage() const {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
return m_opaque_up ? m_opaque_up->GetLanguage() : eScriptLanguageNone;
|
||||
}
|
||||
|
||||
ScriptObject &SBScriptObject::ref() {
|
||||
if (m_opaque_up == nullptr)
|
||||
m_opaque_up = std::make_unique<ScriptObject>(nullptr, eScriptLanguageNone);
|
||||
return *m_opaque_up;
|
||||
}
|
||||
|
||||
const ScriptObject &SBScriptObject::ref() const {
|
||||
// This object should already have checked with "IsValid()" prior to calling
|
||||
// this function. In case you didn't we will assert and die to let you know.
|
||||
assert(m_opaque_up.get());
|
||||
return *m_opaque_up;
|
||||
}
|
||||
|
||||
ScriptObject *SBScriptObject::get() { return m_opaque_up.get(); }
|
||||
Reference in new issue
Block a user