Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working in MFC application which has lots of dialog box. I am not able to tell which class or function created dialog box while debugging.

To illustrate the problem I have created a simple Dialog based MFC application. Run it in debug mode and pause the debugging.

I can see DoModal is called in call stack using CDialog::DoModal(). How do I understand exactly which function and from which class this DoModal() is getting called?
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jan-15 11:29am    
How come? Call stack shows you everything. Maybe you also need to stop in proper place.
—SA
kpranit 7-Jan-15 11:34am    
Call stack shows me CDialog::DoModal() call, but which Dialog, like all dialog in MFC is derived from CDialog, we have 100s of dialog in our application, exactly which dialog is launch that detail I do not get in Call Stack.
Sergey Alexandrovich Kryukov 7-Jan-15 11:47am    
100s dialog classes or 100s dialog instances (why so many? :-)?
—SA

1 solution

Please see my comment to the question. Probably, you need to set a break point at certain place. Isn't it obvious that "Call stack" shows all calls up the stack, not down? I hope you understand it and can see from this debug window. It means, it shows you the calls which already led you to the break point, all calling functions. You cannot see what is called from a given point; essentially, what you need to see wasn't yet called. You can follow the execution using step-by-step debugging, but it may take too much time.

So, you have to put break-point to all places where CDialog::DoModal and examine the instance in all case, but it also might become too long. So, as you have (as far as I could understand), different dialog classes, you have to put a break point in some method of each class. But where? I guess, the problem is that this method is in the base class, so you cannot put different break points on your different terminal classes. What to do?

You can add some code specially for debugging. Pay attention that CDialog::DoModal is a virtual method:
http://msdn.microsoft.com/en-us/library/619z63f5.aspx[^].

It means that you can override it in all your dialog classes in question, just for debugging purpose. Write some trivial implementation calling the base's CDialog::DoModal. The only purpose of it is to put a break point on this line, for each of your classes. This way, you will see where the calls are dispatched on certain action.

I tried to explain only some of the basic debugging technique; and they are not so easy to explain. It's easier to invent a debugging technique then to explain how it works in simple words, without demonstrating it. There are many others. They come up with some experience and logical thinking during debugging. Generally, try to do more analysis and logical thinking and less attempts, less of trial-and-error operations.

—SA
 
Share this answer
 
v2
Comments
kpranit 7-Jan-15 11:54am    
Your answer is good, but it will not solve my problem.
Sergey Alexandrovich Kryukov 7-Jan-15 11:56am    
Not sure, maybe it will. Why not? Maybe I'll think of something else...
—SA
kpranit 7-Jan-15 11:59am    
+5 No doubt your answer is helpful. I was thinking my problem will be solved by debugger, you suggest it should be solved by logic.
Sergey Alexandrovich Kryukov 7-Jan-15 12:02pm    
No. You consider "by debugger" and "by logic" as alternatives, which is just funny.
Anyway, you did not answer my "why not" question, so it's hard to continue from this point...
—SA
Albert Holguin 7-Jan-15 20:49pm    
A good combination of the call stack and adding breakpoints at different places should allow you to narrow down the location of the call and thereby the class/instance. Heck, I've found memory leaks by getting creative with breakpoints.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900