7 def stack_frames(debugger
, command
, result
, dict):
8 command_args
= shlex
.split(command
)
9 usage
= "usage: %prog [options] <PATH> [PATH ...]"
10 description
= """This command will enumerate all stack frames, print the stack size for each, and print an aggregation of which functions have the largest stack frame sizes at the end."""
11 parser
= optparse
.OptionParser(description
=description
, prog
="ls", usage
=usage
)
17 help="display verbose debug info",
21 (options
, args
) = parser
.parse_args(command_args
)
25 target
= debugger
.GetSelectedTarget()
26 process
= target
.GetProcess()
29 for thread
in process
:
31 print("thread %u" % (thread
.id))
32 for frame
in thread
.frames
:
36 if frame
.fp
== last_frame
.fp
:
37 # No frame one the first frame (might be right at the
40 frame_size
= frame
.fp
- frame
.sp
42 # First frame that has a valid size
43 first_frame_size
= last_frame
.fp
- last_frame
.sp
44 print("<%#7x> %s" % (first_frame_size
, last_frame
))
46 name
= last_frame
.name
47 if name
not in frame_info
:
48 frame_info
[name
] = first_frame_size
50 frame_info
[name
] += first_frame_size
52 # Second or higher frame
53 frame_size
= frame
.fp
- last_frame
.fp
54 print("<%#7x> %s" % (frame_size
, frame
))
57 if name
not in frame_info
:
58 frame_info
[name
] = frame_size
60 frame_info
[name
] += frame_size
65 def __lldb_init_module(debugger
, internal_dict
):
66 debugger
.HandleCommand("command script add -o -f stacks.stack_frames stack_frames")
68 "A new command called 'stack_frames' was added, type 'stack_frames --help' for more information."