Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GDB to inspect the Machine Stack

Tags:

gdb

Is there any way to get GDB to print the last "n" values pushed on the machine's stack. For example, currently if I want to inspect the contents of the stack I do the following (assuming x86 architecture):

(gdb) # get last value pushed on stack
(gdb) p *(int *)($esp)
(gdb) # get 2nd to last value pushed on stack
(gdb) p *(int *)($esp + 4) 

Is there a better way to view the machine stack? Printed nicely, maybe?

like image 428
Rohit Avatar asked Oct 25 '10 22:10

Rohit


1 Answers

Examine 16 words on the top of stack:

x/16wx $esp

The "w" is for printing words

like image 60
Employed Russian Avatar answered Nov 08 '22 15:11

Employed Russian