Created
August 9, 2019 09:22
-
-
Save roblabla/ababd5cad76ec72cf1143ed65d67d194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
class GetFrameSizesCommand(gdb.Command): | |
"""Gets the size of each frame, and of the whole stack. | |
Useful debugging tool to find out which functions have a fat stackframe. | |
""" | |
def __init__(self): | |
super(GetFrameSizesCommand, self).__init__( | |
"get-frame-sizes", | |
gdb.COMMAND_STATUS, | |
gdb.COMPLETE_NONE, | |
False) | |
def invoke(self, args, from_tty): | |
frame = gdb.newest_frame() | |
frame = frame.older() | |
s = 0 | |
while frame != None: | |
newer_frame = frame.newer() | |
bottom_esp = newer_frame.read_register("esp") | |
top_esp = frame.read_register("esp") | |
function_name = frame.function() | |
print(str(function_name) + ": " + hex(top_esp - bottom_esp)) | |
s += top_esp - bottom_esp | |
frame = frame.older() | |
print("Total stack size: " + hex(s)) | |
GetFrameSizesCommand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment