Menu

RT: Getting Started With The Debugger

Wayne Keen
2004-03-07
2012-09-26
  • Wayne Keen

    Wayne Keen - 2004-03-07

    Basic Debugging - Getting Started:

    OK, first, below is some simple code. Nothing special, after all, I wrote it. Now, the first thing I do, before I do anything having to do with the debugger is I set a couple of compile options. Since I am not compiling this as a project, but just as a single file, I went to

    Tools:Compiler Options:Compiler:Add The Following Cammands When Calling The Compiler

    and added

    -g3 -O0

    The first command generates maximum symbol table information to support debug operation, the last turns OFF optimization.

    So now, I go to Execute: Compile on the following promised simple code:

    #include<iostream>
    using namespace std;
    int main(void)

    {
    int j;
    for (int i = 0; i <= 10; i++)
    {
    cout << "This is what that idiot wayne said to do\n";
    j = i + 3;
    }
    system("pause");
    return 0;
    }

    Here is my compile log:

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\mycstuff\detest.cpp" -o "C:\mycstuff\detest.exe" -g3 -O0 -traditional-cpp -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    Execution terminated
    Compilation successful

    (Your compile log is always useful when you have a problem, remember to post it all, like this, and not just any errors)

    Now, before I go to the debugger, theres one more thing I will do. I will click in the little "gutter" to the left of the code, in this case, I chose the cout line of code. When I click in the right place, the line turns red, and little red circle with a green checkmark appears in the gutter. I have set a breakpoint to stop the code at the cout statement.

    Now, I fire up and start the debugger by going to

    Debug:Debug

    This starts the code up, and it runs to my breakpoint. Now, the breakpoint line, which was red, turns blue. Now, suppose I want to put some watchpoints on some variables. If I hold my cursor over the variable "i", a watch appears in the debug window to the left of the code stating

    i = 0

    Do the same to j, and I get another watch that states:

    j = 4370436

    You, the astute observer will have already noticed that j has not been assigned yet, so what I am seeing is garbage in the memory location for j.

    Now, if I got down to the bottom, and hit "Next Step", the blue line moves down one line, and now I have a red and a blue line. j still has its non-sense value, as the debugger has stopped before the line of code is executed. One more "Next Step", and the debug window has

    i = 0
    j = 3

    And you can hit continue, to take you from breakpoint to breakpoint....the sort of stuff you should be comfortable with.

    Did this get you started? If you are still having problems, try to be specific about what you did, what you did it to etc...

    Wayne

     
    • Nobody/Anonymous

      Here is my output from debug window:
      Reading symbols from c:\cpp\myserver.exe
      done
      frames-invalid

      compiler options are correct but i'm not able to debug

      Piotr

       
    • Wayne Keen

      Wayne Keen - 2004-03-24

      If you have a question, please start a new thread, and give the basic information discussed in the link about how to ask a question in the "Forum FAQ" thread please.

      Keep in mind a simple example is the best wat to get help...

      Wayne

       
    • Nobody/Anonymous

      Are there any special considerations for Win32 GUI Programs ? I am writing a wx-Widgets app, but I cannot seem to get the debugger operating correctly.

      Difficult to give a code example.

      I appear to be setting breakpoints, but then pressing 'debug' just runs without stopping. When I do manage to get it to stop on sections of code, I clear the breakpoint, but pressing 'Continue', when that particular function being debugged is entered again causes the 'cleared' breakpoint to appear again....

      Not sure how to explain this better, or what to do.

      I CAN get simple console examples to debug properly though.

       
      • dododeu

        dododeu - 2007-11-23

        i have read the basic3 and searched on the forum for this problem
        but i didn't find something helpful
        win xp , dev-cpp 4.9.9.2

        i can't get the debugger go step by step,
        i have put breakpoint ,it doesn't stop till the end

        is the some problem like this guy:

        Are there any special considerations for Win32 GUI Programs ? I am writing a wx-Widgets app, but I cannot seem to get the debugger operating correctly.

        Difficult to give a code example.

        I appear to be setting breakpoints, but then pressing 'debug' just runs without stopping. When I do manage to get it to stop on sections of code, I clear the breakpoint, but pressing 'Continue', when that particular function being debugged is entered again causes the 'cleared' breakpoint to appear again....

        Not sure how to explain this better, or what to do.

        I CAN get simple console examples to debug properly though.

         
    • Nobody/Anonymous

      The debugger is shit.

       
    • Nobody/Anonymous

      When I run the example I get the same log as you got. But when I try to run the program it gives error 'source file not compiled' .
      I re-run compile. Same thing. Help!
      JRH

       
      • Wayne Keen

        Wayne Keen - 2006-08-05

        JRH,

        A couple of post above yours is a post that asked you to not ask a question on this thread, please start a separate thread.

        Thanks,and when you do, please post your Basic 3, and what you did to compile...

        Wayne

         
    • Nobody/Anonymous

      To get this to work I had to do:

      right click the project name:project options:parameters

      and add the -g3 -O0 there.

      Changing it in the Tools menu did not give the desired compile log. The log I got after my changes is:

      Compiler: Default compiler
      Building Makefile: "C:\rw778grafika\temp\Makefile.win"
      Finding dependencies for file: C:\rw778grafika\temp\testdebugger.cpp
      Executing make...
      make.exe -f "C:\rw778grafika\temp\Makefile.win" all
      g++.exe -DDEBUG testdebugger.o -o "debugtest.exe" -L"C:/Dev-Cpp/lib" -g3

      Execution terminated
      Compilation successful

      Perhaps I wasn't supposed to use a project, but I cant get Devc++ to compile a standalone file...

       
    • pronecracker

      pronecracker - 2006-08-07

      Wayne asked you to start a new threat!

       
    • pronecracker

      pronecracker - 2006-08-07

      On the other side, this useful threat is at least visible now..:P

       
      • Wayne Keen

        Wayne Keen - 2006-08-07

        It doesn't have to be visible - it is linked through the thread "Please Read Before Posting a Question"

        Wayne

         
    • Wayne Keen

      Wayne Keen - 2007-11-24

      Threads that start with RT are not the appropriate venue for asking questions.

      Please go back to the original thread you started and post your Basic 3.

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.