summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2012-01-06 00:46:12 +0000
committerJohnny Chen <johnny.chen@apple.com>2012-01-06 00:46:12 +0000
commit39c6d0f9ae60dae09d48eaa264339ff438bbebd2 (patch)
treed3f4c34417b7acdfd1de8514df5f8f8daec75a1a /lldb/scripts/Python
parent650e3b014ea230203bebd8a293c893cdb6b3727e (diff)
downloadbcm5719-llvm-39c6d0f9ae60dae09d48eaa264339ff438bbebd2.tar.gz
bcm5719-llvm-39c6d0f9ae60dae09d48eaa264339ff438bbebd2.zip
http://llvm.org/bugs/show_bug.cgi?id=11619
Allow creating SBData values from arrays or primitives in Python Patch submitted by Enrico Granata. llvm-svn: 147639
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r--lldb/scripts/Python/interface/SBProcess.i19
-rw-r--r--lldb/scripts/Python/python-typemaps.swig153
2 files changed, 172 insertions, 0 deletions
diff --git a/lldb/scripts/Python/interface/SBProcess.i b/lldb/scripts/Python/interface/SBProcess.i
index da8a28f209a..ee324d21b11 100644
--- a/lldb/scripts/Python/interface/SBProcess.i
+++ b/lldb/scripts/Python/interface/SBProcess.i
@@ -280,6 +280,25 @@ public:
lldb::SBError
UnloadImage (uint32_t image_token);
+
+ lldb::SBData
+ GetDataFromCString(const char* data);
+
+ lldb::SBData
+ GetDataFromUnsignedInt64Array(uint64_t* array, size_t array_len);
+
+ lldb::SBData
+ GetDataFromUnsignedInt32Array(uint32_t* array, size_t array_len);
+
+ lldb::SBData
+ GetDataFromSignedInt64Array(int64_t* array, size_t array_len);
+
+ lldb::SBData
+ GetDataFromSignedInt32Array(int32_t* array, size_t array_len);
+
+ lldb::SBData
+ GetDataFromDoubleArray(double* array, size_t array_len);
+
};
} // namespace lldb
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index 86ce7af6980..539e55a01a7 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -135,3 +135,156 @@
$result = PyString_FromStringAndSize(static_cast<const char*>($1),result);
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 {
+ PyErr_SetString(PyExc_TypeError,"list must contain numbers");
+ free($1);
+ return NULL;
+ }
+ }
+ } else if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%typemap(freearg) (uint64_t* array, size_t array_len) {
+ free($1);
+}
+
+%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 {
+ PyErr_SetString(PyExc_TypeError,"list must contain numbers");
+ free($1);
+ return NULL;
+ }
+ }
+ } else if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%typemap(freearg) (uint32_t* array, size_t array_len) {
+ free($1);
+}
+
+%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 {
+ PyErr_SetString(PyExc_TypeError,"list must contain numbers");
+ free($1);
+ return NULL;
+ }
+ }
+ } else if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%typemap(freearg) (int64_t* array, size_t array_len) {
+ free($1);
+}
+
+%typemap(in) (int32_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 = (int32_t*) malloc(size * sizeof(int32_t));
+ for (i = 0; i < size; i++) {
+ PyObject *o = PyList_GetItem($input,i);
+ if (PyInt_Check(o)) {
+ $1[i] = PyInt_AsLong(o);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,"list must contain numbers");
+ free($1);
+ return NULL;
+ }
+ }
+ } else if ($input == Py_None) {
+ $1 = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%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;
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+
+%typemap(freearg) (double* array, size_t array_len) {
+ free($1);
+}
OpenPOWER on IntegriCloud