blob: 6b28689034339168db5e248c0cab1dd839885256 [file] [log] [blame]
Greg Clayton01f7c962012-01-20 03:15:45 +00001#!/usr/bin/python
2
3#----------------------------------------------------------------------
4# Be sure to add the python path that points to the LLDB shared library.
5# On MacOSX csh, tcsh:
6# setenv PYTHONPATH /Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
7# On MacOSX sh, bash:
8# export PYTHONPATH=/Developer/Library/PrivateFrameworks/LLDB.framework/Resources/Python
9#----------------------------------------------------------------------
10
11import lldb
12import commands # commands.getoutput ('/bin/ls /tmp')
13import optparse
14import os
15import plistlib
16import pprint
17import re
18import sys
19import time
Greg Claytoncd793122012-01-20 06:12:47 +000020import uuid
21
Greg Clayton01f7c962012-01-20 03:15:45 +000022
23PARSE_MODE_NORMAL = 0
24PARSE_MODE_THREAD = 1
25PARSE_MODE_IMAGES = 2
26PARSE_MODE_THREGS = 3
27PARSE_MODE_SYSTEM = 4
28
29class CrashLog:
30 """Class that does parses darwin crash logs"""
31 thread_state_regex = re.compile('^Thread ([0-9]+) crashed with')
32 thread_regex = re.compile('^Thread ([0-9]+)([^:]*):(.*)')
Greg Clayton8077a532012-01-20 03:32:35 +000033 frame_regex = re.compile('^([0-9]+) +([^ ]+) *\t(0x[0-9a-fA-F]+) +(.*)')
34 image_regex_uuid = re.compile('(0x[0-9a-fA-F]+)[- ]+(0x[0-9a-fA-F]+) +[+]?([^ ]+) +([^<]+)<([-0-9a-fA-F]+)> (.*)');
35 image_regex_no_uuid = re.compile('(0x[0-9a-fA-F]+)[- ]+(0x[0-9a-fA-F]+) +[+]?([^ ]+) +([^/]+)/(.*)');
Greg Clayton01f7c962012-01-20 03:15:45 +000036 empty_line_regex = re.compile('^$')
37
38 class Thread:
39 """Class that represents a thread in a darwin crash log"""
40 def __init__(self, index):
41 self.index = index
42 self.frames = list()
43 self.registers = dict()
44 self.reason = None
45 self.queue = None
46
47 def dump(self, prefix):
48 print "%sThread[%u] %s" % (prefix, self.index, self.reason)
49 if self.frames:
50 print "%s Frames:" % (prefix)
51 for frame in self.frames:
52 frame.dump(prefix + ' ')
53 if self.registers:
54 print "%s Registers:" % (prefix)
55 for reg in self.registers.keys():
56 print "%s %-5s = %#16.16x" % (prefix, reg, self.registers[reg])
57
58 def did_crash(self):
59 return self.reason != None
60
61 def __str__(self):
62 s = "Thread[%u]" % self.index
63 if self.reason:
64 s += ' %s' % self.reason
65 return s
66
67
68 class Frame:
69 """Class that represents a stack frame in a thread in a darwin crash log"""
70 def __init__(self, index, pc, details):
71 self.index = index
72 self.pc = pc
73 self.sym_ctx = None
74 self.details = details
75
76 def __str__(self):
77 return "[%2u] %#16.16x %s" % (self.index, self.pc, self.details)
78
79 def dump(self, prefix):
80 print "%s%s" % (prefix, self)
81
82
83 class Image:
84 """Class that represents a binary images in a darwin crash log"""
Greg Clayton8077a532012-01-20 03:32:35 +000085 dsymForUUIDBinary = os.path.expanduser('~rc/bin/dsymForUUID')
Greg Claytoncd793122012-01-20 06:12:47 +000086 if not os.path.exists(dsymForUUIDBinary):
87 dsymForUUIDBinary = commands.getoutput('which dsymForUUID')
88
89 dwarfdump_uuid_regex = re.compile('UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*')
Greg Clayton8077a532012-01-20 03:32:35 +000090
Greg Clayton01f7c962012-01-20 03:15:45 +000091 def __init__(self, text_addr_lo, text_addr_hi, ident, version, uuid, path):
92 self.text_addr_lo = text_addr_lo
93 self.text_addr_hi = text_addr_hi
94 self.ident = ident
95 self.version = version
Greg Claytoncd793122012-01-20 06:12:47 +000096 self.arch = None
Greg Clayton01f7c962012-01-20 03:15:45 +000097 self.uuid = uuid
98 self.path = path
Greg Claytoncd793122012-01-20 06:12:47 +000099 self.resolved_path = None
100 self.dsym = None
Greg Clayton01f7c962012-01-20 03:15:45 +0000101 self.target = None
102 self.module = None
Greg Clayton01f7c962012-01-20 03:15:45 +0000103
104 def dump(self, prefix):
105 print "%s%s" % (prefix, self)
106
107 def __str__(self):
Greg Claytoncd793122012-01-20 06:12:47 +0000108 return "%#16.16x %s %s" % (self.text_addr_lo, self.uuid, self.get_resolved_path())
Greg Clayton01f7c962012-01-20 03:15:45 +0000109
Greg Claytoncd793122012-01-20 06:12:47 +0000110 def get_resolved_path(self):
111 if self.resolved_path:
112 return self.resolved_path
113 elif self.path:
114 return self.path
115 return None
116
117 def get_resolved_path_basename(self):
118 path = self.get_resolved_path()
119 if path:
120 return os.path.basename(path)
121 return None
122
123 def dsym_basename(self):
124 if self.dsym:
125 return os.path.basename(self.dsym)
Greg Clayton01f7c962012-01-20 03:15:45 +0000126 return None
127
128 def fetch_symboled_executable_and_dsym(self):
Greg Claytoncd793122012-01-20 06:12:47 +0000129 if self.resolved_path:
130 # Don't load a module twice...
131 return 0
132 print 'Locating %s %s...' % (self.uuid, self.path),
Greg Clayton8077a532012-01-20 03:32:35 +0000133 if os.path.exists(self.dsymForUUIDBinary):
134 dsym_for_uuid_command = '%s %s' % (self.dsymForUUIDBinary, self.uuid)
Greg Clayton8077a532012-01-20 03:32:35 +0000135 s = commands.getoutput(dsym_for_uuid_command)
136 if s:
137 plist_root = plistlib.readPlistFromString (s)
138 if plist_root:
139 # pp = pprint.PrettyPrinter(indent=4)
140 # pp.pprint(plist_root)
Greg Claytoncd793122012-01-20 06:12:47 +0000141 plist = plist_root[self.uuid]
142 if plist:
143 if 'DBGArchitecture' in plist:
144 self.arch = plist['DBGArchitecture']
145 if 'DBGDSYMPath' in plist:
146 self.dsym = os.path.realpath(plist['DBGDSYMPath'])
147 if 'DBGSymbolRichExecutable' in plist:
148 self.resolved_path = os.path.expanduser (plist['DBGSymbolRichExecutable'])
149 if not self.resolved_path and os.path.exists(self.path):
150 dwarfdump_cmd_output = commands.getoutput('dwarfdump --uuid "%s"' % self.path)
151 self_uuid = uuid.UUID(self.uuid)
152 for line in dwarfdump_cmd_output.splitlines():
153 match = self.dwarfdump_uuid_regex.search (line)
154 if match:
155 dwarf_uuid_str = match.group(1)
156 dwarf_uuid = uuid.UUID(dwarf_uuid_str)
157 if self_uuid == dwarf_uuid:
158 self.resolved_path = self.path
159 self.arch = match.group(2)
160 break;
161 if not self.resolved_path:
162 print "error: file %s '%s' doesn't match the UUID in the installed file" % (self.uuid, self.path)
163 return 0
164 if (self.resolved_path and os.path.exists(self.resolved_path)) or (self.path and os.path.exists(self.path)):
165 print 'ok'
166 if self.path != self.resolved_path:
167 print ' exe = "%s"' % self.resolved_path
168 if self.dsym:
169 print ' dsym = "%s"' % self.dsym
170 return 1
Greg Clayton01f7c962012-01-20 03:15:45 +0000171 else:
Greg Claytoncd793122012-01-20 06:12:47 +0000172 return 0
Greg Clayton01f7c962012-01-20 03:15:45 +0000173
174 def load_module(self):
175 if self.module:
176 text_section = self.module.FindSection ("__TEXT")
177 if text_section:
178 error = self.target.SetSectionLoadAddress (text_section, self.text_addr_lo)
179 if error.Success():
Greg Clayton8077a532012-01-20 03:32:35 +0000180 #print 'Success: loaded %s.__TEXT = 0x%x' % (self.basename(), self.text_addr_lo)
Greg Clayton01f7c962012-01-20 03:15:45 +0000181 return None
182 else:
183 return 'error: %s' % error.GetCString()
184 else:
Greg Claytoncd793122012-01-20 06:12:47 +0000185 return 'error: unable to find "__TEXT" section in "%s"' % self.get_resolved_path()
Greg Clayton01f7c962012-01-20 03:15:45 +0000186 else:
187 return 'error: invalid module'
188
189 def create_target(self, debugger):
190 if self.fetch_symboled_executable_and_dsym ():
Greg Claytoncd793122012-01-20 06:12:47 +0000191 resolved_path = self.get_resolved_path();
192 path_spec = lldb.SBFileSpec (resolved_path)
Greg Clayton01f7c962012-01-20 03:15:45 +0000193 #result.PutCString ('plist[%s] = %s' % (uuid, self.plist))
194 error = lldb.SBError()
Greg Claytoncd793122012-01-20 06:12:47 +0000195 self.target = debugger.CreateTarget (resolved_path, self.arch, None, False, error);
Greg Clayton01f7c962012-01-20 03:15:45 +0000196 if self.target:
197 self.module = self.target.FindModule (path_spec)
198 if self.module:
199 err = self.load_module()
200 if err:
201 print err
202 else:
203 return None
204 else:
Greg Claytoncd793122012-01-20 06:12:47 +0000205 return 'error: unable to get module for (%s) "%s"' % (self.arch, resolved_path)
Greg Clayton01f7c962012-01-20 03:15:45 +0000206 else:
Greg Claytoncd793122012-01-20 06:12:47 +0000207 return 'error: unable to create target for (%s) "%s"' % (self.arch, resolved_path)
Greg Clayton01f7c962012-01-20 03:15:45 +0000208
209 def add_target_module(self, target):
210 if target:
211 self.target = target
212 if self.fetch_symboled_executable_and_dsym ():
Greg Claytoncd793122012-01-20 06:12:47 +0000213 resolved_path = self.get_resolved_path();
214 path_spec = lldb.SBFileSpec (resolved_path)
215 #print 'target.AddModule (path="%s", arch="%s", uuid=%s)' % (resolved_path, self.arch, self.uuid)
216 self.module = target.AddModule (resolved_path, self.arch, self.uuid)
Greg Clayton01f7c962012-01-20 03:15:45 +0000217 if self.module:
218 err = self.load_module()
219 if err:
220 print err;
221 else:
222 return None
223 else:
Greg Claytoncd793122012-01-20 06:12:47 +0000224 return 'error: unable to get module for (%s) "%s"' % (self.arch, resolved_path)
Greg Clayton01f7c962012-01-20 03:15:45 +0000225 else:
226 return 'error: invalid target'
227
228 def __init__(self, path):
229 """CrashLog constructor that take a path to a darwin crash log file"""
230 self.path = path;
231 self.info_lines = list()
232 self.system_profile = list()
233 self.threads = list()
234 self.images = list()
235 self.idents = list() # A list of the required identifiers for doing all stack backtraces
236 self.crashed_thread_idx = -1
237 self.version = -1
238 # With possible initial component of ~ or ~user replaced by that user's home directory.
239 f = open(os.path.expanduser(self.path))
240 self.file_lines = f.read().splitlines()
241 parse_mode = PARSE_MODE_NORMAL
242 thread = None
243 for line in self.file_lines:
244 # print line
245 line_len = len(line)
246 if line_len == 0:
247 if thread:
248 if parse_mode == PARSE_MODE_THREAD:
249 if thread.index == self.crashed_thread_idx:
250 thread.reason = ''
251 if self.thread_exception:
252 thread.reason += self.thread_exception
253 if self.thread_exception_data:
254 thread.reason += " (%s)" % self.thread_exception_data
255 self.threads.append(thread)
256 thread = None
257 else:
258 # only append an extra empty line if the previous line
259 # in the info_lines wasn't empty
260 if len(self.info_lines) > 0 and len(self.info_lines[-1]):
261 self.info_lines.append(line)
262 parse_mode = PARSE_MODE_NORMAL
263 # print 'PARSE_MODE_NORMAL'
264 elif parse_mode == PARSE_MODE_NORMAL:
265 if line.startswith ('Process:'):
266 (self.process_name, pid_with_brackets) = line[8:].strip().split()
267 self.process_id = pid_with_brackets.strip('[]')
268 elif line.startswith ('Path:'):
269 self.process_path = line[5:].strip()
270 elif line.startswith ('Identifier:'):
271 self.process_identifier = line[11:].strip()
272 elif line.startswith ('Version:'):
273 (self.process_version, compatability_version) = line[8:].strip().split()
274 self.process_compatability_version = compatability_version.strip('()')
275 elif line.startswith ('Parent Process:'):
276 (self.parent_process_name, pid_with_brackets) = line[15:].strip().split()
277 self.parent_process_id = pid_with_brackets.strip('[]')
278 elif line.startswith ('Exception Type:'):
279 self.thread_exception = line[15:].strip()
280 continue
281 elif line.startswith ('Exception Codes:'):
282 self.thread_exception_data = line[16:].strip()
283 continue
284 elif line.startswith ('Crashed Thread:'):
285 self.crashed_thread_idx = int(line[15:].strip().split()[0])
286 continue
287 elif line.startswith ('Report Version:'):
288 self.version = int(line[15:].strip())
289 continue
290 elif line.startswith ('System Profile:'):
291 parse_mode = PARSE_MODE_SYSTEM
292 continue
293 elif (line.startswith ('Interval Since Last Report:') or
294 line.startswith ('Crashes Since Last Report:') or
295 line.startswith ('Per-App Interval Since Last Report:') or
296 line.startswith ('Per-App Crashes Since Last Report:') or
297 line.startswith ('Sleep/Wake UUID:') or
298 line.startswith ('Anonymous UUID:')):
299 # ignore these
300 continue
301 elif line.startswith ('Thread'):
302 thread_state_match = self.thread_state_regex.search (line)
303 if thread_state_match:
304 thread_state_match = self.thread_regex.search (line)
305 thread_idx = int(thread_state_match.group(1))
306 parse_mode = PARSE_MODE_THREGS
307 thread = self.threads[thread_idx]
308 else:
309 thread_match = self.thread_regex.search (line)
310 if thread_match:
311 # print 'PARSE_MODE_THREAD'
312 parse_mode = PARSE_MODE_THREAD
313 thread_idx = int(thread_match.group(1))
314 thread = CrashLog.Thread(thread_idx)
315 continue
316 elif line.startswith ('Binary Images:'):
317 parse_mode = PARSE_MODE_IMAGES
318 continue
319 self.info_lines.append(line.strip())
320 elif parse_mode == PARSE_MODE_THREAD:
321 frame_match = self.frame_regex.search(line)
322 if frame_match:
323 ident = frame_match.group(2)
324 if not ident in self.idents:
325 self.idents.append(ident)
326 thread.frames.append (CrashLog.Frame(int(frame_match.group(1)), int(frame_match.group(3), 0), frame_match.group(4)))
327 else:
Greg Clayton8077a532012-01-20 03:32:35 +0000328 print 'error: frame regex failed for line: "%s"' % line
Greg Clayton01f7c962012-01-20 03:15:45 +0000329 elif parse_mode == PARSE_MODE_IMAGES:
330 image_match = self.image_regex_uuid.search (line)
331 if image_match:
332 image = CrashLog.Image (int(image_match.group(1),0),
333 int(image_match.group(2),0),
334 image_match.group(3).strip(),
335 image_match.group(4).strip(),
336 image_match.group(5),
337 image_match.group(6))
338 self.images.append (image)
339 else:
340 image_match = self.image_regex_no_uuid.search (line)
341 if image_match:
342 image = CrashLog.Image (int(image_match.group(1),0),
343 int(image_match.group(2),0),
344 image_match.group(3).strip(),
345 image_match.group(4).strip(),
346 None,
347 image_match.group(5))
348 self.images.append (image)
349 else:
350 print "error: image regex failed for: %s" % line
351
352 elif parse_mode == PARSE_MODE_THREGS:
353 stripped_line = line.strip()
354 reg_values = stripped_line.split(' ')
355 for reg_value in reg_values:
356 (reg, value) = reg_value.split(': ')
357 thread.registers[reg.strip()] = int(value, 0)
358 elif parse_mode == PARSE_MODE_SYSTEM:
359 self.system_profile.append(line)
360 f.close()
361
362 def dump(self):
363 print "Crash Log File: %s" % (self.path)
364 print "\nThreads:"
365 for thread in self.threads:
366 thread.dump(' ')
367 print "\nImages:"
368 for image in self.images:
369 image.dump(' ')
370
371 def find_image_with_identifier(self, ident):
372 for image in self.images:
373 if image.ident == ident:
374 return image
375 return None
376
377def disassemble_instructions (target, instructions, pc, insts_before_pc, insts_after_pc):
378 lines = list()
379 pc_index = -1
380 comment_column = 50
381 for inst_idx, inst in enumerate(instructions):
382 inst_pc = inst.GetAddress().GetLoadAddress(target);
383 if pc == inst_pc:
384 pc_index = inst_idx
385 mnemonic = inst.GetMnemonic (target)
386 operands = inst.GetOperands (target)
387 comment = inst.GetComment (target)
388 #data = inst.GetData (target)
389 lines.append ("%#16.16x: %8s %s" % (inst_pc, mnemonic, operands))
390 if comment:
391 line_len = len(lines[-1])
392 if line_len < comment_column:
393 lines[-1] += ' ' * (comment_column - line_len)
394 lines[-1] += "; %s" % comment
395
396 if pc_index >= 0:
397 if pc_index >= insts_before_pc:
398 start_idx = pc_index - insts_before_pc
399 else:
400 start_idx = 0
401 end_idx = pc_index + insts_after_pc
402 if end_idx > inst_idx:
403 end_idx = inst_idx
404 for i in range(start_idx, end_idx+1):
405 if i == pc_index:
406 print ' -> ', lines[i]
407 else:
408 print ' ', lines[i]
409
410def print_module_section_data (section):
411 print section
412 section_data = section.GetSectionData()
413 if section_data:
414 ostream = lldb.SBStream()
415 section_data.GetDescription (ostream, section.GetFileAddress())
416 print ostream.GetData()
417
418def print_module_section (section, depth):
419 print section
420
421 if depth > 0:
422 num_sub_sections = section.GetNumSubSections()
423 for sect_idx in range(num_sub_sections):
424 print_module_section (section.GetSubSectionAtIndex(sect_idx), depth - 1)
425
426def print_module_sections (module, depth):
427 for sect in module.section_iter():
428 print_module_section (sect, depth)
429
430def print_module_symbols (module):
431 for sym in module:
432 print sym
433
434def usage():
435 print "Usage: lldb-symbolicate.py [-n name] executable-image"
436 sys.exit(0)
437
438def Symbolicate(debugger, command, result, dict):
439 SymbolicateCrashLog (command.split())
440
441def SymbolicateCrashLog(command_args):
442
443 parser = optparse.OptionParser(description='A script that parses skinny and universal mach-o files.')
444 parser.add_option('--arch', type='string', metavar='arch', dest='triple', help='specify one architecture or target triple')
445 parser.add_option('--platform', type='string', metavar='platform', dest='platform', help='specify one platform by name')
446 parser.add_option('--verbose', action='store_true', dest='verbose', help='display verbose debug info', default=False)
447 parser.add_option('--interactive', action='store_true', dest='interactive', help='enable interactive mode', default=False)
448 parser.add_option('--no-images', action='store_false', dest='show_images', help='don\'t show images in stack frames', default=True)
449 parser.add_option('--no-dependents', action='store_false', dest='dependents', help='skip loading dependent modules', default=True)
450 parser.add_option('--sections', action='store_true', dest='dump_sections', help='show module sections', default=False)
451 parser.add_option('--symbols', action='store_true', dest='dump_symbols', help='show module symbols', default=False)
452 parser.add_option('--image-list', action='store_true', dest='dump_image_list', help='show image list', default=False)
453 parser.add_option('--debug-delay', type='int', dest='debug_delay', metavar='NSEC', help='pause for NSEC seconds for debugger', default=0)
454 parser.add_option('--section-depth', type='int', dest='section_depth', help='set the section depth to use when showing sections', default=0)
455 parser.add_option('--section-data', type='string', action='append', dest='sect_data_names', help='specify sections by name to display data for')
456 parser.add_option('--address', type='int', action='append', dest='addresses', help='specify addresses to lookup')
457 parser.add_option('--crash-log', type='string', action='append', dest='crash_log_files', help='specify crash log files to symbolicate')
458 parser.add_option('--crashed-only', action='store_true', dest='crashed_only', help='only show the crashed thread', default=False)
459 loaded_addresses = False
460 (options, args) = parser.parse_args(command_args)
461 if options.verbose:
462 print 'options', options
463
464 if options.debug_delay > 0:
465 print "Waiting %u seconds for debugger to attach..." % options.debug_delay
466 time.sleep(options.debug_delay)
467
468 # Create a new debugger instance
469 debugger = lldb.SBDebugger.Create()
470
471 error = lldb.SBError()
472
473
474 if options.crash_log_files:
475 options.dependents = False
476 for crash_log_file in options.crash_log_files:
477 crash_log = CrashLog(crash_log_file)
Greg Clayton8077a532012-01-20 03:32:35 +0000478 if options.verbose:
479 crash_log.dump()
Greg Clayton01f7c962012-01-20 03:15:45 +0000480 if crash_log.images:
481 err = crash_log.images[0].create_target (debugger)
482 if err:
483 print err
484 else:
485 target = crash_log.images[0].target
486 exe_module = target.GetModuleAtIndex(0)
487 image_paths = list()
488 # for i in range (1, len(crash_log.images)):
489 # image = crash_log.images[i]
490 for ident in crash_log.idents:
491 image = crash_log.find_image_with_identifier (ident)
492 if image:
493 if image.path in image_paths:
494 print "warning: skipping %s loaded at %#16.16x duplicate entry (probably commpage)" % (image.path, image.text_addr_lo)
495 else:
496 err = image.add_target_module (target)
497 if err:
498 print err
499 else:
500 image_paths.append(image.path)
501 else:
502 print 'error: can\'t find image for identifier "%s"' % ident
503
504 for line in crash_log.info_lines:
505 print line
506
507 # Reconstruct inlined frames for all threads for anything that has debug info
508 for thread in crash_log.threads:
509 if options.crashed_only and thread.did_crash() == False:
510 continue
511 # start a new frame list that we will fixup for each thread
512 new_thread_frames = list()
513 # Iterate through all concrete frames for a thread and resolve
514 # any parent frames of inlined functions
515 for frame_idx, frame in enumerate(thread.frames):
516 # Resolve the frame's pc into a section + offset address 'pc_addr'
517 pc_addr = target.ResolveLoadAddress (frame.pc)
518 # Check to see if we were able to resolve the address
519 if pc_addr:
520 # We were able to resolve the frame's PC into a section offset
521 # address.
522
523 # Resolve the frame's PC value into a symbol context. A symbol
524 # context can resolve a module, compile unit, function, block,
525 # line table entry and/or symbol. If the frame has a block, then
526 # we can look for inlined frames, which are represented by blocks
527 # that have inlined information in them
528 frame.sym_ctx = target.ResolveSymbolContextForAddress (pc_addr, lldb.eSymbolContextEverything);
529
530 # dump if the verbose option was specified
531 if options.verbose:
532 print "frame.pc = %#16.16x (file_addr = %#16.16x)" % (frame.pc, pc_addr.GetFileAddress())
533 print "frame.pc_addr = ", pc_addr
534 print "frame.sym_ctx = "
535 print frame.sym_ctx
536 print
537
538 # Append the frame we already had from the crash log to the new
539 # frames list
540 new_thread_frames.append(frame)
541
542 new_frame = CrashLog.Frame (frame.index, -1, None)
543
544 # Try and use the current frame's symbol context to calculate a
545 # parent frame for an inlined function. If the curent frame is
546 # inlined, it will return a valid symbol context for the parent
547 # frame of the current inlined function
548 parent_pc_addr = lldb.SBAddress()
549 new_frame.sym_ctx = frame.sym_ctx.GetParentOfInlinedScope (pc_addr, parent_pc_addr)
550
551 # See if we were able to reconstruct anything?
552 while new_frame.sym_ctx:
553 # We have a parent frame of an inlined frame, create a new frame
554 # Convert the section + offset 'parent_pc_addr' to a load address
555 new_frame.pc = parent_pc_addr.GetLoadAddress(target)
556 # push the new frame onto the new frame stack
557 new_thread_frames.append (new_frame)
558 # dump if the verbose option was specified
559 if options.verbose:
560 print "new_frame.pc = %#16.16x (%s)" % (new_frame.pc, parent_pc_addr)
561 print "new_frame.sym_ctx = "
562 print new_frame.sym_ctx
563 print
564 # Create another new frame in case we have multiple inlined frames
565 prev_new_frame = new_frame
566 new_frame = CrashLog.Frame (frame.index, -1, None)
567 # Swap the addresses so we can try another inlined lookup
568 pc_addr = parent_pc_addr;
569 new_frame.sym_ctx = prev_new_frame.sym_ctx.GetParentOfInlinedScope (pc_addr, parent_pc_addr)
570 # Replace our thread frames with our new list that includes parent
571 # frames for inlined functions
572 thread.frames = new_thread_frames
573 # Now iterate through all threads and display our richer stack backtraces
574 for thread in crash_log.threads:
575 this_thread_crashed = thread.did_crash()
576 if options.crashed_only and this_thread_crashed == False:
577 continue
578 print "%s" % thread
579 prev_frame_index = -1
580 for frame_idx, frame in enumerate(thread.frames):
581 details = ' %s' % frame.details
582 module = frame.sym_ctx.GetModule()
583 instructions = None
584 if module:
585 module_basename = module.GetFileSpec().GetFilename();
586 function_start_load_addr = -1
587 function_name = None
588 function = frame.sym_ctx.GetFunction()
589 block = frame.sym_ctx.GetBlock()
590 line_entry = frame.sym_ctx.GetLineEntry()
591 symbol = frame.sym_ctx.GetSymbol()
592 inlined_block = block.GetContainingInlinedBlock();
593 if inlined_block:
594 function_name = inlined_block.GetInlinedName();
595 block_range_idx = inlined_block.GetRangeIndexForBlockAddress (target.ResolveLoadAddress (frame.pc))
596 if block_range_idx < lldb.UINT32_MAX:
597 block_range_start_addr = inlined_block.GetRangeStartAddress (block_range_idx)
598 function_start_load_addr = block_range_start_addr.GetLoadAddress (target)
599 else:
600 function_start_load_addr = frame.pc
601 if this_thread_crashed and frame_idx == 0:
602 instructions = function.GetInstructions(target)
603 elif function:
604 function_name = function.GetName()
605 function_start_load_addr = function.GetStartAddress().GetLoadAddress (target)
606 if this_thread_crashed and frame_idx == 0:
607 instructions = function.GetInstructions(target)
608 elif symbol:
609 function_name = symbol.GetName()
610 function_start_load_addr = symbol.GetStartAddress().GetLoadAddress (target)
611 if this_thread_crashed and frame_idx == 0:
612 instructions = symbol.GetInstructions(target)
613
614 if function_name:
615 # Print the function or symbol name and annotate if it was inlined
616 inline_suffix = ''
617 if inlined_block:
618 inline_suffix = '[inlined] '
619 else:
620 inline_suffix = ' '
621 if options.show_images:
622 details = "%s%s`%s" % (inline_suffix, module_basename, function_name)
623 else:
624 details = "%s" % (function_name)
625 # Dump the offset from the current function or symbol if it is non zero
626 function_offset = frame.pc - function_start_load_addr
627 if function_offset > 0:
628 details += " + %u" % (function_offset)
629 elif function_offset < 0:
630 defaults += " %i (invalid negative offset, file a bug) " % function_offset
631 # Print out any line information if any is available
632 if line_entry.GetFileSpec():
633 details += ' at %s' % line_entry.GetFileSpec().GetFilename()
634 details += ':%u' % line_entry.GetLine ()
635 column = line_entry.GetColumn()
636 if column > 0:
637 details += ':%u' % column
638
639
640 # Only print out the concrete frame index if it changes.
641 # if prev_frame_index != frame.index:
642 # print "[%2u] %#16.16x %s" % (frame.index, frame.pc, details)
643 # else:
644 # print " %#16.16x %s" % (frame.pc, details)
645 print "[%2u] %#16.16x %s" % (frame.index, frame.pc, details)
646 prev_frame_index = frame.index
647 if instructions:
648 print
649 disassemble_instructions (target, instructions, frame.pc, 4, 4)
650 print
651
652 print
653
654 if options.dump_image_list:
655 print "Binary Images:"
656 for image in crash_log.images:
657 print image
658
659
660if __name__ == '__main__':
661 SymbolicateCrashLog (args)
662