Visual Studio not able to show the value of 'this' in release mode (with debug information)

后端 未结 8 628
感情败类
感情败类 2020-12-29 11:15

Original question:

Why is the this pointer 0 in a VS c++ release build?

When breaking in a Visual Studio 2008 SP1 release build with the /Zi

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 11:52

    As others already said you should make sure that the compiler does not do anything which can confuse the debugger, optimizations are likely to do. The fact that you have NULL pointer can happen IF you call the function statically like :

    A* b=NULL;
    b->foo();
    

    The function is not static here but called a static way.

    The best spot to find the real this pointer is the take a look at the stack. For non-static class functions the this pointer MUST be the first ( hidden ) argument of your function.

    class A
    {
      void foo() { } // this is "void foo(A *this)" really
      int f_;
    };
    

    If your this prointer is null here, then you have problem before calling the function. If the pointer is correct here then you debugger is kinda messed up.

    I've been using Code::Blocks with Mingw for years now, with the built in debugger ( gdb ) I only have problems with the pointer when I had optimizations turned on, otherwise it always knows the this pointer and can dreference it any time.

提交回复
热议问题