Thread: What is "Debugger"?

  1. #1
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008

    Question What is "Debugger"?

    Hi all,
    I have learned C++ for 2 years and my skills are currently very good (I think, ).
    But during my learning way I never used the "Debugger" to debug the program. Simply, when there was some error, the compiler showed me where (usually at some line) was the problem and then I fixed it.

    But what the h**l is the "Debugger"?
    Because I have absolutely no idea how it can work.

    Could anybody explain me "in few words" this problematic, or if it cannot be explained "in few words", just write here about some book about debugging?

    Thanks in advance.

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    Basically, there are two types of errors.
    Compile-time errors are found by the compiler. They are easy to fix.
    Run-time errors, however, are more difficult. The compiler won't find them for you. For example, one type of run-time error is a crash. Bad pointer, for example. Memory corruption.
    To find these types of errors, we commonly use a debugger, a tool that helps us detect and fix these errors.

    My favorite debugger is Visual Studio's debugger. Very powerful and flexible.
    I could write an entire guide on how to debug and different techniques and such.
    The most common are breakpoints and step-by-step execution. Breakpoints halt execution when a criteria is met (memory location X is written or read; line X is reached; the value of variable X has changed, etc). Step-by-step execution allows you to execute lines one-by-one to "step" through your program and find errors.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    The debugger, in essense allows you to view what your variables are, set a breakpoint to stop when a condition is met (such as getting to a particular line is reached).

    Single-stepping is a very good way to discover the flow of your code. You can do that by hand, by using the "pretend to be a computer" method, but it's easier if you use a debugger to just press F10 (or whatever) to step to the next line. You can choose to step in to functions to see what happens in the function, or just continue in this function onto the next line "fast-forwarding" the function call (the function is still called, but you will not have to step through the function).

    Sometimes, you can also change the value of a variable. Say you have made a mistake that gives you the wrong value on a bool variable. Instead of stopping, repairing the code, compiling again, and then find that you have another mistake 3 lines further down, you can change the bool to the correct value, and then continue the execution with the new value.

    One of the most powerful features is that if you have a crash in the code, you can look back at how you got to that point, and most of the time, you can inspec the variables that are in the functions that you passed one the way to the failure and realize that "if i is greater than MAX_VALUES here in func1, then we read outside of the array, and get some rubbish, which causes invalid data to be used in func2, which leads to a divide by zero error in func3." So you can quite easily catch what went wrong, and see how to fix it without recompiling the code with a huge number of print-statements to figure out where it goes wrong.

    Edit: If you are usign gcc, there is "Gnu DeBugger", gdb that you can use. If you are using Visual Studio, the debugger is integrated into the Visual Studio toolchain, so you just press some slightly different keys.

    Last edited by matsp; 09-26-2008 at 07:42 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Thank you both for nice explanation.

Popular pages Recent additions subscribe to a feed