3

I've got a DLL with following class:

Cat.h:

#ifndef CAT_H
#define CAT_H

class __declspec( dllexport ) Cat
{
    class CatImpl;  // Not defined here
    CatImpl *cat_;  // Handle
public:
    Cat();
    int a;
}; 

#endif

Cat.cpp:

#include "Cat.h"

class Cat::CatImpl
{
public:
    int c1;
    int c2;
};

Cat::Cat()
{
    cat_ = new Cat::CatImpl();
    cat_->c1 = 1; 
}

Then I've got a project(in separate solution) creating an instance of this class:

Main.cpp:

#include <Windows.h>
#include "..\..\DLL\DLL\Cat.h"

int CALLBACK WinMain(
  _In_  HINSTANCE hInstance,
  _In_  HINSTANCE hPrevInstance,
  _In_  LPSTR lpCmdLine,
  _In_  int nCmdShow
)
{
    Cat cat;
    int x = 0;
}

Now I'm placing a breakpoint at the line:

int x = 0;

and open Quickwatch window: image

Symbols are loaded and *(cat.cat_) doesn't work:

image

Is there any way to view the contents of cat_?

The only way I have come up with so far is:

(int)(*((char*)cat.cat_ + 0))

Also why is the following returning 0?:

image

Community
  • 1
  • 1
stiopa
  • 137
  • 9
  • Have you tried `*(cat.cat_)`? – kol Apr 09 '14 at 19:38
  • Have you loaded symbols for the library? I mean the part _not defined here_. – W.B. Apr 09 '14 at 19:38
  • At the point you show there aren't any contents. You have to create a new instance of `Cat::CatImpl` first. Try 'step into' ... – πάντα ῥεῖ Apr 09 '14 at 19:40
  • I've edited the post, nothing works. – stiopa Apr 09 '14 at 19:51
  • @stiopa It really looks that debug symbols for the interns of your DLL aren't available when you're debugging. – πάντα ῥεῖ Apr 09 '14 at 20:04
  • Is the .pdb for the DLL in the same directory as your DLL. – cup Apr 09 '14 at 20:11
  • πάντα ῥεῖ: what do you mean by " interns of your DLL aren't available when you're debugging"? The DLL with Cat class is DLL.dll and it says that the symbols are loaded? Unless I'm missing something? cup: yes pdb is in the same dir as DLL.dll – stiopa Apr 09 '14 at 20:16
  • 1
    @stiopa If the symbols are loaded, you should be able to set a breakpoint on `new CatImpl()` and step into the constructor from there (if you have a non default one). If you're not able to do that and have a non default constructor, then you're missing debug symbols. – W.B. Apr 09 '14 at 20:42
  • @W.B: I can step into the constructor and see the value of c1 from there, but the question is how do I see that value without having to step into the constructor? The only way I have come up with is looking at the pointer address in the Memory window, which is easy in this simple example, but not that simple in a real situation I need to use it in... – stiopa Apr 09 '14 at 20:51

1 Answers1

1

A workaround for this is to add a watch on the value, where you "cast" it to the DLL that contains the impl. So in your case that would be.

(DLL.dll!Cat::CatImpl*)cat.cat_
Chronial
  • 66,706
  • 14
  • 93
  • 99