blob: 37f33ba416a506154aaffaa460b1550fd1b5b2aa [file] [log] [blame]
Greg Clayton923bedf2013-03-07 02:57:54 +00001#!/usr/bin/python
2
3import lldb
4import optparse
5import shlex
6import string
7import sys
8
9def create_dump_module_line_tables_options ():
10 usage = "usage: dump_module_line_tables [options] MODULE1 [MODULE2 ...]"
11 description='''Dumps all line tables from all compile units for any modules specified as arguments. Specifying the --verbose flag will output address ranges for each line entry.'''
12 parser = optparse.OptionParser(description=description, prog='start_gdb_log',usage=usage)
13 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', help='Display verbose output.', default=False)
14 return parser
15
16def dump_module_line_tables(debugger, command, result, dict):
17 '''Dumps all line tables from all compile units for any modules specified as arguments.'''
18 command_args = shlex.split(command)
19
20 parser = create_dump_module_line_tables_options ()
21 try:
22 (options, args) = parser.parse_args(command_args)
23 except:
24 return
25 if command_args:
26 target = debugger.GetSelectedTarget()
27 lldb.target = target
28 for module_name in command_args:
29 result.PutCString('Searching for module "%s"' % (module_name,))
30 module_fspec = lldb.SBFileSpec (module_name, False)
31 module = target.FindModule (module_fspec);
32 if module:
33 for cu_idx in range (module.GetNumCompileUnits()):
34 cu = module.GetCompileUnitAtIndex(cu_idx)
35 result.PutCString("\n%s:" % (cu.file))
36 for line_idx in range(cu.GetNumLineEntries()):
37 line_entry = cu.GetLineEntryAtIndex(line_idx)
38 start_file_addr = line_entry.addr.file_addr
39 end_file_addr = line_entry.end_addr.file_addr
40 # If the two addresses are equal, this line table entry is a termination entry
41 if options.verbose:
42 if start_file_addr != end_file_addr:
43 result.PutCString('[%#x - %#x): %s' % (start_file_addr, end_file_addr, line_entry))
44 else:
45 if start_file_addr == end_file_addr:
46 result.PutCString('%#x: END' % (start_file_addr))
47 else:
48 result.PutCString('%#x: %s' % (start_file_addr, line_entry))
49 if start_file_addr == end_file_addr:
50 result.Printf("\n")
51 else:
52 result.PutCString ("no module for '%s'" % module)
53 else:
54 result.PutCString ("error: invalid target")
55
56parser = create_dump_module_line_tables_options ()
57dump_module_line_tables.__doc__ = parser.format_help()
58lldb.debugger.HandleCommand('command script add -f %s.dump_module_line_tables dump_module_line_tables' % __name__)
59print 'Installed "dump_module_line_tables" command'