Skip to content

Commit 0a57034

Browse files
committed
[lldb/SWIG] Guard embedded Python code in SWIG interfaces by SWIGPYTHON
Guard the embedded Python code in LLDB's interface files by the SWIGPYTHON define to ensures they can be reused for other languages supported by SWIG.
1 parent 9fdb7ac commit 0a57034

36 files changed

+82
-0
lines changed

lldb/scripts/interface/SBAddress.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ public:
6363

6464
explicit operator bool() const;
6565

66+
#ifdef SWIGPYTHON
6667
// operator== is a free function, which swig does not handle, so we inject
6768
// our own equality operator here
6869
%pythoncode%{
6970
def __eq__(self, other):
7071
return not self.__ne__(other)
7172
%}
73+
#endif
7274

7375
bool operator!=(const SBAddress &rhs) const;
7476

@@ -138,6 +140,7 @@ public:
138140
lldb::SBLineEntry
139141
GetLineEntry ();
140142

143+
#ifdef SWIGPYTHON
141144
%pythoncode %{
142145
def __get_load_addr_property__ (self):
143146
'''Get the load address for a lldb.SBAddress using the current target.'''
@@ -173,6 +176,7 @@ public:
173176
file_addr = property(GetFileAddress, None, doc='''A read only property that returns file address for the section as an integer. This is the address that represents the address as it is found in the object file that defines it.''')
174177
load_addr = property(__get_load_addr_property__, __set_load_addr_property__, doc='''A read/write property that gets/sets the SBAddress using load address. The setter resolves SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command) and not in Python based commands, or breakpoint commands.''')
175178
%}
179+
#endif
176180

177181
};
178182

lldb/scripts/interface/SBBlock.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public:
100100
bool locals,
101101
bool statics);
102102

103+
#ifdef SWIGPYTHON
103104
%pythoncode %{
104105
def get_range_at_index(self, idx):
105106
if idx < self.GetNumRanges():
@@ -153,6 +154,7 @@ public:
153154
ranges = property(get_ranges_array, None, doc='''A read only property that returns a list() object that contains all of the address ranges for the block.''')
154155
num_ranges = property(GetNumRanges, None, doc='''A read only property that returns the same result as GetNumRanges().''')
155156
%}
157+
#endif
156158

157159
};
158160

lldb/scripts/interface/SBBreakpoint.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public:
249249
bool
250250
IsHardware ();
251251

252+
#ifdef SWIGPYTHON
252253
%pythoncode %{
253254

254255
class locations_access(object):
@@ -295,6 +296,7 @@ public:
295296
one_shot = property(IsOneShot, SetOneShot, doc='''A read/write property that configures whether this breakpoint is one-shot (deleted when hit) or not.''')
296297
num_locations = property(GetNumLocations, None, doc='''A read only property that returns the count of locations of this breakpoint.''')
297298
%}
299+
#endif
298300

299301

300302
};

lldb/scripts/interface/SBCompileUnit.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public:
116116
bool
117117
operator != (const lldb::SBCompileUnit &rhs) const;
118118

119+
#ifdef SWIGPYTHON
119120
%pythoncode %{
120121
def __iter__(self):
121122
'''Iterate over all line entries in a lldb.SBCompileUnit object.'''
@@ -129,6 +130,7 @@ public:
129130
file = property(GetFileSpec, None, doc='''A read only property that returns the same result an lldb object that represents the source file (lldb.SBFileSpec) for the compile unit.''')
130131
num_line_entries = property(GetNumLineEntries, None, doc='''A read only property that returns the number of line entries in a compile unit as an integer.''')
131132
%}
133+
#endif
132134
};
133135

134136
} // namespace lldb

lldb/scripts/interface/SBData.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public:
134134
bool
135135
SetDataFromDoubleArray (double* array, size_t array_len);
136136

