Skip to content

Instantly share code, notes, and snippets.

@Matir
Forked from ayosec/README.md
Last active March 8, 2017 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Matir/10226aec9a1cfe9c321fee098aac262c to your computer and use it in GitHub Desktop.
Save Matir/10226aec9a1cfe9c321fee098aac262c to your computer and use it in GitHub Desktop.
GDB commands to trace calls to malloc/free

Attach to a running process with

  gdb -x trace-dyn-mem -p $PID

After every malloc the returned value (the allocated address) will be read from the RAX (64 bits) register.

After every free the last item in the backtrace (the free itself) will be shown. With the libc6-dbg package installed you can see the address passed as the first argument of free.

break malloc
commands
silent
bt 4
up
break
commands
silent
clear
print $rax
continue
end
continue
end
break free
commands
silent
bt 1
continue
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment