[<<][c][>>][..]
Thu Dec 29 11:05:45 EST 2011

Obtaining pointer to current function

Is there a way to obtain a pointer to the current function's address
without knowing its name?  I.e.

  void foo(void) {
      void *me = &this_function;
  }

From [1] it seems that this isn't possible, except for doing it with a
function call like this:

  #include <stdio.h>

  void *get_addr(void) {
      return __builtin_return_address(0);
  }

  int main(void) {
      printf("%p\n", get_addr());
      return 0;
  }

This might be enough though.  The thing is that gdb knows how to map
this to a source location, given the binary compiled with debugging
symbols:

  # gdb <ELF>
  (gdb) list *<ADDRESS>





[1] http://stackoverflow.com/questions/2154852/get-a-pointer-to-the-current-function-in-c-gcc



[Reply][About]
[<<][c][>>][..]