11 command_name
= "dump-line-tables"
13 "Dumps full paths to compile unit files and optionally all line table files."
15 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."
16 usage
= "usage: %prog [options] MODULE1 [MODULE2 ...]"
18 def create_options(self
):
19 self
.parser
= optparse
.OptionParser(
20 description
=self
.description
, prog
=self
.command_name
, usage
=self
.usage
23 self
.parser
.add_option(
28 help="Display verbose output.",
32 def get_short_help(self
):
33 return self
.short_description
35 def get_long_help(self
):
36 return self
.help_string
38 def __init__(self
, debugger
, unused
):
40 self
.help_string
= self
.parser
.format_help()
42 def __call__(self
, debugger
, command
, exe_ctx
, result
):
43 # Use the Shell Lexer to properly parse up command options just like a
45 command_args
= shlex
.split(command
)
48 (options
, args
) = self
.parser
.parse_args(command_args
)
50 # if you don't handle exceptions, passing an incorrect argument to the OptionParser will cause LLDB to exit
51 # (courtesy of OptParse dealing with argument errors by throwing SystemExit)
52 result
.SetError("option parsing failed")
55 # Always get program state from the SBExecutionContext passed in as exe_ctx
56 target
= exe_ctx
.GetTarget()
57 if not target
.IsValid():
58 result
.SetError("invalid target")
61 for module_path
in args
:
62 module
= target
.module
[module_path
]
64 result
.SetError('no module found that matches "%s".' % (module_path
))
66 num_cus
= module
.GetNumCompileUnits()
67 print('Module: "%s"' % (module
.file.fullpath
), end
=" ", file=result
)
69 print("no debug info.", file=result
)
71 print("has %u compile units:" % (num_cus
), file=result
)
72 for cu_idx
in range(num_cus
):
73 cu
= module
.GetCompileUnitAtIndex(cu_idx
)
74 print(" Compile Unit: %s" % (cu
.file.fullpath
), file=result
)
75 for line_idx
in range(cu
.GetNumLineEntries()):
76 line_entry
= cu
.GetLineEntryAtIndex(line_idx
)
77 start_file_addr
= line_entry
.addr
.file_addr
78 end_file_addr
= line_entry
.end_addr
.file_addr
79 # If the two addresses are equal, this line table entry
80 # is a termination entry
82 if start_file_addr
!= end_file_addr
:
85 % (start_file_addr
, end_file_addr
, line_entry
)
88 if start_file_addr
== end_file_addr
:
89 result
.PutCString(" %#x: END" % (start_file_addr
))
92 " %#x: %s" % (start_file_addr
, line_entry
)
94 if start_file_addr
== end_file_addr
:
95 result
.PutCString("\n")
99 command_name
= "dump-files"
100 short_description
= (
101 "Dumps full paths to compile unit files and optionally all line table files."
103 usage
= "usage: %prog [options] MODULE1 [MODULE2 ...]"
104 description
= """This class adds a dump-files command to the LLDB interpreter.
106 This command will dump all compile unit file paths found for each source file
107 for the binaries specified as arguments in the current target. Specify the
108 --support-files or -s option to see all file paths that a compile unit uses in
109 its lines tables. This is handy for troubleshooting why breakpoints aren't
110 working in IDEs that specify full paths to source files when setting file and
111 line breakpoints. Sometimes symlinks cause the debug info to contain the symlink
112 path and an IDE will resolve the path to the actual file and use the resolved
113 path when setting breakpoints.
116 def create_options(self
):
117 # Pass add_help_option = False, since this keeps the command in line with lldb commands,
118 # and we wire up "help command" to work by providing the long & short help methods below.
119 self
.parser
= optparse
.OptionParser(
120 description
=self
.description
,
121 prog
=self
.command_name
,
123 add_help_option
=False,
126 self
.parser
.add_option(
130 dest
="support_files",
131 help="Dumps full paths to all files used in a compile unit.",
135 def get_short_help(self
):
136 return self
.short_description
138 def get_long_help(self
):
139 return self
.help_string
141 def __init__(self
, debugger
, unused
):
142 self
.create_options()
143 self
.help_string
= self
.parser
.format_help()
145 def __call__(self
, debugger
, command
, exe_ctx
, result
):
146 # Use the Shell Lexer to properly parse up command options just like a
148 command_args
= shlex
.split(command
)
151 (options
, args
) = self
.parser
.parse_args(command_args
)
153 # if you don't handle exceptions, passing an incorrect argument to the OptionParser will cause LLDB to exit
154 # (courtesy of OptParse dealing with argument errors by throwing SystemExit)
155 result
.SetError("option parsing failed")
158 # Always get program state from the SBExecutionContext passed in as exe_ctx
159 target
= exe_ctx
.GetTarget()
160 if not target
.IsValid():
161 result
.SetError("invalid target")
165 result
.SetError("one or more executable paths must be specified")
168 for module_path
in args
:
169 module
= target
.module
[module_path
]
171 result
.SetError('no module found that matches "%s".' % (module_path
))
173 num_cus
= module
.GetNumCompileUnits()
174 print('Module: "%s"' % (module
.file.fullpath
), end
=" ", file=result
)
176 print("no debug info.", file=result
)
178 print("has %u compile units:" % (num_cus
), file=result
)
179 for i
in range(num_cus
):
180 cu
= module
.GetCompileUnitAtIndex(i
)
181 print(" Compile Unit: %s" % (cu
.file.fullpath
), file=result
)
182 if options
.support_files
:
183 num_support_files
= cu
.GetNumSupportFiles()
184 for j
in range(num_support_files
):
185 path
= cu
.GetSupportFileAtIndex(j
).fullpath
186 print(" file[%u]: %s" % (j
, path
), file=result
)
189 def __lldb_init_module(debugger
, dict):
190 # This initializer is being run from LLDB in the embedded command interpreter
192 # Add any commands contained in this module to LLDB
193 debugger
.HandleCommand(
194 "command script add -o -c %s.DumpLineTables %s"
195 % (__name__
, DumpLineTables
.command_name
)
197 debugger
.HandleCommand(
198 "command script add -o -c %s.DumpFiles %s" % (__name__
, DumpFiles
.command_name
)
201 'The "%s" and "%s" commands have been installed.'
202 % (DumpLineTables
.command_name
, DumpFiles
.command_name
)