Sometimes when you debug applications, it happens that you have got the pointer to class which has few member variables including structures and another class objects! How to look at values of those inner class/structure variable’s members?? So, here is the tip.
Following is the code being used for demonstrating commands.
1: struct testStruct
3: int i;
4: char ch;
5: long l;
6: char* str;
9: class myClass2
14: testStruct structObj;
19: //Do Nothing..
20: char *pStr = new char;
21: sprintf(pStr, "Test Message");
22: structObj.i = 101; structObj.l = 1001; structObj.ch = 'j'; structObj.str = pStr;
27: delete structObj.str;
30: int test2(myClass2* classObject)
32: return classObject->structObj.i;
35: void CWinDbgDlg::OnBnClickedButton2()
37: // TODO: Add your control notification handler code here
38: myClass2 *ptr = new myClass2();
39: int retVal = test2(ptr);
So, what we want to do is, while we break @ test2 function, we want to see in WinDbg whats the value of structObj.str of that instance.
Here are steps which needs to be done in Windbg. Attach the process to WinDbg, break on the function test2 by putting simple breakpoint. Hit kb command to find out the first parameter to test2 function (which is pointer to class object for myClass2).
First parameter to function test2 is, 0x006ab520 (see the third column in first row of call stack above). As you might know, if you want to see member variable of class object pointer, you can use dt command.
But, our goal is to find out whats inside structObj! Well, you can give following command to get that detail,
Notice the difference between last command and one prior to that. We appended “structObj.” at the end. That’s how we can find members inside that structure. Mission Accomplished!!
I know, its really difficult to explain what exactly we are doing, and I think I am trying my best to explain it with the help of snapshot and coding, if you think it can be improved, please let me know..