Re: [GD-Linux] Determining address of C++ member function atrun-time...
Brought to you by:
vexxed72
From: D. S. <st...@id...> - 2001-12-12 08:46:33
|
"Ryan C. Gordon" wrote: > > > 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); If you don't mind compiling it in, there are standard defines under gcc (I think on most platforms, not just linux) of __FILE__ and __LINE__. E.G.: printf( "%s at line %s\n", __FILE__, __LINE__ ); Assuming you can live with file name and line number, it'll do the trick. D. Stimits, st...@id... > > 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. > > _______________________________________________ > Gamedevlists-linux mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-linux |