aboutsummaryrefslogtreecommitdiff
path: root/scripts/lldb.swig
diff options
context:
space:
mode:
authorEnrico Granata <granata.enrico@gmail.com>2011-07-15 02:26:42 +0000
committerEnrico Granata <granata.enrico@gmail.com>2011-07-15 02:26:42 +0000
commitf7a9b14c2c02d2fa9fad586c19f29d77533fcc09 (patch)
treee116337f230ddc573c29fd3bbd7c5fa445e7c04e /scripts/lldb.swig
parente3a83d21d6f4fd813446fc7471c739507bbe11b5 (diff)
downloadlldb-f7a9b14c2c02d2fa9fad586c19f29d77533fcc09.tar.gz
Python summary strings:
- you can use a Python script to write a summary string for data-types, in one of three ways: -P option and typing the script a line at a time -s option and passing a one-line Python script -F option and passing the name of a Python function these options all work for the "type summary add" command your Python code (if provided through -P or -s) is wrapped in a function that accepts two parameters: valobj (a ValueObject) and dict (an LLDB internal dictionary object). if you use -F and give a function name, you're expected to define the function on your own and with the right prototype. your function, however defined, must return a Python string - test case for the Python summary feature - a few quirks: Python summaries cannot have names, and cannot use regex as type names both issues will be fixed ASAP major redesign of type summary code: - type summary working with strings and type summary working with Python code are two classes, with a common base class SummaryFormat - SummaryFormat classes now are able to actively format objects rather than just aggregating data - cleaner code to print descriptions for summaries the public API now exports a method to easily navigate a ValueObject hierarchy New InputReaderEZ and PriorityPointerPair classes Several minor fixes and improvements git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@135238 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'scripts/lldb.swig')
-rw-r--r--scripts/lldb.swig124
1 files changed, 124 insertions, 0 deletions
diff --git a/scripts/lldb.swig b/scripts/lldb.swig
index 9d9cc2547..158004c68 100644
--- a/scripts/lldb.swig
+++ b/scripts/lldb.swig
@@ -359,4 +359,128 @@ LLDBSwigPythonBreakpointCallbackFunction
return stop_at_breakpoint;
}
+SWIGEXPORT std::string
+LLDBSwigPythonCallTypeScript
+(
+ const char *python_function_name,
+ const char *session_dictionary_name,
+ const lldb::ValueObjectSP& valobj_sp
+)
+{
+ lldb::SBValue sb_value (valobj_sp);
+
+ std::string retval = "";
+
+ PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *) &valobj_sp, SWIGTYPE_p_lldb__SBValue, 0);
+
+ if (ValObj_PyObj == NULL)
+ return retval;
+
+ if (!python_function_name || !session_dictionary_name)
+ return retval;
+
+ PyObject *pmodule, *main_dict, *session_dict, *pfunc;
+ PyObject *pargs, *pvalue;
+
+ pmodule = PyImport_AddModule ("__main__");
+ if (pmodule != NULL)
+ {
+ main_dict = PyModule_GetDict (pmodule);
+ if (main_dict != NULL)
+ {
+ PyObject *key, *value;
+ Py_ssize_t pos = 0;
+
+ // Find the current session's dictionary in the main module's dictionary.
+
+ if (PyDict_Check (main_dict))
+
+ {
+ session_dict = NULL;
+ while (PyDict_Next (main_dict, &pos, &key, &value))
+ {
+ // We have stolen references to the key and value objects in the dictionary; we need to increment
+ // them now so that Python's garbage collector doesn't collect them out from under us.
+ Py_INCREF (key);
+ Py_INCREF (value);
+ if (strcmp (PyString_AsString (key), session_dictionary_name) == 0)
+ {
+ session_dict = value;
+ break;
+ }
+ }
+ }
+
+ if (!session_dict || !PyDict_Check (session_dict))
+ return retval;
+
+ // Find the function we need to call in the current session's dictionary.
+
+ pos = 0;
+ pfunc = NULL;
+ while (PyDict_Next (session_dict, &pos, &key, &value))
+ {
+ if (PyString_Check (key))
+ {
+ // We have stolen references to the key and value objects in the dictionary; we need to increment
+ // them now so that Python's garbage collector doesn't collect them out from under us.
+ Py_INCREF (key);
+ Py_INCREF (value);
+ if (strcmp (PyString_AsString (key), python_function_name) == 0)
+ {
+ pfunc = value;
+ break;
+ }
+ }
+ }
+
+ // Set up the arguments and call the function.
+
+ if (pfunc && PyCallable_Check (pfunc))
+ {
+ pargs = PyTuple_New (2);
+ if (pargs == NULL)
+ {
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ return retval;
+ }
+
+ PyTuple_SetItem (pargs, 0, ValObj_PyObj); // This "steals" a reference to ValObj_PyObj
+ PyTuple_SetItem (pargs, 1, session_dict); // This "steals" a reference to session_dict
+ pvalue = PyObject_CallObject (pfunc, pargs);
+ Py_DECREF (pargs);
+
+ if (pvalue != NULL)
+ {
+ if (pvalue != Py_None)
+ retval = std::string(PyString_AsString(pvalue));
+ else
+ retval = "None";
+ Py_DECREF (pvalue);
+ }
+ else if (PyErr_Occurred ())
+ {
+ PyErr_Clear();
+ }
+ Py_INCREF (session_dict);
+ }
+ else if (PyErr_Occurred())
+ {
+ PyErr_Clear();
+ }
+ }
+ else if (PyErr_Occurred())
+ {
+ PyErr_Clear();
+ }
+ }
+ else if (PyErr_Occurred ())
+ {
+ PyErr_Clear ();
+ }
+ return retval;
+}
+
+
%}