[Lldb-commits] [lldb] 06d122b - Re-land "[lldb/Lua] Add string conversion operator for SBTarget."

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 7 13:43:52 PST 2020


Author: Jonas Devlieghere
Date: 2020-01-07T13:43:40-08:00
New Revision: 06d122bc4236bf0d049eab72d883c98cfc2a9901

URL: https://github.com/llvm/llvm-project/commit/06d122bc4236bf0d049eab72d883c98cfc2a9901
DIFF: https://github.com/llvm/llvm-project/commit/06d122bc4236bf0d049eab72d883c98cfc2a9901.diff

LOG: Re-land "[lldb/Lua] Add string conversion operator for SBTarget."

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.

Added: 
    lldb/scripts/extensions.swig

Modified: 
    lldb/scripts/Python/python-extensions.swig
    lldb/scripts/lldb.swig
    lldb/scripts/lldb_lua.swig

Removed: 
    


################################################################################
diff  --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index c10c32b44877..51b7e4779116 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -502,18 +502,6 @@
 }
 
 %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
index 000000000000..974d28b53399
--- /dev/null
+++ b/lldb/scripts/extensions.swig
@@ -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;
+}
+

diff  --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig
index f030116b6cb8..0adfcc27d635 100644
--- a/lldb/scripts/lldb.swig
+++ b/lldb/scripts/lldb.swig
@@ -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"

diff  --git a/lldb/scripts/lldb_lua.swig b/lldb/scripts/lldb_lua.swig
index 85edefff76f2..87f37397c858 100644
--- a/lldb/scripts/lldb_lua.swig
+++ b/lldb/scripts/lldb_lua.swig
@@ -9,6 +9,7 @@
 %module lldb
 
 %include "./headers.swig"
+%include "./extensions.swig"
 
 %{
 using namespace lldb_private;


        


More information about the lldb-commits mailing list