137+
#ifdef SWIGPYTHON
137138
%pythoncode %{
138139

139140
class read_data_helper:
@@ -287,6 +288,7 @@ public:
287288
byte_order = property(GetByteOrder, SetByteOrder, doc='''A read/write property getting and setting the endianness of this SBData (data.byte_order = lldb.eByteOrderLittle).''')
288289
size = property(GetByteSize, None, doc='''A read only property that returns the size the same result as GetByteSize().''')
289290
%}
291+
#endif
290292

291293
};
292294

lldb/scripts/interface/SBDebugger.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public:
165165
void
166166
SkipLLDBInitFiles (bool b);
167167

168+
#ifdef SWIGPYTHON
168169
%pythoncode %{
169170
def SetOutputFileHandle(self, file, transfer_ownership):
170171
"DEPRECATED, use SetOutputFile"
@@ -187,6 +188,7 @@ public:
187188
file = sys.stderr
188189
self.SetErrorFile(SBFile.Create(file, borrow=True))
189190
%}
191+
#endif
190192

191193

192194
%extend {
@@ -514,6 +516,7 @@ n_errors, quit_requested, has_crashed = debugger.RunCommandInterpreter(True,
514516
lldb::SBError
515517
RunREPL (lldb::LanguageType language, const char *repl_options);
516518

519+
#ifdef SWIGPYTHON
517520
%pythoncode%{
518521
def __iter__(self):
519522
'''Iterate over all targets in a lldb.SBDebugger object.'''
@@ -523,6 +526,7 @@ n_errors, quit_requested, has_crashed = debugger.RunCommandInterpreter(True,
523526
'''Return the number of targets in a lldb.SBDebugger object.'''
524527
return self.GetNumTargets()
525528
%}
529+
#endif
526530

527531
}; // class SBDebugger
528532

lldb/scripts/interface/SBDeclaration.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ namespace lldb {
5353
bool
5454
operator != (const lldb::SBDeclaration &rhs) const;
5555

56+
#ifdef SWIGPYTHON
5657
%pythoncode %{
5758
file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this line entry.''')
5859
line = property(GetLine, None, doc='''A read only property that returns the 1 based line number for this line entry, a return value of zero indicates that no line information is available.''')
5960
column = property(GetColumn, None, doc='''A read only property that returns the 1 based column number for this line entry, a return value of zero indicates that no column information is available.''')
6061
%}
62+
#endif
6163
};
6264

6365
} // namespace lldb

lldb/scripts/interface/SBError.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ public:
105105
bool
106106
GetDescription (lldb::SBStream &description);
107107

108+
#ifdef SWIGPYTHON
108109
%pythoncode %{
109110
value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''')
110111
fail = property(Fail, None, doc='''A read only property that returns the same result as Fail().''')
111112
success = property(Success, None, doc='''A read only property that returns the same result as Success().''')
112113
description = property(GetCString, None, doc='''A read only property that returns the same result as GetCString().''')
113114
type = property(GetType, None, doc='''A read only property that returns the same result as GetType().''')
114115
%}
116+
#endif
115117

116118
};
117119

lldb/scripts/interface/SBExecutionContext.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public:
3737
SBFrame
3838
GetFrame () const;
3939

40+
#ifdef SWIGPYTHON
4041
%pythoncode %{
4142
target = property(GetTarget, None, doc='''A read only property that returns the same result as GetTarget().''')
4243
process = property(GetProcess, None, doc='''A read only property that returns the same result as GetProcess().''')
4344
thread = property(GetThread, None, doc='''A read only property that returns the same result as GetThread().''')
4445
frame = property(GetFrame, None, doc='''A read only property that returns the same result as GetFrame().''')
4546
%}
47+
#endif
4648

4749
};
4850

lldb/scripts/interface/SBFile.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public:
3838
}
3939
}
4040

41+
#ifdef SWIGPYTHON
4142
%pythoncode {
4243
@classmethod
4344
def Create(cls, file, borrow=False, force_io_methods=False):
@@ -61,6 +62,7 @@ public:
6162
else:
6263
return cls(file)
6364
}
65+
#endif
6466

6567
~SBFile ();
6668

0 commit comments

Comments
 (0)