[Lldb-commits] [lldb] ae47a3d - [lldb/SWIG] Refactor extensions to be non Python-specific (2/2)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 8 16:34:16 PST 2020
Author: Jonas Devlieghere
Date: 2020-01-08T16:34:09-08:00
New Revision: ae47a3d8107856c84c104f3c2e43a553f4e36748
URL: https://github.com/llvm/llvm-project/commit/ae47a3d8107856c84c104f3c2e43a553f4e36748
DIFF: https://github.com/llvm/llvm-project/commit/ae47a3d8107856c84c104f3c2e43a553f4e36748.diff
LOG: [lldb/SWIG] Refactor extensions to be non Python-specific (2/2)
The current SWIG extensions for the string conversion operator is Python
specific because it uses the PythonObjects. This means that the code
cannot be reused for other SWIG supported languages such as Lua.
This reimplements the extensions in a more generic way that can be
reused. It uses a SWIG macro to reduce code duplication.
Differential revision: https://reviews.llvm.org/D72377
Added:
lldb/scripts/macros.swig
Modified:
lldb/scripts/Python/python-extensions.swig
lldb/scripts/interface/SBAddress.i
lldb/scripts/interface/SBBlock.i
lldb/scripts/interface/SBBreakpoint.i
lldb/scripts/interface/SBBreakpointLocation.i
lldb/scripts/interface/SBBreakpointName.i
lldb/scripts/interface/SBCommandReturnObject.i
lldb/scripts/interface/SBCompileUnit.i
lldb/scripts/interface/SBData.i
lldb/scripts/interface/SBDebugger.i
lldb/scripts/interface/SBDeclaration.i
lldb/scripts/interface/SBError.i
lldb/scripts/interface/SBFileSpec.i
lldb/scripts/interface/SBFrame.i
lldb/scripts/interface/SBFunction.i
lldb/scripts/interface/SBInstruction.i
lldb/scripts/interface/SBInstructionList.i
lldb/scripts/interface/SBLineEntry.i
lldb/scripts/interface/SBMemoryRegionInfo.i
lldb/scripts/interface/SBModule.i
lldb/scripts/interface/SBModuleSpec.i
lldb/scripts/interface/SBTarget.i
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 dbd4b1d79d00..36dac19644bd 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -1,42 +1,4 @@
-%extend lldb::SBAddress {
- %nothreadallow;
- PyObject *lldb::SBAddress::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBBlock {
- %nothreadallow;
- PyObject *lldb::SBBlock::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
%extend lldb::SBBreakpoint {
- %nothreadallow;
- PyObject *lldb::SBBreakpoint::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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)):
@@ -50,34 +12,6 @@
return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
%}
-
-}
-%extend lldb::SBBreakpointLocation {
- %nothreadallow;
- PyObject *lldb::SBBreakpointLocation::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description, lldb::eDescriptionLevelFull);
- 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;
-}
-
-%extend lldb::SBBreakpointName {
- %nothreadallow;
- PyObject *lldb::SBBreakpointName::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
}
%extend lldb::SBBroadcaster {
@@ -97,18 +31,6 @@
}
%extend lldb::SBCommandReturnObject {
- %nothreadallow;
- PyObject *lldb::SBCommandReturnObject::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-
/* 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
print >>sb_command_return_object, "something"
@@ -122,18 +44,8 @@
void lldb::SBCommandReturnObject::flush ()
{}
}
+
%extend lldb::SBCompileUnit {
- %nothreadallow;
- PyObject *lldb::SBCompileUnit::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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)):
@@ -148,45 +60,8 @@
return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
%}
}
-%extend lldb::SBData {
- %nothreadallow;
- PyObject *lldb::SBData::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBDebugger {
- %nothreadallow;
- PyObject *lldb::SBDebugger::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBDeclaration {
- %nothreadallow;
- PyObject *lldb::SBDeclaration::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
+%extend lldb::SBDeclaration {
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -200,60 +75,9 @@
return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
%}
-
-}
-%extend lldb::SBError {
- %nothreadallow;
- PyObject *lldb::SBError::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBFileSpec {
- %nothreadallow;
- PyObject *lldb::SBFileSpec::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
}
-%extend lldb::SBFrame {
- %nothreadallow;
- PyObject *lldb::SBFrame::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBFunction {
- %nothreadallow;
- PyObject *lldb::SBFunction::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
+%extend lldb::SBFunction {
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -267,47 +91,9 @@
return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs)
%}
-
-}
-%extend lldb::SBInstruction {
- %nothreadallow;
- PyObject *lldb::SBInstruction::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-%extend lldb::SBInstructionList {
- %nothreadallow;
- PyObject *lldb::SBInstructionList::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
}
-%extend lldb::SBLineEntry {
- %nothreadallow;
- PyObject *lldb::SBLineEntry::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
+%extend lldb::SBLineEntry {
%pythoncode %{
def __eq__(self, rhs):
if not isinstance(rhs, type(self)):
@@ -323,33 +109,7 @@
%}
}
-%extend lldb::SBMemoryRegionInfo {
- %nothreadallow;
- PyObject *lldb::SBMemoryRegionInfo::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-
%extend lldb::SBModule {
- %nothreadallow;
- PyObject *lldb::SBModule::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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)):
@@ -365,34 +125,6 @@
%}
}
-%extend lldb::SBModuleSpec {
- %nothreadallow;
- PyObject *lldb::SBModuleSpec::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-
-%extend lldb::SBModuleSpecList {
- %nothreadallow;
- PyObject *lldb::SBModuleSpecList::__str__ (){
- lldb::SBStream description;
- $self->GetDescription (description);
- 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;
-}
-
%extend lldb::SBProcess {
%nothreadallow;
PyObject *lldb::SBProcess::__str__ (){
diff --git a/lldb/scripts/interface/SBAddress.i b/lldb/scripts/interface/SBAddress.i
index 6c5352bac6d7..4658534d153e 100644
--- a/lldb/scripts/interface/SBAddress.i
+++ b/lldb/scripts/interface/SBAddress.i
@@ -140,6 +140,8 @@ public:
lldb::SBLineEntry
GetLineEntry ();
+ STRING_EXTENSION(SBAddress)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __get_load_addr_property__ (self):
diff --git a/lldb/scripts/interface/SBBlock.i b/lldb/scripts/interface/SBBlock.i
index 73079a11760c..8bd8e37953cf 100644
--- a/lldb/scripts/interface/SBBlock.i
+++ b/lldb/scripts/interface/SBBlock.i
@@ -100,6 +100,8 @@ public:
bool locals,
bool statics);
+ STRING_EXTENSION(SBBlock)
+
#ifdef SWIGPYTHON
%pythoncode %{
def get_range_at_index(self, idx):
diff --git a/lldb/scripts/interface/SBBreakpoint.i b/lldb/scripts/interface/SBBreakpoint.i
index f84f2ada3d32..20354346be90 100644
--- a/lldb/scripts/interface/SBBreakpoint.i
+++ b/lldb/scripts/interface/SBBreakpoint.i
@@ -249,6 +249,8 @@ public:
bool
IsHardware ();
+ STRING_EXTENSION(SBBreakpoint)
+
#ifdef SWIGPYTHON
%pythoncode %{
diff --git a/lldb/scripts/interface/SBBreakpointLocation.i b/lldb/scripts/interface/SBBreakpointLocation.i
index 44fd42b514f7..dc39c83c2d67 100644
--- a/lldb/scripts/interface/SBBreakpointLocation.i
+++ b/lldb/scripts/interface/SBBreakpointLocation.i
@@ -134,6 +134,8 @@ public:
SBBreakpoint
GetBreakpoint ();
+
+ STRING_EXTENSION_LEVEL(SBBreakpointLocation, lldb::eDescriptionLevelFull)
};
} // namespace lldb
diff --git a/lldb/scripts/interface/SBBreakpointName.i b/lldb/scripts/interface/SBBreakpointName.i
index 2a06d0a2105f..e280d4224591 100644
--- a/lldb/scripts/interface/SBBreakpointName.i
+++ b/lldb/scripts/interface/SBBreakpointName.i
@@ -108,6 +108,7 @@ public:
bool GetDescription(lldb::SBStream &description);
+ STRING_EXTENSION(SBBreakpointName)
};
} // namespace lldb
diff --git a/lldb/scripts/interface/SBCommandReturnObject.i b/lldb/scripts/interface/SBCommandReturnObject.i
index 73d4001aaba5..affa16520f28 100644
--- a/lldb/scripts/interface/SBCommandReturnObject.i
+++ b/lldb/scripts/interface/SBCommandReturnObject.i
@@ -96,6 +96,8 @@ public:
void SetImmediateOutputFile(lldb::FileSP BORROWED);
void SetImmediateErrorFile(lldb::FileSP BORROWED);
+ STRING_EXTENSION(SBCommandReturnObject)
+
%extend {
// transfer_ownership does nothing, and is here for compatibility with
// old scripts. Ownership is tracked by reference count in the ordinary way.
diff --git a/lldb/scripts/interface/SBCompileUnit.i b/lldb/scripts/interface/SBCompileUnit.i
index bc2d45ae8e56..d6a4c07038c6 100644
--- a/lldb/scripts/interface/SBCompileUnit.i
+++ b/lldb/scripts/interface/SBCompileUnit.i
@@ -116,6 +116,8 @@ public:
bool
operator != (const lldb::SBCompileUnit &rhs) const;
+ STRING_EXTENSION(SBCompileUnit)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __iter__(self):
diff --git a/lldb/scripts/interface/SBData.i b/lldb/scripts/interface/SBData.i
index fdaa6962f0ec..3e74240329e0 100644
--- a/lldb/scripts/interface/SBData.i
+++ b/lldb/scripts/interface/SBData.i
@@ -134,6 +134,8 @@ public:
bool
SetDataFromDoubleArray (double* array, size_t array_len);
+ STRING_EXTENSION(SBData)
+
#ifdef SWIGPYTHON
%pythoncode %{
diff --git a/lldb/scripts/interface/SBDebugger.i b/lldb/scripts/interface/SBDebugger.i
index 52f65841893c..f2e23a7ed780 100644
--- a/lldb/scripts/interface/SBDebugger.i
+++ b/lldb/scripts/interface/SBDebugger.i
@@ -479,6 +479,8 @@ public:
lldb::SBTypeSynthetic
GetSyntheticForType (lldb::SBTypeNameSpecifier);
+ STRING_EXTENSION(SBDebugger)
+
%feature("docstring",
"Launch a command interpreter session. Commands are read from standard input or
from the input handle specified for the debugger object. Output/errors are
diff --git a/lldb/scripts/interface/SBDeclaration.i b/lldb/scripts/interface/SBDeclaration.i
index cdaec8567646..621c1a0ab7c8 100644
--- a/lldb/scripts/interface/SBDeclaration.i
+++ b/lldb/scripts/interface/SBDeclaration.i
@@ -53,6 +53,8 @@ namespace lldb {
bool
operator != (const lldb::SBDeclaration &rhs) const;
+ STRING_EXTENSION(SBDeclaration)
+
#ifdef SWIGPYTHON
%pythoncode %{
file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this line entry.''')
diff --git a/lldb/scripts/interface/SBError.i b/lldb/scripts/interface/SBError.i
index 96cd6c4886f5..ea48e2263a77 100644
--- a/lldb/scripts/interface/SBError.i
+++ b/lldb/scripts/interface/SBError.i
@@ -105,6 +105,8 @@ public:
bool
GetDescription (lldb::SBStream &description);
+ STRING_EXTENSION(SBError)
+
#ifdef SWIGPYTHON
%pythoncode %{
value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''')
diff --git a/lldb/scripts/interface/SBFileSpec.i b/lldb/scripts/interface/SBFileSpec.i
index 07a7630ebbac..d287a940c051 100644
--- a/lldb/scripts/interface/SBFileSpec.i
+++ b/lldb/scripts/interface/SBFileSpec.i
@@ -80,6 +80,8 @@ public:
void
AppendPathComponent (const char *file_or_directory);
+ STRING_EXTENSION(SBFileSpec)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __get_fullpath__(self):
diff --git a/lldb/scripts/interface/SBFrame.i b/lldb/scripts/interface/SBFrame.i
index 811f7f22f9b4..c65b88f863e7 100644
--- a/lldb/scripts/interface/SBFrame.i
+++ b/lldb/scripts/interface/SBFrame.i
@@ -285,6 +285,8 @@ public:
bool
GetDescription (lldb::SBStream &description);
+ STRING_EXTENSION(SBFrame)
+
#ifdef SWIGPYTHON
%pythoncode %{
def get_all_variables(self):
diff --git a/lldb/scripts/interface/SBFunction.i b/lldb/scripts/interface/SBFunction.i
index 7b157bb38816..630c4db22c55 100644
--- a/lldb/scripts/interface/SBFunction.i
+++ b/lldb/scripts/interface/SBFunction.i
@@ -111,6 +111,8 @@ public:
bool
operator != (const lldb::SBFunction &rhs) const;
+ STRING_EXTENSION(SBFunction)
+
#ifdef SWIGPYTHON
%pythoncode %{
def get_instructions_from_current_target (self):
diff --git a/lldb/scripts/interface/SBInstruction.i b/lldb/scripts/interface/SBInstruction.i
index 09688214630b..d50a080fd045 100644
--- a/lldb/scripts/interface/SBInstruction.i
+++ b/lldb/scripts/interface/SBInstruction.i
@@ -74,6 +74,8 @@ public:
bool
TestEmulation (lldb::SBStream &output_stream, const char *test_file);
+ STRING_EXTENSION(SBInstruction)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __mnemonic_property__ (self):
diff --git a/lldb/scripts/interface/SBInstructionList.i b/lldb/scripts/interface/SBInstructionList.i
index d50deba4f5e1..135732302757 100644
--- a/lldb/scripts/interface/SBInstructionList.i
+++ b/lldb/scripts/interface/SBInstructionList.i
@@ -66,6 +66,8 @@ public:
bool
DumpEmulationForAllInstructions (const char *triple);
+ STRING_EXTENSION(SBInstructionList)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __iter__(self):
diff --git a/lldb/scripts/interface/SBLineEntry.i b/lldb/scripts/interface/SBLineEntry.i
index 90f60df23247..be365377ba8b 100644
--- a/lldb/scripts/interface/SBLineEntry.i
+++ b/lldb/scripts/interface/SBLineEntry.i
@@ -84,6 +84,8 @@ public:
bool
operator != (const lldb::SBLineEntry &rhs) const;
+ STRING_EXTENSION(SBLineEntry)
+
#ifdef SWIGPYTHON
%pythoncode %{
file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this line entry.''')
diff --git a/lldb/scripts/interface/SBMemoryRegionInfo.i b/lldb/scripts/interface/SBMemoryRegionInfo.i
index 7a59d0051cea..6a2ad6a3e364 100644
--- a/lldb/scripts/interface/SBMemoryRegionInfo.i
+++ b/lldb/scripts/interface/SBMemoryRegionInfo.i
@@ -55,6 +55,7 @@ public:
bool
GetDescription (lldb::SBStream &description);
+ STRING_EXTENSION(SBMemoryRegionInfo)
};
} // namespace lldb
diff --git a/lldb/scripts/interface/SBModule.i b/lldb/scripts/interface/SBModule.i
index 03c8aeb2bed9..a9d9480cd7cf 100644
--- a/lldb/scripts/interface/SBModule.i
+++ b/lldb/scripts/interface/SBModule.i
@@ -344,6 +344,8 @@ public:
lldb::SBAddress
GetObjectFileEntryPointAddress() const;
+ STRING_EXTENSION(SBModule)
+
#ifdef SWIGPYTHON
%pythoncode %{
def __len__(self):
diff --git a/lldb/scripts/interface/SBModuleSpec.i b/lldb/scripts/interface/SBModuleSpec.i
index ec4e9bb7fbf7..64d0aa641a77 100644
--- a/lldb/scripts/interface/SBModuleSpec.i
+++ b/lldb/scripts/interface/SBModuleSpec.i
@@ -91,6 +91,7 @@ public:
bool
GetDescription (lldb::SBStream &description);
+ STRING_EXTENSION(SBModuleSpec)
};
@@ -127,6 +128,7 @@ public:
bool
GetDescription (lldb::SBStream &description);
+ STRING_EXTENSION(SBModuleSpecList)
};
} // namespace lldb
diff --git a/lldb/scripts/interface/SBTarget.i b/lldb/scripts/interface/SBTarget.i
index 02c70b6e1cd6..371bf5c35ebd 100644
--- a/lldb/scripts/interface/SBTarget.i
+++ b/lldb/scripts/interface/SBTarget.i
@@ -967,21 +967,7 @@ public:
lldb::SBValue
EvaluateExpression (const char *expr, const lldb::SBExpressionOptions &options);
- %extend {
- %nothreadallow;
- std::string lldb::SBTarget::__str__(){
- lldb::SBStream stream;
- $self->GetDescription (stream, lldb::eDescriptionLevelBrief);
-
- const char *desc = stream.GetData();
- size_t desc_len = stream.GetSize();
- if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
- --desc_len;
-
- return std::string(desc, desc_len);
- }
- %clearnothreadallow;
- }
+ STRING_EXTENSION_LEVEL(SBTarget, lldb::eDescriptionLevelBrief)
#ifdef SWIGPYTHON
%pythoncode %{
diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig
index c3b908332741..bebf9bf534a3 100644
--- a/lldb/scripts/lldb.swig
+++ b/lldb/scripts/lldb.swig
@@ -59,6 +59,23 @@ except ImportError:
// Parameter types will be used in the autodoc string.
%feature("autodoc", "1");
+%define ARRAYHELPER(type,name)
+%inline %{
+type *new_ ## name (int nitems) {
+ return (type *) malloc(sizeof(type)*nitems);
+}
+void delete_ ## name(type *t) {
+ free(t);
+}
+type name ## _get(type *t, int index) {
+ return t[index];
+}
+void name ## _set(type *t, int index, type val) {
+ t[index] = val;
+}
+%}
+%enddef
+
%pythoncode%{
import uuid
import re
@@ -95,6 +112,7 @@ def lldb_iter(obj, getsize, getelem):
%include <std_string.i>
%include "./Python/python-typemaps.swig"
+%include "./macros.swig"
%include "./headers.swig"
%{
diff --git a/lldb/scripts/lldb_lua.swig b/lldb/scripts/lldb_lua.swig
index bf8809015d9a..3b279a6b69e7 100644
--- a/lldb/scripts/lldb_lua.swig
+++ b/lldb/scripts/lldb_lua.swig
@@ -9,6 +9,7 @@
%module lldb
%include <std_string.i>
+%include "./macros.swig"
%include "./headers.swig"
%{
diff --git a/lldb/scripts/macros.swig b/lldb/scripts/macros.swig
new file mode 100644
index 000000000000..e0756c2f1793
--- /dev/null
+++ b/lldb/scripts/macros.swig
@@ -0,0 +1,33 @@
+%define STRING_EXTENSION_LEVEL(Class, Level)
+%extend {
+ %nothreadallow;
+ std::string lldb:: ## Class ## ::__str__(){
+ lldb::SBStream stream;
+ $self->GetDescription (stream, Level);
+ const char *desc = stream.GetData();
+ size_t desc_len = stream.GetSize();
+ if (desc_len > 0 && (desc[desc_len-1] == 'n' || desc[desc_len-1] == 'r')) {
+ --desc_len;
+ }
+ return std::string(desc, desc_len);
+ }
+ %clearnothreadallow;
+}
+%enddef
+
+%define STRING_EXTENSION(Class)
+%extend {
+ %nothreadallow;
+ std::string lldb:: ## Class ## ::__str__(){
+ lldb::SBStream stream;
+ $self->GetDescription (stream);
+ const char *desc = stream.GetData();
+ size_t desc_len = stream.GetSize();
+ if (desc_len > 0 && (desc[desc_len-1] == 'n' || desc[desc_len-1] == 'r')) {
+ --desc_len;
+ }
+ return std::string(desc, desc_len);
+ }
+ %clearnothreadallow;
+}
+%enddef
More information about the lldb-commits
mailing list