@@ -38,16 +38,18 @@ except ImportError:
38
38
if swift_exec is not None :
39
39
site_packages = os .path .join (os .path .dirname (swift_exec ),
40
40
'../lib/python2.7/site-packages/' )
41
- import sys
42
41
sys .path .append (site_packages )
43
42
import lldb
44
43
45
44
lldb_target = None
46
45
known_memmap = {}
46
+
47
+
47
48
def print_with_flush (buff ):
48
49
print (buff )
49
50
sys .stdout .flush ()
50
51
52
+
51
53
def process_ldd (lddoutput ):
52
54
dyn_libs = {}
53
55
for line in lddoutput .splitlines ():
@@ -73,6 +75,7 @@ def setup_lldb_target(binary, memmap):
73
75
slide = text_section .GetFileAddress () - text_section .GetFileOffset ()
74
76
lldb_target .SetModuleLoadAddress (module , memmap [dynlib_path ] - slide )
75
77
78
+
76
79
def check_base_address (dynlib_path , dynlib_baseaddr , memmap ):
77
80
global known_memmap
78
81
if dynlib_path in memmap or dynlib_path in known_memmap :
@@ -87,6 +90,7 @@ def check_base_address(dynlib_path, dynlib_baseaddr, memmap):
87
90
dynlib_path , existing_baseaddr , dynlib_baseaddr )
88
91
raise Exception (error_msg )
89
92
93
+
90
94
def symbolicate_one (frame_addr , frame_idx , dynlib_fname ):
91
95
global lldb_target
92
96
so_addr = lldb_target .ResolveLoadAddress (frame_addr - 1 )
@@ -110,6 +114,7 @@ def symbolicate_one(frame_addr, frame_idx, dynlib_fname):
110
114
return "{0:s} {1:s} {2:s}" .format (
111
115
frame_fragment , symbol_fragment , line_fragment )
112
116
117
+
113
118
def get_processed_stack (binary , dyn_libs , stack ):
114
119
global lldb_target
115
120
global known_memmap
@@ -158,39 +163,57 @@ def get_processed_stack(binary, dyn_libs, stack):
158
163
159
164
return processed_stack
160
165
166
+
161
167
def is_fatal_error (line ):
162
168
return line .startswith ("Fatal error:" )
163
169
170
+
164
171
def is_stack_trace_header (line ):
165
172
return line .startswith ("Current stack trace:" )
166
173
174
+
167
175
def should_print_previous_line (current_line , previous_line ):
168
- return is_fatal_error (previous_line ) and not is_stack_trace_header (current_line )
176
+ return is_fatal_error (previous_line ) and \
177
+ not is_stack_trace_header (current_line )
178
+
169
179
170
180
def should_print_current_line (current_line , previous_line ):
171
- return (not is_fatal_error (current_line ) and not is_stack_trace_header (current_line )) or (is_stack_trace_header (current_line ) and not is_fatal_error (previous_line ))
181
+ return (not is_fatal_error (current_line ) and
182
+ not is_stack_trace_header (current_line )) or \
183
+ (is_stack_trace_header (current_line ) and
184
+ not is_fatal_error (previous_line ))
185
+
172
186
173
187
def fatal_error_with_stack_trace_found (current_line , previous_line ):
174
- return is_stack_trace_header (current_line ) and is_fatal_error (previous_line )
188
+ return is_stack_trace_header (current_line ) and \
189
+ is_fatal_error (previous_line )
175
190
176
- def print_stack (fatal_error_header , fatal_error_stack_trace_header , fatal_log_format , processed_stack ):
191
+
192
+ def print_stack (fatal_error_header ,
193
+ fatal_error_stack_trace_header ,
194
+ fatal_log_format ,
195
+ processed_stack ):
177
196
if not fatal_error_header :
178
197
for line in processed_stack :
179
198
print_with_flush (line )
180
199
else :
181
- #fatal error with a stack trace
182
- stack_str = fatal_error_header + fatal_error_stack_trace_header + '\n ' .join (processed_stack )
200
+ # fatal error with a stack trace
201
+ stack_str = fatal_error_header + fatal_error_stack_trace_header + \
202
+ '\n ' .join (processed_stack )
183
203
formatted_output = fatal_log_format
184
204
185
205
if "%t" in formatted_output :
186
206
current_time = datetime .datetime .now ()
187
- time_in_iso_format = current_time .strftime ('%Y-%m-%dT%H:%M:%S,%f%z' )
188
- formatted_output = formatted_output .replace ("%t" , time_in_iso_format )
207
+ time_in_iso_format = \
208
+ current_time .strftime ('%Y-%m-%dT%H:%M:%S,%f%z' )
209
+ formatted_output = \
210
+ formatted_output .replace ("%t" , time_in_iso_format )
189
211
if "%m" in formatted_output :
190
212
formatted_output = formatted_output .replace ("%m" , stack_str )
191
213
192
214
print_with_flush (formatted_output )
193
215
216
+
194
217
def main ():
195
218
parser = argparse .ArgumentParser (
196
219
formatter_class = argparse .RawDescriptionHelpFormatter ,
@@ -202,7 +225,10 @@ def main():
202
225
help = "Log file for symbolication. Defaults to stdin." )
203
226
parser .add_argument (
204
227
"--fatal-log-format" , default = "%m" ,
205
- help = "Format for logging fatal errors. Variable %%t will be replaced with current time in ISO 8601 format, variable %%m will be replaced with the error message with a full stack trace." )
228
+ help = "Format for logging fatal errors. Variable %%t will be "
229
+ "replaced with current time in ISO 8601 format, variable "
230
+ "%%m will be replaced with the error message with a full "
231
+ "stack trace." )
206
232
args = parser .parse_args ()
207
233
208
234
binary = args .binary
@@ -228,7 +254,10 @@ def main():
228
254
stackidx = stackidx + 1
229
255
else :
230
256
processed_stack = get_processed_stack (binary , dyn_libs , stack )
231
- print_stack (fatal_error_header , fatal_error_stack_trace_header , fatal_log_format , processed_stack )
257
+ print_stack (fatal_error_header ,
258
+ fatal_error_stack_trace_header ,
259
+ fatal_log_format ,
260
+ processed_stack )
232
261
233
262
instack = False
234
263
stackidx = 0
@@ -253,7 +282,11 @@ def main():
253
282
if is_fatal_error (previous_line ):
254
283
print_with_flush (previous_line .rstrip ())
255
284
processed_stack = get_processed_stack (binary , dyn_libs , stack )
256
- print_stack (fatal_error_header , fatal_error_stack_trace_header , fatal_log_format , processed_stack )
285
+ print_stack (fatal_error_header ,
286
+ fatal_error_stack_trace_header ,
287
+ fatal_log_format ,
288
+ processed_stack )
289
+
257
290
258
291
if __name__ == '__main__' :
259
292
main ()
0 commit comments