Created
September 6, 2013 01:09
-
-
Save nddrylliog/6458295 to your computer and use it in GitHub Desktop.
Is this stupid or just cool? Inspired by http://jpassing.com/2008/03/12/walking-the-stack-of-the-current-thread/
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
$ gdb --args ./register | |
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Thu Nov 15 10:42:43 UTC 2012) | |
Copyright 2004 Free Software Foundation, Inc. | |
GDB is free software, covered by the GNU General Public License, and you are | |
welcome to change it and/or distribute copies of it under certain conditions. | |
Type "show copying" to see the conditions. | |
There is absolutely no warranty for GDB. Type "show warranty" for details. | |
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done | |
(gdb) break do_something | |
Breakpoint 1 at 0x1ebc: file register.c, line 7. | |
(gdb) r | |
Starting program: /Users/amos/Dev/tests/assy/register | |
warning: posix_spawn failed, trying execvp, error: 86 | |
Reading symbols for shared libraries +......................... done | |
Breakpoint 1, do_something () at register.c:7 | |
7 void * reg_eip = 0; | |
(gdb) info registers | |
eax 0x1ebb 7867 | |
ecx 0x1 1 | |
edx 0x90864725 -1870248155 | |
ebx 0xbffff440 -1073744832 | |
esp 0xbffff270 0xbffff270 | |
ebp 0xbffff298 0xbffff298 | |
esi 0x0 0 | |
edi 0x0 0 |
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
all: register | |
register : register.c | |
gcc -save-temps -m32 -g -fno-pie -o $@ $^ | |
dsymutil $@ | |
clean: | |
rm -rf register register.dSYM |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
int do_something() { | |
void * reg_eip = 0; | |
__asm__ volatile ("1: movl $1b, %0" : "=r" (reg_eip)); | |
printf("eip = %p\n", reg_eip); | |
void * reg_ebp = 0; | |
__asm__ volatile ("movl %%ebp, %0" : "=r" (reg_ebp)); | |
printf("ebp = %p\n", reg_ebp); | |
void * reg_esp = 0; | |
__asm__ volatile ("movl %%esp, %0" : "=r" (reg_esp)); | |
printf("esp = %p\n", reg_esp); | |
} | |
int main(int argc, char ** argv) { | |
do_something(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment