blob: c5cbab05de1c7dd4087e64bb2e71166d1d529cf8 [file] [log] [blame]
Johnny Chen14097802011-04-28 21:31:18 +00001#
Johnny Chend7e04d92011-08-05 20:17:27 +00002# modify-python-lldb.py
Johnny Chen14097802011-04-28 21:31:18 +00003#
4# This script modifies the lldb module (which was automatically generated via
Johnny Chen22e418a2011-04-29 19:22:24 +00005# running swig) to support iteration and/or equality operations for certain lldb
Johnny Chene5637d22011-05-24 21:05:16 +00006# objects, implements truth value testing for certain lldb objects, and adds a
7# global variable 'debugger_unique_id' which is initialized to 0.
Johnny Chen14097802011-04-28 21:31:18 +00008#
Johnny Chen09e0a422011-07-01 22:14:07 +00009# As a cleanup step, it also removes the 'residues' from the autodoc features of
10# swig. For an example, take a look at SBTarget.h header file, where we take
Johnny Chen2c77fa42011-07-02 20:01:09 +000011# advantage of the already existing doxygen C++-docblock and make it the Python
Johnny Chen09e0a422011-07-01 22:14:07 +000012# docstring for the same method. The 'residues' in this context include the
Johnny Chenf6ce70a2011-07-03 19:55:50 +000013# '#endif', the '#ifdef SWIG', the c comment marker, the trailing blank (SPC's)
14# line, and the doxygen comment start marker.
Johnny Chen09e0a422011-07-01 22:14:07 +000015#
Johnny Chen37811372011-07-06 21:55:45 +000016# In addition to the 'residues' removal during the cleanup step, it also
17# transforms the 'char' data type (which was actually 'char *' but the 'autodoc'
18# feature of swig removes ' *' from it into 'str' (as a Python str type).
19#
Johnny Chen14097802011-04-28 21:31:18 +000020# It also calls SBDebugger.Initialize() to initialize the lldb debugger
21# subsystem.
22#
23
24import sys, re, StringIO
25
26if len (sys.argv) != 2:
27 output_name = "./lldb.py"
28else:
29 output_name = sys.argv[1] + "/lldb.py"
30
31# print "output_name is '" + output_name + "'"
32
Johnny Chen37811372011-07-06 21:55:45 +000033#
Johnny Chen09e0a422011-07-01 22:14:07 +000034# Residues to be removed.
Johnny Chen37811372011-07-06 21:55:45 +000035#
Johnny Chen09e0a422011-07-01 22:14:07 +000036c_endif_swig = "#endif"
37c_ifdef_swig = "#ifdef SWIG"
Johnny Chen2c77fa42011-07-02 20:01:09 +000038c_comment_marker = "//------------"
39# The pattern for recognizing the doxygen comment block line.
Johnny Chenebd63b22011-07-16 21:15:39 +000040doxygen_comment_start = re.compile("^\s*(/// ?)")
Johnny Chenf6ce70a2011-07-03 19:55:50 +000041# The demarcation point for turning on/off residue removal state.
42# When bracketed by the lines, the CLEANUP_DOCSTRING state (see below) is ON.
43toggle_docstring_cleanup_line = ' """'
Johnny Chen09e0a422011-07-01 22:14:07 +000044
Johnny Chen37811372011-07-06 21:55:45 +000045def char_to_str_xform(line):
46 """This transforms the 'char', i.e, 'char *' to 'str', Python string."""
47 line = line.replace(' char', ' str')
48 line = line.replace('char ', 'str ')
Johnny Chen2de7ce62011-07-14 00:17:49 +000049 # Special case handling of 'char **argv' and 'char **envp'.
50 line = line.replace('str argv', 'list argv')
51 line = line.replace('str envp', 'list envp')
Johnny Chen37811372011-07-06 21:55:45 +000052 return line
53
54#
55# The one-liner docstring also needs char_to_str transformation, btw.
56#
Johnny Chen21c0fd12011-07-08 23:57:20 +000057TWO_SPACES = ' ' * 2
58EIGHT_SPACES = ' ' * 8
59one_liner_docstring_pattern = re.compile('^(%s|%s)""".*"""$' % (TWO_SPACES, EIGHT_SPACES))
Johnny Chen37811372011-07-06 21:55:45 +000060
Johnny Chen14097802011-04-28 21:31:18 +000061#
Johnny Chenbf338e62011-09-30 00:42:49 +000062# lldb_helpers and lldb_iter() should appear before our first SB* class definition.
Johnny Chen14097802011-04-28 21:31:18 +000063#
Johnny Chenbf338e62011-09-30 00:42:49 +000064lldb_helpers = '''
65def in_range(symbol, section):
Johnny Chenf11c0292011-09-30 00:49:02 +000066 """Test whether a symbol is within the range of a section."""
Johnny Chenbf338e62011-09-30 00:42:49 +000067 symSA = symbol.GetStartAddress().GetFileAddress()
68 symEA = symbol.GetEndAddress().GetFileAddress()
69 secSA = section.GetFileAddress()
70 secEA = secSA + section.GetByteSize()
71
72 if symEA != LLDB_INVALID_ADDRESS:
73 if secSA <= symSA and symEA <= secEA:
74 return True
75 else:
76 return False
77 else:
78 if secSA <= symSA and symSA < secEA:
79 return True
80 else:
81 return False
82'''
83
Johnny Chen14097802011-04-28 21:31:18 +000084lldb_iter_def = '''
85# ===================================
86# Iterator for lldb container objects
87# ===================================
88def lldb_iter(obj, getsize, getelem):
89 """A generator adaptor to support iteration for lldb container objects."""
90 size = getattr(obj, getsize)
91 elem = getattr(obj, getelem)
92 for i in range(size()):
93 yield elem(i)
94
Johnny Chen81422202011-06-01 19:21:08 +000095# ==============================================================================
96# The modify-python-lldb.py script is responsible for post-processing this SWIG-
97# generated lldb.py module. It is responsible for adding the above lldb_iter()
98# function definition as well as the supports, in the following, for iteration
99# protocol: __iter__, rich comparison methods: __eq__ and __ne__, truth value
100# testing (and built-in operation bool()): __nonzero__, and built-in function
101# len(): __len__.
102# ==============================================================================
Johnny Chen14097802011-04-28 21:31:18 +0000103'''
104
Johnny Chenfbebbc92011-07-25 19:32:35 +0000105#
Johnny Chende856cc2011-07-25 23:41:08 +0000106# linked_list_iter() is a special purpose iterator to treat the SBValue as the
107# head of a list data structure, where you specify the child member name which
108# points to the next item on the list and you specify the end-of-list function
109# which takes an SBValue and returns True if EOL is reached and False if not.
Johnny Chenfbebbc92011-07-25 19:32:35 +0000110#
111linked_list_iter_def = '''
Johnny Chena4673e12011-07-26 20:57:10 +0000112 def __eol_test__(val):
113 """Default function for end of list test takes an SBValue object.
114
115 Return True if val is invalid or it corresponds to a null pointer.
116 Otherwise, return False.
117 """
Johnny Chend96c9e82011-08-11 00:49:03 +0000118 if not val or val.GetValueAsUnsigned() == 0:
Johnny Chena4673e12011-07-26 20:57:10 +0000119 return True
120 else:
121 return False
122
Johnny Chenfbebbc92011-07-25 19:32:35 +0000123 # ==================================================
124 # Iterator for lldb.SBValue treated as a linked list
125 # ==================================================
Johnny Chena4673e12011-07-26 20:57:10 +0000126 def linked_list_iter(self, next_item_name, end_of_list_test=__eol_test__):
Johnny Chende856cc2011-07-25 23:41:08 +0000127 """Generator adaptor to support iteration for SBValue as a linked list.
128
129 linked_list_iter() is a special purpose iterator to treat the SBValue as
130 the head of a list data structure, where you specify the child member
131 name which points to the next item on the list and you specify the
132 end-of-list test function which takes an SBValue for an item and returns
133 True if EOL is reached and False if not.
Johnny Chenfbebbc92011-07-25 19:32:35 +0000134
Johnny Chen758db962011-08-11 01:19:46 +0000135 linked_list_iter() also detects infinite loop and bails out early.
136
Johnny Chena4673e12011-07-26 20:57:10 +0000137 The end_of_list_test arg, if omitted, defaults to the __eol_test__
138 function above.
139
Johnny Chenfbebbc92011-07-25 19:32:35 +0000140 For example,
141
Johnny Chenfbebbc92011-07-25 19:32:35 +0000142 # Get Frame #0.
143 ...
144
145 # Get variable 'task_head'.
146 task_head = frame0.FindVariable('task_head')
147 ...
148
Johnny Chena4673e12011-07-26 20:57:10 +0000149 for t in task_head.linked_list_iter('next'):
Johnny Chenfbebbc92011-07-25 19:32:35 +0000150 print t
151 """
Johnny Chend96c9e82011-08-11 00:49:03 +0000152 if end_of_list_test(self):
153 return
154 item = self
Johnny Chen758db962011-08-11 01:19:46 +0000155 visited = set()
Johnny Chenfbebbc92011-07-25 19:32:35 +0000156 try:
Johnny Chen758db962011-08-11 01:19:46 +0000157 while not end_of_list_test(item) and not item.GetValueAsUnsigned() in visited:
158 visited.add(item.GetValueAsUnsigned())
Johnny Chenfbebbc92011-07-25 19:32:35 +0000159 yield item
160 # Prepare for the next iteration.
161 item = item.GetChildMemberWithName(next_item_name)
Johnny Chenfbebbc92011-07-25 19:32:35 +0000162 except:
163 # Exception occurred. Stop the generator.
164 pass
165
166 return
167'''
168
Johnny Chen14097802011-04-28 21:31:18 +0000169# This supports the iteration protocol.
Johnny Chen14097802011-04-28 21:31:18 +0000170iter_def = " def __iter__(self): return lldb_iter(self, '%s', '%s')"
171module_iter = " def module_iter(self): return lldb_iter(self, '%s', '%s')"
172breakpoint_iter = " def breakpoint_iter(self): return lldb_iter(self, '%s', '%s')"
Johnny Chen092bd152011-09-27 01:19:20 +0000173watchpoint_location_iter = " def watchpoint_location_iter(self): return lldb_iter(self, '%s', '%s')"
Johnny Chendc0cbd12011-09-24 04:51:43 +0000174section_iter = " def section_iter(self): return lldb_iter(self, '%s', '%s')"
Johnny Chen2077f0d2011-05-17 22:14:39 +0000175
Johnny Chena79a21c2011-05-16 20:31:18 +0000176# Called to implement the built-in function len().
177# Eligible objects are those containers with unambiguous iteration support.
Johnny Chena79a21c2011-05-16 20:31:18 +0000178len_def = " def __len__(self): return self.%s()"
Johnny Chen2077f0d2011-05-17 22:14:39 +0000179
Johnny Chen3a3d6592011-04-29 19:03:02 +0000180# This supports the rich comparison methods of __eq__ and __ne__.
Johnny Chen7616cb92011-05-02 19:05:52 +0000181eq_def = " def __eq__(self, other): return isinstance(other, %s) and %s"
Johnny Chen3a3d6592011-04-29 19:03:02 +0000182ne_def = " def __ne__(self, other): return not self.__eq__(other)"
Johnny Chen14097802011-04-28 21:31:18 +0000183
Johnny Chen2077f0d2011-05-17 22:14:39 +0000184# Called to implement truth value testing and the built-in operation bool();
185# should return False or True, or their integer equivalents 0 or 1.
186# Delegate to self.IsValid() if it is defined for the current lldb object.
187nonzero_def = " def __nonzero__(self): return self.IsValid()"
188
Johnny Chenbf338e62011-09-30 00:42:49 +0000189# A convenience iterator for SBSymbol!
190symbol_in_section_iter_def = '''
191 def symbol_in_section_iter(self, section):
192 """Given a module and its contained section, returns an iterator on the
193 symbols within the section."""
194 for sym in self:
195 if in_range(sym, section):
196 yield sym
197'''
198
Johnny Chen14097802011-04-28 21:31:18 +0000199#
Johnny Chena6303ef2011-05-24 22:53:03 +0000200# This dictionary defines a mapping from classname to (getsize, getelem) tuple.
Johnny Chen14097802011-04-28 21:31:18 +0000201#
202d = { 'SBBreakpoint': ('GetNumLocations', 'GetLocationAtIndex'),
203 'SBCompileUnit': ('GetNumLineEntries', 'GetLineEntryAtIndex'),
204 'SBDebugger': ('GetNumTargets', 'GetTargetAtIndex'),
205 'SBModule': ('GetNumSymbols', 'GetSymbolAtIndex'),
206 'SBProcess': ('GetNumThreads', 'GetThreadAtIndex'),
Johnny Chendc0cbd12011-09-24 04:51:43 +0000207 'SBSection': ('GetNumSubSections', 'GetSubSectionAtIndex'),
Johnny Chen14097802011-04-28 21:31:18 +0000208 'SBThread': ('GetNumFrames', 'GetFrameAtIndex'),
209
210 'SBInstructionList': ('GetSize', 'GetInstructionAtIndex'),
211 'SBStringList': ('GetSize', 'GetStringAtIndex',),
212 'SBSymbolContextList': ('GetSize', 'GetContextAtIndex'),
Johnny Chen3ee85202011-08-05 01:35:49 +0000213 'SBTypeList': ('GetSize', 'GetTypeAtIndex'),
214 'SBValueList': ('GetSize', 'GetValueAtIndex'),
Johnny Chen14097802011-04-28 21:31:18 +0000215
216 'SBType': ('GetNumberChildren', 'GetChildAtIndex'),
217 'SBValue': ('GetNumChildren', 'GetChildAtIndex'),
218
Johnny Chen08477f52011-05-24 22:57:42 +0000219 # SBTarget needs special processing, see below.
Johnny Chen14097802011-04-28 21:31:18 +0000220 'SBTarget': {'module': ('GetNumModules', 'GetModuleAtIndex'),
Johnny Chen092bd152011-09-27 01:19:20 +0000221 'breakpoint': ('GetNumBreakpoints', 'GetBreakpointAtIndex'),
222 'watchpoint_location': ('GetNumWatchpointLocations', 'GetWatchpointLocationAtIndex')
Johnny Chendc0cbd12011-09-24 04:51:43 +0000223 },
224
225 # SBModule has an additional section_iter(), see below.
Johnny Chenbf338e62011-09-30 00:42:49 +0000226 'SBModule-section': ('GetNumSections', 'GetSectionAtIndex'),
227 # As well as symbol_in_section_iter().
228 'SBModule-symbol-in-section': symbol_in_section_iter_def
Johnny Chen14097802011-04-28 21:31:18 +0000229 }
230
Johnny Chen3a3d6592011-04-29 19:03:02 +0000231#
Johnny Chen7616cb92011-05-02 19:05:52 +0000232# This dictionary defines a mapping from classname to equality method name(s).
Johnny Chen3a3d6592011-04-29 19:03:02 +0000233#
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000234e = { 'SBAddress': ['GetFileAddress', 'GetModule'],
235 'SBBreakpoint': ['GetID'],
236 'SBWatchpointLocation': ['GetID'],
237 'SBFileSpec': ['GetFilename', 'GetDirectory'],
238 'SBModule': ['GetFileSpec', 'GetUUIDString'],
239 'SBType': ['GetByteSize', 'GetName']
Johnny Chen7616cb92011-05-02 19:05:52 +0000240 }
241
242def list_to_frag(list):
243 """Transform a list to equality program fragment.
244
245 For example, ['GetID'] is transformed to 'self.GetID() == other.GetID()',
246 and ['GetFilename', 'GetDirectory'] to 'self.GetFilename() == other.GetFilename()
247 and self.GetDirectory() == other.GetDirectory()'.
248 """
249 if not list:
250 raise Exception("list should be non-empty")
251 frag = StringIO.StringIO()
252 for i in range(len(list)):
253 if i > 0:
254 frag.write(" and ")
255 frag.write("self.{0}() == other.{0}()".format(list[i]))
256 return frag.getvalue()
Johnny Chen3a3d6592011-04-29 19:03:02 +0000257
Johnny Chenebd63b22011-07-16 21:15:39 +0000258class NewContent(StringIO.StringIO):
259 """Simple facade to keep track of the previous line to be committed."""
260 def __init__(self):
261 StringIO.StringIO.__init__(self)
262 self.prev_line = None
263 def add_line(self, a_line):
264 """Add a line to the content, if there is a previous line, commit it."""
265 if self.prev_line != None:
266 print >> self, self.prev_line
267 self.prev_line = a_line
268 def del_line(self):
269 """Forget about the previous line, do not commit it."""
270 self.prev_line = None
271 def del_blank_line(self):
272 """Forget about the previous line if it is a blank line."""
273 if self.prev_line != None and not self.prev_line.strip():
274 self.prev_line = None
275 def finish(self):
276 """Call this when you're finished with populating content."""
277 if self.prev_line != None:
278 print >> self, self.prev_line
279 self.prev_line = None
280
Johnny Chen14097802011-04-28 21:31:18 +0000281# The new content will have the iteration protocol defined for our lldb objects.
Johnny Chenebd63b22011-07-16 21:15:39 +0000282new_content = NewContent()
Johnny Chen14097802011-04-28 21:31:18 +0000283
284with open(output_name, 'r') as f_in:
285 content = f_in.read()
286
287# The pattern for recognizing the beginning of an SB class definition.
288class_pattern = re.compile("^class (SB.*)\(_object\):$")
289
290# The pattern for recognizing the beginning of the __init__ method definition.
Johnny Chen3ee85202011-08-05 01:35:49 +0000291init_pattern = re.compile("^ def __init__\(self.*\):")
Johnny Chen14097802011-04-28 21:31:18 +0000292
Johnny Chen2077f0d2011-05-17 22:14:39 +0000293# The pattern for recognizing the beginning of the IsValid method definition.
Peter Collingbournef2084532011-06-14 03:55:41 +0000294isvalid_pattern = re.compile("^ def IsValid\(")
Johnny Chen2077f0d2011-05-17 22:14:39 +0000295
Johnny Chena79a21c2011-05-16 20:31:18 +0000296# These define the states of our finite state machine.
Johnny Chen14097802011-04-28 21:31:18 +0000297NORMAL = 0
298DEFINING_ITERATOR = 1
Johnny Chen3a3d6592011-04-29 19:03:02 +0000299DEFINING_EQUALITY = 2
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000300CLEANUP_DOCSTRING = 4
Johnny Chen14097802011-04-28 21:31:18 +0000301
302# The lldb_iter_def only needs to be inserted once.
303lldb_iter_defined = False;
304
Johnny Chen2077f0d2011-05-17 22:14:39 +0000305# Our FSM begins its life in the NORMAL state, and transitions to the
306# DEFINING_ITERATOR and/or DEFINING_EQUALITY state whenever it encounters the
307# beginning of certain class definitions, see dictionaries 'd' and 'e' above.
308#
309# Note that the two states DEFINING_ITERATOR and DEFINING_EQUALITY are
310# orthogonal in that our FSM can be in one, the other, or both states at the
311# same time. During such time, the FSM is eagerly searching for the __init__
312# method definition in order to insert the appropriate method(s) into the lldb
313# module.
314#
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000315# The state CLEANUP_DOCSTRING can be entered from either the NORMAL or the
316# DEFINING_ITERATOR/EQUALITY states. While in this state, the FSM is fixing/
317# cleaning the Python docstrings generated by the swig docstring features.
318#
Johnny Chenb72d1772011-05-24 22:29:49 +0000319# The FSM, in all possible states, also checks the current input for IsValid()
320# definition, and inserts a __nonzero__() method definition to implement truth
321# value testing and the built-in operation bool().
Johnny Chen14097802011-04-28 21:31:18 +0000322state = NORMAL
323for line in content.splitlines():
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000324 # Handle the state transition into CLEANUP_DOCSTRING state as it is possible
325 # to enter this state from either NORMAL or DEFINING_ITERATOR/EQUALITY.
326 #
327 # If ' """' is the sole line, prepare to transition to the
328 # CLEANUP_DOCSTRING state or out of it.
329 if line == toggle_docstring_cleanup_line:
330 if state & CLEANUP_DOCSTRING:
Johnny Chenebd63b22011-07-16 21:15:39 +0000331 # Special handling of the trailing blank line right before the '"""'
332 # end docstring marker.
333 new_content.del_blank_line()
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000334 state ^= CLEANUP_DOCSTRING
335 else:
336 state |= CLEANUP_DOCSTRING
Johnny Chen09e0a422011-07-01 22:14:07 +0000337
Johnny Chen14097802011-04-28 21:31:18 +0000338 if state == NORMAL:
339 match = class_pattern.search(line)
Johnny Chenbf338e62011-09-30 00:42:49 +0000340 # Inserts lldb_helpers and the lldb_iter() definition before the first
341 # class definition.
Johnny Chen14097802011-04-28 21:31:18 +0000342 if not lldb_iter_defined and match:
Johnny Chenbf338e62011-09-30 00:42:49 +0000343 new_content.add_line(lldb_helpers)
Johnny Chenebd63b22011-07-16 21:15:39 +0000344 new_content.add_line(lldb_iter_def)
Johnny Chen14097802011-04-28 21:31:18 +0000345 lldb_iter_defined = True
Johnny Chen2077f0d2011-05-17 22:14:39 +0000346
347 # If we are at the beginning of the class definitions, prepare to
348 # transition to the DEFINING_ITERATOR/DEFINING_EQUALITY state for the
349 # right class names.
Johnny Chen3a3d6592011-04-29 19:03:02 +0000350 if match:
Johnny Chen14097802011-04-28 21:31:18 +0000351 cls = match.group(1)
Johnny Chen3a3d6592011-04-29 19:03:02 +0000352 if cls in d:
353 # Adding support for iteration for the matched SB class.
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000354 state |= DEFINING_ITERATOR
Johnny Chen3a3d6592011-04-29 19:03:02 +0000355 if cls in e:
356 # Adding support for eq and ne for the matched SB class.
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000357 state |= DEFINING_EQUALITY
358
Johnny Chen533ed2f2011-07-15 20:46:19 +0000359 if (state & DEFINING_ITERATOR) or (state & DEFINING_EQUALITY):
Johnny Chen14097802011-04-28 21:31:18 +0000360 match = init_pattern.search(line)
361 if match:
362 # We found the beginning of the __init__ method definition.
Johnny Chen3a3d6592011-04-29 19:03:02 +0000363 # This is a good spot to insert the iter and/or eq-ne support.
Johnny Chen14097802011-04-28 21:31:18 +0000364 #
Johnny Chen092bd152011-09-27 01:19:20 +0000365 # But note that SBTarget has three types of iterations.
Johnny Chen14097802011-04-28 21:31:18 +0000366 if cls == "SBTarget":
Johnny Chenebd63b22011-07-16 21:15:39 +0000367 new_content.add_line(module_iter % (d[cls]['module']))
368 new_content.add_line(breakpoint_iter % (d[cls]['breakpoint']))
Johnny Chen092bd152011-09-27 01:19:20 +0000369 new_content.add_line(watchpoint_location_iter % (d[cls]['watchpoint_location']))
Johnny Chen14097802011-04-28 21:31:18 +0000370 else:
Johnny Chen3a3d6592011-04-29 19:03:02 +0000371 if (state & DEFINING_ITERATOR):
Johnny Chenebd63b22011-07-16 21:15:39 +0000372 new_content.add_line(iter_def % d[cls])
373 new_content.add_line(len_def % d[cls][0])
Johnny Chen3a3d6592011-04-29 19:03:02 +0000374 if (state & DEFINING_EQUALITY):
Johnny Chenebd63b22011-07-16 21:15:39 +0000375 new_content.add_line(eq_def % (cls, list_to_frag(e[cls])))
376 new_content.add_line(ne_def)
Johnny Chena2f86e82011-04-29 19:19:13 +0000377
Johnny Chenbf338e62011-09-30 00:42:49 +0000378 # SBModule has an extra SBSection iterator and symbol_in_section_iter()!
Johnny Chendc0cbd12011-09-24 04:51:43 +0000379 if cls == "SBModule":
Johnny Chenbf338e62011-09-30 00:42:49 +0000380 new_content.add_line(section_iter % d[cls+'-section'])
381 new_content.add_line(d[cls+'-symbol-in-section'])
382
Johnny Chenfbebbc92011-07-25 19:32:35 +0000383 # This special purpose iterator is for SBValue only!!!
384 if cls == "SBValue":
385 new_content.add_line(linked_list_iter_def)
386
Johnny Chena2f86e82011-04-29 19:19:13 +0000387 # Next state will be NORMAL.
388 state = NORMAL
Johnny Chen14097802011-04-28 21:31:18 +0000389
Johnny Chen533ed2f2011-07-15 20:46:19 +0000390 if (state & CLEANUP_DOCSTRING):
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000391 # Cleanse the lldb.py of the autodoc'ed residues.
392 if c_ifdef_swig in line or c_endif_swig in line:
393 continue
Johnny Chenebd63b22011-07-16 21:15:39 +0000394 # As well as the comment marker line.
395 if c_comment_marker in line:
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000396 continue
Johnny Chenebd63b22011-07-16 21:15:39 +0000397
Johnny Chen533ed2f2011-07-15 20:46:19 +0000398 # Also remove the '\a ' and '\b 'substrings.
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000399 line = line.replace('\a ', '')
Johnny Chen533ed2f2011-07-15 20:46:19 +0000400 line = line.replace('\b ', '')
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000401 # And the leading '///' substring.
402 doxygen_comment_match = doxygen_comment_start.match(line)
403 if doxygen_comment_match:
404 line = line.replace(doxygen_comment_match.group(1), '', 1)
405
Johnny Chen37811372011-07-06 21:55:45 +0000406 line = char_to_str_xform(line)
407
Johnny Chenf6ce70a2011-07-03 19:55:50 +0000408 # Note that the transition out of CLEANUP_DOCSTRING is handled at the
409 # beginning of this function already.
410
Johnny Chen37811372011-07-06 21:55:45 +0000411 # This deals with one-liner docstring, for example, SBThread.GetName:
412 # """GetName(self) -> char""".
413 if one_liner_docstring_pattern.match(line):
414 line = char_to_str_xform(line)
415
Johnny Chenb72d1772011-05-24 22:29:49 +0000416 # Look for 'def IsValid(*args):', and once located, add implementation
417 # of truth value testing for this object by delegation.
418 if isvalid_pattern.search(line):
Johnny Chenebd63b22011-07-16 21:15:39 +0000419 new_content.add_line(nonzero_def)
Johnny Chenb72d1772011-05-24 22:29:49 +0000420
Johnny Chen6ea16c72011-05-02 17:53:04 +0000421 # Pass the original line of content to new_content.
Johnny Chenebd63b22011-07-16 21:15:39 +0000422 new_content.add_line(line)
423
424# We are finished with recording new content.
425new_content.finish()
426
Johnny Chen14097802011-04-28 21:31:18 +0000427with open(output_name, 'w') as f_out:
428 f_out.write(new_content.getvalue())
429 f_out.write("debugger_unique_id = 0\n")
430 f_out.write("SBDebugger.Initialize()\n")