简体   繁体   中英

Why doesn't VS2015 debugger show the function address correctly in the watch window?

C++ code in Visual Studio 2015 debugger. Platform: Window 10

The watch window says:

Name : functionPointer Value :0x012812d0 Type :void(*)(float)

Name : printStuff Value :0x01282440 Type :void(float)

Name : &printStuff Value :0x01282440 Type :void(*)(float)

However, the output windows says:

functionPointer = 012812D0 printStuff = 0x012812D0 &printStuff = 0x012812D0 This is the print stuff function

#include<iostream> 
using namespace std;
void printStuff(float)
{
    cout << "This is the print stuff function." << endl;
}

const float PI = 3.1415926f;

int main()
{
    void(*functionPointer)(float); // *functionPointer is a pointer
    functionPointer = printStuff;  // *functionPointer point to function printstuff
    cout << "functionPointer = " << functionPointer << "  " << "printStuff = " << printStuff << "  " << "&printStuff = " << &printStuff << endl;
    functionPointer(PI);

    return 0;
}

在此处输入图片说明

Output

在此处输入图片说明

This behavior seems to be because of incremental linking. When it is enabled, the function is assembled in one memory address and another address contains a jump table entry with one jump instruction to the 'real' address. The function is always called by calling the jump table. If you disable incremental linking, the 'detour' via the jump table goes away and also your example case shows just one address.

Everything else seems to show the address to the jump table, but the 'printStuff' and '&printStuff' watch expressions show the actual address where the function code is located.

See also: jump stubs in PE files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM