Re: [GD-Linux] Determining address of C++ member function at run-time...
Brought to you by:
vexxed72
From: Ryan C. G. <ic...@cl...> - 2001-12-12 07:47:09
|
> That leads me to another question: How can > I get the run-time address of C++ statements? > For example, suppose I do this: > > goto my_label; > > my_label: > printf("Happy day, citizen!\n"); > > Could I figure out the approximate address of > the "printf" call (NOT the location of the > implementation of printf(), but the local > "line" of code where the "call printf" > assembly language is) just by doing the > following: > > printf( "%x", (unsigned int)(my_label) ); > > or something similar? Not portably. There IS a gcc extension, though: printf("address of my_label is (%p).\n", &&my_label); That is TWO ampersands, and is NOT a typo. And did I mention it's not portable. Chances are, if you need this, you also need to rethink your design. > Am I allowed to read any code pages just like > memory allocated on the heap? I mean *MY* code > pages. So is it possible to scan through the > assembly language opcodes of my own program > to search for code? By default, you have read and execute access to memory pages that represent your program. You need to change that to have write access, too, if you plan to do any self-modifying code, or you'll segfault. --ryan. |