Re-land "[lldb/Lua] Add string conversion operator for SBTarget."
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 7 Jan 2020 21:23:52 +0000 (13:23 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 7 Jan 2020 21:43:40 +0000 (13:43 -0800)
Extend the SBTarget class with a string conversion operator and reuse
the same code between Python and Lua. This should happen for all the SB
classes, but I'm doing just this one as an example and for use in a test
case.

lldb/scripts/Python/python-extensions.swig
lldb/scripts/extensions.swig [new file with mode: 0644]
lldb/scripts/lldb.swig
lldb/scripts/lldb_lua.swig

index c10c32b..51b7e47 100644 (file)
 }
 
 %extend lldb::SBTarget {
-        %nothreadallow;
-        PyObject *lldb::SBTarget::__str__ (){
-                lldb::SBStream description;
-                $self->GetDescription (description, lldb::eDescriptionLevelBrief);
-                const char *desc = description.GetData();
-                size_t desc_len = description.GetSize();
-                if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
-                    --desc_len;
-                return PythonString(llvm::StringRef(desc, desc_len)).release();
-        }
-        %clearnothreadallow;
-
     %pythoncode %{
         def __eq__(self, rhs):
             if not isinstance(rhs, type(self)):
diff --git a/lldb/scripts/extensions.swig b/lldb/scripts/extensions.swig
new file mode 100644 (file)
index 0000000..974d28b
--- /dev/null
@@ -0,0 +1,10 @@
+%extend lldb::SBTarget {
+  %nothreadallow;
+  const char *lldb::SBTarget::__str__ (){
+    lldb::SBStream description;
+    $self->GetDescription (description, lldb::eDescriptionLevelBrief);
+    return description.GetData();
+  }
+  %clearnothreadallow;
+}
+
index f030116..0adfcc2 100644 (file)
@@ -95,6 +95,7 @@ def lldb_iter(obj, getsize, getelem):
 
 %include "./Python/python-typemaps.swig"
 %include "./headers.swig"
+%include "./extensions.swig"
 
 %{
 #include "../source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
index 85edeff..87f3739 100644 (file)
@@ -9,6 +9,7 @@
 %module lldb
 
 %include "./headers.swig"
+%include "./extensions.swig"
 
 %{
 using namespace lldb_private;