ARTICLE AD BOX
Asked 16 years, 1 month ago
Viewed 6k times
Debugging some code in Visual Studio 2008 (C++), I noticed that the address in my function pointer variable is not the actual address of the function itself. This is an extern "C" function.
int main() { void (*printaddr)(const char *) = &print; // debug shows printaddr == 0x013C1429 } Address: 0x013C4F10 void print() { ... }The disassembly of taking the function address is:
void (*printaddr)(const char *) = &print; 013C7465 C7 45 BC 29 14 3C 01 mov dword ptr [printaddr],offset print (13C1429h)EDIT: I viewed the code at address 013C4F10 and the compiler is apparently inserting a "jmp" instruction at that address.
013C4F10 E9 C7 3F 00 00 jmp print (013C1429h)There is actually a whole jump table of every method in the .exe.
Can someone expound on why it does this? Is it a debugging "feature" ?
381k53 gold badges759 silver badges1k bronze badges
8
I'm going to hazard a guess here, but it's possibly to enable Edit-and-Continue.
Say you need to recompile that function, you only need to change the indirection table, not all callers. That would dramatically reduce the amount of work to do when the Edit-and-Continue feature is being exercised.
4 Comments
@Martin: no, the function pointer always points to the jump table, so that when edit and continue recompiles the function, only the jump table gets modified. The function pointer value does not change, ever. That's the beauty of it, really. Imagine your code stores a function pointer somewhere in memory. Edit and Continue has no way to update that. But by pointing it to a jump table, modifying the jump table catches all the potential usages of the function at once.
2010-03-21T14:50:43.207Z+00:00
The compiler is inserting a "jmp" instruction at that address to the real method.
013C4F10 E9 C7 3F 00 00 jmp print (013C1429h)There is actually a whole jump table of every method in the .exe.
It is a Debugging feature. When I switch to release mode the jump table goes away and the address is indeed the actual function address.
Explore related questions
See similar questions with these tags.
