Click here to Skip to main content
16,012,843 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Setting up CListView Properties Pin
Aaron Schaefer5-Feb-02 12:29
Aaron Schaefer5-Feb-02 12:29 
GeneralRe: Setting up CListView Properties Pin
Michael Dunn5-Feb-02 13:09
sitebuilderMichael Dunn5-Feb-02 13:09 
Generalchecking first char input be4 reading the rest Pin
5-Feb-02 10:18
suss5-Feb-02 10:18 
Generalhere is my code Pin
5-Feb-02 10:24
suss5-Feb-02 10:24 
GeneralDebugging Pin
Paul M Watt5-Feb-02 13:21
mentorPaul M Watt5-Feb-02 13:21 
GeneralRe: Debugging Pin
5-Feb-02 16:21
suss5-Feb-02 16:21 
GeneralRe: Debugging Pin
Christian Graus5-Feb-02 18:43
protectorChristian Graus5-Feb-02 18:43 
GeneralRe: Debugging Pin
Paul M Watt5-Feb-02 19:45
mentorPaul M Watt5-Feb-02 19:45 
I would just like to add a little more detail to what Christian G (CG). said.

I assume that you are running your programs right now by clicking the icon with the !. This simply runs the app. like CG said, run your application by hitting the F5 key instead. You could also go to the Build menu, and select Start Debug. There are a lot of other useful commands on this menu.

When you know that you have a trouble area in your program, go to the line of code where you think that the problem is starting and hit the F9 key. Like CG said, this will set a breakpoint. A the program will halt its execution when it reaches this point.

At this point you can move your cursor over any variable to see what values they hold. There are a number of windows that you will want to open from the debug menu in order to get important information from the debugger.

The watch window will allow you to type in any of the variables that are in the current scope, or function, and you can see the values that they hold. If you have a class or a struct this is a really nice window because you can view all of the data member values of the object.
You can change the value of a variable in the right hand side of the watch window. This is very useful if you want to change the or set the value of a variable while debugging, with out writing code, or if you want to see how this new value will affect code execution.

The variables window will show all of the variables that are currently being used on the current line. Just like the watch window, you can change the value of the variables in the right hand side of the window.

You probably will not have to worry about the registers window for right now unless you learn more about x86 assembly. However the EAX register is the register where return values are always sent. So if you call an API function, but do not store the return value with a variable in your program, you can check this register.

The memory window is good for checking the memory at a particular address. So if you have a pointer and you want to see what memory it points to, type in the variable name in the address section, and dereference it ex. *lpString.

The call stack window is helpful to see what function calls have led upto the current function. You can also click on one of the previous lines in the call stack window to set the current debug context to one of those other functions. This will allow you to check variable values in a different function call that is on the stack. Some times you can uncover problems that happened in a previous function that caused problems later on.

Just like the registers window, you will not have to worry about the disassembly window until you learn more about x86 assembly.

A few more tips:

You can step to the next line of code with F10.

You can skip over a function call with F11.

If you want to stop execution of a program that is currently being debugged, hold Shift + F5.

You can set the current execution point by setting the caret to the line that you want to execute from and right click to get the context menu and select "Set Next Execution Point". This is very useful when you execute a statement with a wrong value and then you want to change the value in the watch window and re-execute a piece of code. Or if you want to skip over an entire section of code.

The most important thing of all, say you have a breakpoint set. The execution of your program has halted at that breakpoint, and you step through your program with F10. You finally find the problem, you can directly edit you code, make the one line fix or what ever the simple problem may be, hit F10, and Dev Studio will has if you want to edit and continue. If you choose yes, it will recompile your code, and you can continue executing the program from the same point without restarting the program. This works in most cases, but the compiler cannot recover after all of the changes that you make. SO you will want to limit this feature to small changes in your program.

I know there is alot of information here, and it may take you some time to get comfortable with all of the things that I have explained here, however these are the bare essentials to debugging in Dev Studio, and I stringly suggest you learn and use every one of these features. It will help you find problems quicker and you will learn your code faster as well.

I know there are a few other things that I left out so if anyone thinks that I left out anything important please add to this.
GeneralRe: Debugging Pin
5-Feb-02 20:59
suss5-Feb-02 20:59 
GeneralTemplate specialization Pin
User 98855-Feb-02 9:55
User 98855-Feb-02 9:55 
GeneralRe: Template specialization Pin
Joaquín M López Muñoz5-Feb-02 10:11
Joaquín M López Muñoz5-Feb-02 10:11 
GeneralRe: Template specialization Pin
User 98855-Feb-02 10:36
User 98855-Feb-02 10:36 
GeneralRe: Template specialization Pin
Joaquín M López Muñoz5-Feb-02 10:41
Joaquín M López Muñoz5-Feb-02 10:41 
GeneralRe: Template specialization Pin
User 98855-Feb-02 12:29
User 98855-Feb-02 12:29 
GeneralRe: Template specialization Pin
User 98855-Feb-02 10:34
User 98855-Feb-02 10:34 
Generalhere is the input i'm having trouble reading Pin
5-Feb-02 8:49
suss5-Feb-02 8:49 
GeneralRe: thank you but... Pin
Joaquín M López Muñoz5-Feb-02 9:14
Joaquín M López Muñoz5-Feb-02 9:14 
GeneralRe: thank you but... Pin
5-Feb-02 9:55
suss5-Feb-02 9:55 
GeneralRe: thank you but... Pin
Christian Graus5-Feb-02 9:57
protectorChristian Graus5-Feb-02 9:57 
GeneralRe: thank you but... Pin
5-Feb-02 10:15
suss5-Feb-02 10:15 
GeneralRe: thank you but... Pin
Christian Graus5-Feb-02 10:33
protectorChristian Graus5-Feb-02 10:33 
GeneralRe: thank you but... Pin
User 98855-Feb-02 10:46
User 98855-Feb-02 10:46 
GeneralRe: thank you but... Pin
Christian Graus5-Feb-02 10:52
protectorChristian Graus5-Feb-02 10:52 
GeneralRe: thank you but... Pin
5-Feb-02 10:53
suss5-Feb-02 10:53 
GeneralRe: thank you but... Pin
Christian Graus5-Feb-02 11:04
protectorChristian Graus5-Feb-02 11:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.