summaryrefslogtreecommitdiff
path: root/scripts/Python
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Python')
-rw-r--r--scripts/Python/python-extensions.swig82
-rw-r--r--scripts/Python/python-swigsafecast.swig23
-rw-r--r--scripts/Python/python-typemaps.swig269
-rw-r--r--scripts/Python/python-wrapper.swig143
4 files changed, 312 insertions, 205 deletions
diff --git a/scripts/Python/python-extensions.swig b/scripts/Python/python-extensions.swig
index 5543bee95d47..892e1af4bae5 100644
--- a/scripts/Python/python-extensions.swig
+++ b/scripts/Python/python-extensions.swig
@@ -1,5 +1,6 @@
%extend lldb::SBAddress {
+ %nothreadallow;
PyObject *lldb::SBAddress::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -12,8 +13,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBBlock {
+ %nothreadallow;
PyObject *lldb::SBBlock::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -26,8 +29,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBBreakpoint {
+ %nothreadallow;
PyObject *lldb::SBBreakpoint::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -40,6 +45,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -57,6 +63,7 @@
}
%extend lldb::SBBreakpointLocation {
+ %nothreadallow;
PyObject *lldb::SBBreakpointLocation::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelFull);
@@ -69,9 +76,11 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBBreakpointName {
+ %nothreadallow;
PyObject *lldb::SBBreakpointName::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -84,6 +93,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBBroadcaster {
@@ -103,6 +113,7 @@
}
%extend lldb::SBCommandReturnObject {
+ %nothreadallow;
PyObject *lldb::SBCommandReturnObject::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -115,6 +126,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
/* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage
they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort
@@ -130,6 +142,7 @@
{}
}
%extend lldb::SBCompileUnit {
+ %nothreadallow;
PyObject *lldb::SBCompileUnit::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -142,6 +155,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -157,6 +171,7 @@
%}
}
%extend lldb::SBData {
+ %nothreadallow;
PyObject *lldb::SBData::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -169,8 +184,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBDebugger {
+ %nothreadallow;
PyObject *lldb::SBDebugger::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -183,8 +200,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBDeclaration {
+ %nothreadallow;
PyObject *lldb::SBDeclaration::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -197,6 +216,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -214,6 +234,7 @@
}
%extend lldb::SBError {
+ %nothreadallow;
PyObject *lldb::SBError::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -226,8 +247,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBFileSpec {
+ %nothreadallow;
PyObject *lldb::SBFileSpec::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -240,8 +263,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBFrame {
+ %nothreadallow;
PyObject *lldb::SBFrame::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -254,8 +279,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBFunction {
+ %nothreadallow;
PyObject *lldb::SBFunction::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -268,6 +295,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -285,6 +313,7 @@
}
%extend lldb::SBInstruction {
+ %nothreadallow;
PyObject *lldb::SBInstruction::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -297,8 +326,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBInstructionList {
+ %nothreadallow;
PyObject *lldb::SBInstructionList::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -311,8 +342,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBLineEntry {
+ %nothreadallow;
PyObject *lldb::SBLineEntry::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -325,6 +358,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -342,6 +376,7 @@
}
%extend lldb::SBMemoryRegionInfo {
+ %nothreadallow;
PyObject *lldb::SBMemoryRegionInfo::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -354,9 +389,11 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBModule {
+ %nothreadallow;
PyObject *lldb::SBModule::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -369,6 +406,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -386,6 +424,7 @@
}
%extend lldb::SBModuleSpec {
+ %nothreadallow;
PyObject *lldb::SBModuleSpec::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -398,9 +437,11 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBModuleSpecList {
+ %nothreadallow;
PyObject *lldb::SBModuleSpecList::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -413,9 +454,11 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBProcess {
+ %nothreadallow;
PyObject *lldb::SBProcess::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -428,8 +471,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBSection {
+ %nothreadallow;
PyObject *lldb::SBSection::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -442,6 +487,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -472,6 +518,7 @@
{}
}
%extend lldb::SBSymbol {
+ %nothreadallow;
PyObject *lldb::SBSymbol::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -484,6 +531,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -499,6 +547,7 @@
%}
}
%extend lldb::SBSymbolContext {
+ %nothreadallow;
PyObject *lldb::SBSymbolContext::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -511,8 +560,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBSymbolContextList {
+ %nothreadallow;
PyObject *lldb::SBSymbolContextList::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -525,9 +576,11 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTarget {
+ %nothreadallow;
PyObject *lldb::SBTarget::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -540,6 +593,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
@@ -557,6 +611,7 @@
}
%extend lldb::SBType {
+ %nothreadallow;
PyObject *lldb::SBType::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -569,8 +624,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeCategory {
+ %nothreadallow;
PyObject *lldb::SBTypeCategory::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -583,8 +640,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeFilter {
+ %nothreadallow;
PyObject *lldb::SBTypeFilter::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -597,6 +656,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -612,6 +672,7 @@
%}
}
%extend lldb::SBTypeFormat {
+ %nothreadallow;
PyObject *lldb::SBTypeFormat::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -624,8 +685,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeMember {
+ %nothreadallow;
PyObject *lldb::SBTypeMember::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -638,8 +701,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeMemberFunction {
+ %nothreadallow;
PyObject *lldb::SBTypeMemberFunction::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -652,8 +717,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeEnumMember {
+ %nothreadallow;
PyObject *lldb::SBTypeEnumMember::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -666,8 +733,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBTypeNameSpecifier {
+ %nothreadallow;
PyObject *lldb::SBTypeNameSpecifier::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -680,6 +749,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -695,6 +765,7 @@
%}
}
%extend lldb::SBTypeSummary {
+ %nothreadallow;
PyObject *lldb::SBTypeSummary::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -707,6 +778,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -722,6 +794,7 @@
%}
}
%extend lldb::SBTypeSynthetic {
+ %nothreadallow;
PyObject *lldb::SBTypeSynthetic::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelBrief);
@@ -734,6 +807,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -749,6 +823,7 @@
%}
}
%extend lldb::SBThread {
+ %nothreadallow;
PyObject *lldb::SBThread::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -761,6 +836,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -776,6 +852,7 @@
%}
}
%extend lldb::SBValue {
+ %nothreadallow;
PyObject *lldb::SBValue::__str__ (){
lldb::SBStream description;
$self->GetDescription (description);
@@ -788,8 +865,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBValueList {
+ %nothreadallow;
PyObject *lldb::SBValueList::__str__ (){
lldb::SBStream description;
const size_t n = $self->GetSize();
@@ -811,8 +890,10 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
%extend lldb::SBWatchpoint {
+ %nothreadallow;
PyObject *lldb::SBWatchpoint::__str__ (){
lldb::SBStream description;
$self->GetDescription (description, lldb::eDescriptionLevelVerbose);
@@ -825,6 +906,7 @@
else
return lldb_private::PythonString("").release();
}
+ %clearnothreadallow;
}
diff --git a/scripts/Python/python-swigsafecast.swig b/scripts/Python/python-swigsafecast.swig
index ffd7546323a0..d5cafbfa67cb 100644
--- a/scripts/Python/python-swigsafecast.swig
+++ b/scripts/Python/python-swigsafecast.swig
@@ -27,15 +27,6 @@ SBTypeToSWIGWrapper (PyObject* py_object)
template <>
PyObject*
-SBTypeToSWIGWrapper (const char* c_str)
-{
- if (c_str)
- return PyString_FromString(c_str);
- return NULL;
-}
-
-template <>
-PyObject*
SBTypeToSWIGWrapper (unsigned int* c_int)
{
if (!c_int)
@@ -147,3 +138,17 @@ SBTypeToSWIGWrapper (lldb::SBTypeSummaryOptions* summary_options_sb)
{
return SWIG_NewPointerObj((void *) summary_options_sb, SWIGTYPE_p_lldb__SBTypeSummaryOptions, 0);
}
+
+template <>
+PyObject*
+SBTypeToSWIGWrapper (lldb::SBStructuredData* structured_data_sb)
+{
+ return SWIG_NewPointerObj((void *) structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData, 0);
+}
+
+template <>
+PyObject*
+SBTypeToSWIGWrapper (lldb::SBSymbolContext* sym_ctx_sb)
+{
+ return SWIG_NewPointerObj((void *) sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0);
+}
diff --git a/scripts/Python/python-typemaps.swig b/scripts/Python/python-typemaps.swig
index 29e5d9b156df..56cab6c58163 100644
--- a/scripts/Python/python-typemaps.swig
+++ b/scripts/Python/python-typemaps.swig
@@ -77,6 +77,26 @@
}
}
+%typemap(in) lldb::StateType {
+ using namespace lldb_private;
+ if (PythonInteger::Check($input))
+ {
+ PythonInteger py_int(PyRefType::Borrowed, $input);
+ int64_t state_type_value = py_int.GetInteger() ;
+
+ if (state_type_value > lldb::StateType::kLastStateType) {
+ PyErr_SetString(PyExc_ValueError, "Not a valid StateType value");
+ return nullptr;
+ }
+ $1 = static_cast<lldb::StateType>(state_type_value);
+ }
+ else
+ {
+ PyErr_SetString(PyExc_ValueError, "Expecting an integer");
+ return nullptr;
+ }
+}
+
/* Typemap definitions to allow SWIG to properly handle char buffer. */
// typemap for a char buffer
@@ -119,30 +139,9 @@
// typemap for an outgoing buffer
// See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len).
-%typemap(in) (const char *cstr, uint32_t cstr_len) {
- using namespace lldb_private;
- if (PythonString::Check($input)) {
- PythonString str(PyRefType::Borrowed, $input);
- $1 = (char*)str.GetString().data();
- $2 = str.GetSize();
- }
- else if(PythonByteArray::Check($input)) {
- PythonByteArray bytearray(PyRefType::Borrowed, $input);
- $1 = (char*)bytearray.GetBytes().data();
- $2 = bytearray.GetSize();
- }
- else if (PythonBytes::Check($input)) {
- PythonBytes bytes(PyRefType::Borrowed, $input);
- $1 = (char*)bytes.GetBytes().data();
- $2 = bytes.GetSize();
- }
- else {
- PyErr_SetString(PyExc_ValueError, "Expecting a string");
- return NULL;
- }
-}
// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).
-%typemap(in) (const char *src, size_t src_len) {
+%typemap(in) (const char *cstr, uint32_t cstr_len),
+ (const char *src, size_t src_len) {
using namespace lldb_private;
if (PythonString::Check($input)) {
PythonString str(PyRefType::Borrowed, $input);
@@ -164,32 +163,9 @@
return NULL;
}
}
-// And SBProcess::WriteMemory.
-%typemap(in) (const void *buf, size_t size) {
- using namespace lldb_private;
- if (PythonString::Check($input)) {
- PythonString str(PyRefType::Borrowed, $input);
- $1 = (void*)str.GetString().data();
- $2 = str.GetSize();
- }
- else if(PythonByteArray::Check($input)) {
- PythonByteArray bytearray(PyRefType::Borrowed, $input);
- $1 = (void*)bytearray.GetBytes().data();
- $2 = bytearray.GetSize();
- }
- else if (PythonBytes::Check($input)) {
- PythonBytes bytes(PyRefType::Borrowed, $input);
- $1 = (void*)bytes.GetBytes().data();
- $2 = bytes.GetSize();
- }
- else {
- PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
- return NULL;
- }
-}
-
-// For SBDebugger::DispatchInput
-%typemap(in) (const void *data, size_t data_len) {
+// For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput.
+%typemap(in) (const void *buf, size_t size),
+ (const void *data, size_t data_len) {
using namespace lldb_private;
if (PythonString::Check($input)) {
PythonString str(PyRefType::Borrowed, $input);
@@ -244,142 +220,70 @@
free($1);
}
-// these typemaps allow Python users to pass list objects
-// and have them turn into C++ arrays (this is useful, for instance
-// when creating SBData objects from lists of numbers)
-%typemap(in) (uint64_t* array, size_t array_len) {
- /* Check if is a list */
- if (PyList_Check($input)) {
- int size = PyList_Size($input);
- int i = 0;
- $2 = size;
- $1 = (uint64_t*) malloc(size * sizeof(uint64_t));
- for (i = 0; i < size; i++) {
- PyObject *o = PyList_GetItem($input,i);
- if (PyInt_Check(o)) {
- $1[i] = PyInt_AsLong(o);
- }
- else if (PyLong_Check(o)) {
- $1[i] = PyLong_AsUnsignedLongLong(o);
- }
- else {
- PyErr_SetString(PyExc_TypeError,"list must contain numbers");
- free($1);
- return NULL;
- }
-
- if (PyErr_Occurred()) {
- free($1);
- return NULL;
- }
- }
- } else if ($input == Py_None) {
- $1 = NULL;
- $2 = 0;
- } else {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
+%{
+namespace {
+template <class T>
+T PyLongAsT(PyObject *obj) {
+ static_assert(true, "unsupported type");
}
-%typemap(freearg) (uint64_t* array, size_t array_len) {
- free($1);
+template <> uint64_t PyLongAsT<uint64_t>(PyObject *obj) {
+ return static_cast<uint64_t>(PyLong_AsUnsignedLongLong(obj));
}
-%typemap(in) (uint32_t* array, size_t array_len) {
- /* Check if is a list */
- if (PyList_Check($input)) {
- int size = PyList_Size($input);
- int i = 0;
- $2 = size;
- $1 = (uint32_t*) malloc(size * sizeof(uint32_t));
- for (i = 0; i < size; i++) {
- PyObject *o = PyList_GetItem($input,i);
- if (PyInt_Check(o)) {
- $1[i] = PyInt_AsLong(o);
- }
- else if (PyLong_Check(o)) {
- $1[i] = PyLong_AsUnsignedLong(o);
- }
- else {
- PyErr_SetString(PyExc_TypeError,"list must contain numbers");
- free($1);
- return NULL;
- }
+template <> uint32_t PyLongAsT<uint32_t>(PyObject *obj) {
+ return static_cast<uint32_t>(PyLong_AsUnsignedLong(obj));
+}
- if (PyErr_Occurred()) {
- free($1);
- return NULL;
- }
- }
- } else if ($input == Py_None) {
- $1 = NULL;
- $2 = 0;
- } else {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
+template <> int64_t PyLongAsT<int64_t>(PyObject *obj) {
+ return static_cast<int64_t>(PyLong_AsLongLong(obj));
}
-%typemap(freearg) (uint32_t* array, size_t array_len) {
- free($1);
+template <> int32_t PyLongAsT<int32_t>(PyObject *obj) {
+ return static_cast<int32_t>(PyLong_AsLong(obj));
}
-%typemap(in) (int64_t* array, size_t array_len) {
- /* Check if is a list */
- if (PyList_Check($input)) {
- int size = PyList_Size($input);
- int i = 0;
- $2 = size;
- $1 = (int64_t*) malloc(size * sizeof(int64_t));
- for (i = 0; i < size; i++) {
- PyObject *o = PyList_GetItem($input,i);
- if (PyInt_Check(o)) {
- $1[i] = PyInt_AsLong(o);
- }
- else if (PyLong_Check(o)) {
- $1[i] = PyLong_AsLongLong(o);
- }
- else {
- PyErr_SetString(PyExc_TypeError,"list must contain numbers");
- free($1);
- return NULL;
- }
+template <class T>
+bool SetNumberFromPyObject(T &number, PyObject *obj) {
+ if (PyInt_Check(obj))
+ number = static_cast<T>(PyInt_AsLong(obj));
+ else if (PyLong_Check(obj))
+ number = PyLongAsT<T>(obj);
+ else return false;
- if (PyErr_Occurred()) {
- free($1);
- return NULL;
- }
- }
- } else if ($input == Py_None) {
- $1 = NULL;
- $2 = 0;
- } else {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
+ return true;
}
-%typemap(freearg) (int64_t* array, size_t array_len) {
- free($1);
+template <>
+bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
+ if (PyFloat_Check(obj)) {
+ number = PyFloat_AsDouble(obj);
+ return true;
+ }
+
+ return false;
}
-%typemap(in) (int32_t* array, size_t array_len) {
+} // namespace
+%}
+
+// these typemaps allow Python users to pass list objects
+// and have them turn into C++ arrays (this is useful, for instance
+// when creating SBData objects from lists of numbers)
+%typemap(in) (uint64_t* array, size_t array_len),
+ (uint32_t* array, size_t array_len),
+ (int64_t* array, size_t array_len),
+ (int32_t* array, size_t array_len),
+ (double* array, size_t array_len) {
/* Check if is a list */
if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$2 = size;
- $1 = (int32_t*) malloc(size * sizeof(int32_t));
+ $1 = ($1_type) malloc(size * sizeof($*1_type));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
- if (PyInt_Check(o)) {
- $1[i] = PyInt_AsLong(o);
- }
- else if (PyLong_Check(o)) {
- $1[i] = PyLong_AsLong(o);
- }
- else {
+ if (!SetNumberFromPyObject($1[i], o)) {
PyErr_SetString(PyExc_TypeError,"list must contain numbers");
free($1);
return NULL;
@@ -399,38 +303,11 @@
}
}
-%typemap(freearg) (int32_t* array, size_t array_len) {
- free($1);
-}
-
-%typemap(in) (double* array, size_t array_len) {
- /* Check if is a list */
- if (PyList_Check($input)) {
- int size = PyList_Size($input);
- int i = 0;
- $2 = size;
- $1 = (double*) malloc(size * sizeof(double));
- for (i = 0; i < size; i++) {
- PyObject *o = PyList_GetItem($input,i);
- if (PyFloat_Check(o)) {
- $1[i] = PyFloat_AsDouble(o);
- }
- else {
- PyErr_SetString(PyExc_TypeError,"list must contain floating-point numbers");
- free($1);
- return NULL;
- }
- }
- } else if ($input == Py_None) {
- $1 = NULL;
- $2 = 0;
- } else {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
-}
-
-%typemap(freearg) (double* array, size_t array_len) {
+%typemap(freearg) (uint64_t* array, size_t array_len),
+ (uint32_t* array, size_t array_len),
+ (int64_t* array, size_t array_len),
+ (int32_t* array, size_t array_len),
+ (double* array, size_t array_len) {
free($1);
}
diff --git a/scripts/Python/python-wrapper.swig b/scripts/Python/python-wrapper.swig
index 96b8dda80f82..8509899df27b 100644
--- a/scripts/Python/python-wrapper.swig
+++ b/scripts/Python/python-wrapper.swig
@@ -333,6 +333,101 @@ LLDBSWIGPythonCallThreadPlan
return false;
}
+SWIGEXPORT void *
+LLDBSwigPythonCreateScriptedBreakpointResolver
+(
+ const char *python_class_name,
+ const char *session_dictionary_name,
+ lldb_private::StructuredDataImpl *args_impl,
+ lldb::BreakpointSP &breakpoint_sp
+)
+{
+ using namespace lldb_private;
+
+ if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
+ Py_RETURN_NONE;
+
+ PyErr_Cleaner py_err_cleaner(true);
+
+ auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
+ auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
+
+ if (!pfunc.IsAllocated())
+ return nullptr;
+
+ lldb::SBBreakpoint *bkpt_value = new lldb::SBBreakpoint(breakpoint_sp);
+
+ PythonObject bkpt_arg(PyRefType::Owned, SBTypeToSWIGWrapper(bkpt_value));
+
+ lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
+ PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
+
+ PythonObject result = pfunc(bkpt_arg, args_arg, dict);
+ // FIXME: At this point we should check that the class we found supports all the methods
+ // that we need.
+
+ if (result.IsAllocated())
+ {
+ // Check that __callback__ is defined:
+ auto callback_func = result.ResolveName<PythonCallable>("__callback__");
+ if (callback_func.IsAllocated())
+ return result.release();
+ else
+ result.release();
+ }
+ Py_RETURN_NONE;
+}
+
+SWIGEXPORT unsigned int
+LLDBSwigPythonCallBreakpointResolver
+(
+ void *implementor,
+ const char *method_name,
+ lldb_private::SymbolContext *sym_ctx
+)
+{
+ using namespace lldb_private;
+
+ PyErr_Cleaner py_err_cleaner(false);
+ PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
+ auto pfunc = self.ResolveName<PythonCallable>(method_name);
+
+ if (!pfunc.IsAllocated())
+ return 0;
+
+ PythonObject result;
+ if (sym_ctx != nullptr) {
+ lldb::SBSymbolContext sb_sym_ctx(sym_ctx);
+ PythonObject sym_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_sym_ctx));
+ result = pfunc(sym_ctx_arg);
+ } else
+ result = pfunc();
+
+ if (PyErr_Occurred())
+ {
+ PyErr_Print();
+ return 0;
+ }
+
+ // The callback will return a bool, but we're need to also return ints
+ // so we're squirrelling the bool through as an int... And if you return
+ // nothing, we'll continue.
+ if (strcmp(method_name, "__callback__") == 0) {
+ if (result.get() == Py_False)
+ return 0;
+ else
+ return 1;
+ }
+
+ PythonInteger int_result = result.AsType<PythonInteger>();
+ if (!int_result.IsAllocated())
+ return 0;
+
+ unsigned int ret_val = int_result.GetInteger();
+
+ return ret_val;
+}
+
// wrapper that calls an optional instance member of an object taking no arguments
static PyObject*
LLDBSwigPython_CallOptionalMember
@@ -690,6 +785,54 @@ LLDBSWIGPythonCreateOSPlugin
}
SWIGEXPORT void*
+LLDBSWIGPython_CreateFrameRecognizer
+(
+ const char *python_class_name,
+ const char *session_dictionary_name
+)
+{
+ using namespace lldb_private;
+
+ if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
+ Py_RETURN_NONE;
+
+ PyErr_Cleaner py_err_cleaner(true);
+
+ auto dict = PythonModule::MainModule().ResolveName<PythonDictionary>(session_dictionary_name);
+ auto pfunc = PythonObject::ResolveNameWithDictionary<PythonCallable>(python_class_name, dict);
+
+ if (!pfunc.IsAllocated())
+ Py_RETURN_NONE;
+
+ auto result = pfunc();
+
+ if (result.IsAllocated())
+ return result.release();
+
+ Py_RETURN_NONE;
+}
+
+SWIGEXPORT PyObject*
+LLDBSwigPython_GetRecognizedArguments
+(
+ PyObject *implementor,
+ const lldb::StackFrameSP& frame_sp
+)
+{
+ using namespace lldb_private;
+
+ static char callee_name[] = "get_recognized_arguments";
+
+ lldb::SBFrame frame_sb(frame_sp);
+ PyObject *arg = SBTypeToSWIGWrapper(frame_sb);
+
+ PythonString str(callee_name);
+ PyObject* result = PyObject_CallMethodObjArgs(implementor, str.get(), arg,
+ NULL);
+ return result;
+}
+
+SWIGEXPORT void*
LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, const lldb::TargetSP& target_sp)
{
using namespace lldb_private;