Skip to content

Commit 820d5f3

Browse files
committed
Syntactic changes to satisfy linter on symbolicate-linux-fatal
1 parent eb06d8e commit 820d5f3

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

utils/symbolicate-linux-fatal

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ except ImportError:
3838
if swift_exec is not None:
3939
site_packages = os.path.join(os.path.dirname(swift_exec),
4040
'../lib/python2.7/site-packages/')
41-
import sys
4241
sys.path.append(site_packages)
4342
import lldb
4443

4544
lldb_target = None
4645
known_memmap = {}
46+
47+
4748
def print_with_flush(buff):
4849
print(buff)
4950
sys.stdout.flush()
5051

52+
5153
def process_ldd(lddoutput):
5254
dyn_libs = {}
5355
for line in lddoutput.splitlines():
@@ -73,6 +75,7 @@ def setup_lldb_target(binary, memmap):
7375
slide = text_section.GetFileAddress() - text_section.GetFileOffset()
7476
lldb_target.SetModuleLoadAddress(module, memmap[dynlib_path] - slide)
7577

78+
7679
def check_base_address(dynlib_path, dynlib_baseaddr, memmap):
7780
global known_memmap
7881
if dynlib_path in memmap or dynlib_path in known_memmap:
@@ -87,6 +90,7 @@ def check_base_address(dynlib_path, dynlib_baseaddr, memmap):
8790
dynlib_path, existing_baseaddr, dynlib_baseaddr)
8891
raise Exception(error_msg)
8992

93+
9094
def symbolicate_one(frame_addr, frame_idx, dynlib_fname):
9195
global lldb_target
9296
so_addr = lldb_target.ResolveLoadAddress(frame_addr - 1)
@@ -110,6 +114,7 @@ def symbolicate_one(frame_addr, frame_idx, dynlib_fname):
110114
return "{0:s} {1:s} {2:s}".format(
111115
frame_fragment, symbol_fragment, line_fragment)
112116

117+
113118
def get_processed_stack(binary, dyn_libs, stack):
114119
global lldb_target
115120
global known_memmap
@@ -158,39 +163,57 @@ def get_processed_stack(binary, dyn_libs, stack):
158163

159164
return processed_stack
160165

166+
161167
def is_fatal_error(line):
162168
return line.startswith("Fatal error:")
163169

170+
164171
def is_stack_trace_header(line):
165172
return line.startswith("Current stack trace:")
166173

174+
167175
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+
169179

170180
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+
172186

173187
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)
175190

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):
177196
if not fatal_error_header:
178197
for line in processed_stack:
179198
print_with_flush(line)
180199
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)
183203
formatted_output = fatal_log_format
184204

185205
if "%t" in formatted_output:
186206
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)
189211
if "%m" in formatted_output:
190212
formatted_output = formatted_output.replace("%m", stack_str)
191213

192214
print_with_flush(formatted_output)
193215

216+
194217
def main():
195218
parser = argparse.ArgumentParser(
196219
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -202,7 +225,10 @@ def main():
202225
help="Log file for symbolication. Defaults to stdin.")
203226
parser.add_argument(
204227
"--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.")
206232
args = parser.parse_args()
207233

208234
binary = args.binary
@@ -228,7 +254,10 @@ def main():
228254
stackidx = stackidx + 1
229255
else:
230256
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)
232261

233262
instack = False
234263
stackidx = 0
@@ -253,7 +282,11 @@ def main():
253282
if is_fatal_error(previous_line):
254283
print_with_flush(previous_line.rstrip())
255284
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+
257290

258291
if __name__ == '__main__':
259292
main()

0 commit comments

Comments
 (0)