Messages in this thread | | | Date | Thu, 18 Nov 2004 13:28:51 +0100 (CET) | From | Pawel Sikora <> | Subject | Re: Accessing program counter registers from within C or Aseembler. |
| |
On Thu, 18 Nov 2004, Jan Engelhardt wrote:
>>> Does anybody know how to access the address of the >>> current executing instruction in C while the program >>> is executing? >> >> In other words, are you trying to answer "Where in memory am *I*?" >> or "Where in memory is <that very recent code I want to look at>?" >> >> (Hint - for the former, you can probably get very good approximations >> by just looking at the entry point address for the function: >> >> (void *) where = &__FUNCTION__; > > Well, that's only the function in which you are (i.e. it's an approximation to > EIP)
Is this good enough ?
(gdb) disassemble __next_eip 0x08048380 <__next_eip+0>: mov (%esp),%eax 0x08048383 <__next_eip+3>: ret
(gdb) disassemble test1 0x08048390 <test1+0>: call 0x8048380 <__next_eip> 0x08048395 <test1+5>: mov %eax,0x80495ec 0x0804839a <test1+10>: ret
(gdb) c Continuing. eip = 0x8048395
*** src ***
void* eip; register unsigned* __esp asm("esp"); void* __attribute__((noinline)) __next_eip() { return (void *)(*__esp); } void test1() { eip = __next_eip(); } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |