【问题标题】:Why doesn't VS2015 debugger show the function address correctly in the watch window?为什么 VS2015 调试器不能在监视窗口中正确显示函数地址?
【发布时间】:2018-01-29 14:50:47
【问题描述】:

Visual Studio 2015 调试器中的 C++ 代码。平台:Window 10

监视窗口显示:

名称:functionPointer :0x012812d0 类型:void(*)(float)

名称:printStuff :0x01282440 类型:void(float)

名称:&printStuff :0x01282440 类型:void(*)(float)

但是,输出窗口显示:

函数指针 = 012812D0 printStuff = 0x012812D0 &printStuff = 0x012812D0 这是打印功能

#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;
}

输出

【问题讨论】:

  • 请显示文本而不是图像(Visual Studio 允许您从监视窗口复制文本)
  • @P.Zhang 请不要将冗长的信息放入 cmets 但edit您的问题。
  • 监视窗口显示: 名称:functionPointer 值:0x012812d0 {jan29.exe!printStuff(float)} 类型:void()(float) 名称:printStuff 值:0x01282440 {jan29.exe !printStuff(float)} 类型:void(float) 名称:&printStuff 值:0x01282440 {jan29.exe!printStuff(float)} 类型:void()(float) 但是,输出窗口显示:“functionPointer = 012812D0 printStuff = 0x012812D0 &printStuff = 0x012812D0 这是打印功能”
  • @MichaelWalz 是的,但是踏入它不会导致您进入printStuff,而是通过一条jmp 指令进入调度表条目,该指令将导致printStuff
  • @VTT 我做到了这一点,并验证了发布中没有发生这种情况。所以我们得到这种行为似乎很好。但是,为什么它在调试中使用调度表 - Edit&Continue(逻辑怀疑)似乎并非如此。

标签: c++ visual-studio visual-studio-2015


【解决方案1】:

这种行为似乎是因为增量链接。当它被启用时,该函数被组装在一个内存地址中,另一个地址包含一个跳转表条目,其中一条跳转指令指向“真实”地址。该函数总是通过调用跳转表来调用。如果您禁用增量链接,则通过跳转表的“绕道”消失,并且您的示例案例仅显示一个地址。

其他所有东西似乎都显示了跳转表的地址,但 'printStuff' 和 '&printStuff' 监视表达式显示了函数代码所在的实际地址。

另请参阅: jump stubs in PE files

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-21
    • 2015-07-15
    • 2014-09-25
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    相关资源
    最近更新 更多