#include #include #include #include #include #include #include #define REGN (FRAME_SIZE+1) const char *reg_names[REGN] = { /* 0 */ "ebx", "ecx", "edx", "esi", "edi", "ebp", "eax", "ds", /* 8 */ "es", "fs", "gs", "orig_eax", "eip", "cs", "eflags", "esp", /* 16 */ "ss", "xxx" }; int main() { pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } else if (pid == 0) { int r; r = ptrace(PTRACE_TRACEME, 0, NULL, NULL); if (r == -1) { perror("ptrace(PTRACE_TRACEME)"); } kill(getpid(), SIGINT); exit(0); } else { int r, i, status; unsigned long regs[REGN]; r = waitpid(pid, &status, 0); if (r == -1) { perror("waitpid"); } for (i = 0; i < REGN; ++i) regs[i] = 0xdeafbeefUL; r = ptrace(PTRACE_GETREGS, pid, NULL, (void *) ®s); if (r == -1) { perror("ptrace"); } for (i = 0; i < REGN; ++i) printf("%2d: %-8s 0x%08x\n", i, reg_names[i], regs[i]); ptrace(PTRACE_KILL, pid, NULL, NULL); } return 0; }