Thread: Debugging Dev C++

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    58

    Debugging Dev C++

    Hi all,

    Im currently new to Dev C++, and im stuggling a little. I am able to write and compile a win console C program, but i am unable to get the debbuger working.

    I have had a read of some of the articles on the net, and many people mention, ""Go to Compiler Options and click on the Linker sheet. Now check 'Generate debugging information'. Do a 'Rebuild All' and you should be able to debug now""

    However after enableing this feature, when my program is put in debug mode and error is displayed "" Unable to generate debugging information"". Below are my steps to debugging a program:

    1) compile the c source code.

    2) right click on variable, and add a watch.

    3) selct debug pink arrow.

    4) error is show??

    Please can you number me some steps to watching a variable.

    Thanks tuurbo46

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Stepping, watching variables, etc, only works if the program is running.

    Set a breakpoint on main, and then choose Compile and Run from the Run menu. Then, once the console window appears, you can set a watch and do whatever you like.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    I don't know if you can even debugg in dev, having you tried searching "debugging in dev-c++" in google?

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, you can; although (as with debugging with any debugger) if optimizing is turned on, the current line can jump around a lot, which is very confusing. If you're debugging, turn off optimizations.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Hi,

    Thanks for the speedy reply. I usually debug by printing the output to the console window, but i thought i would start to learn how do debug properly.

    I will implement your changes and see how i get on.

    Lastly i bought an orignal copy of visual studio 6 c++ at a car boot sale. Would you say this is better than dev c++?

    cheers tuurbo46

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by tuurb046 View Post
    Hi,

    Thanks for the speedy reply. I usually debug by printing the output to the console window, but i thought i would start to learn how do debug properly.

    I will implement your changes and see how i get on.

    Lastly i bought an orignal copy of visual studio 6 c++ at a car boot sale. Would you say this is better than dev c++?

    cheers tuurbo46
    Debug by printf can be very powerful - it's certainly often faster than stepping through oodles of code, so works well if you know roughly where the problem is.

    But single-stepping through code and whatching variabels is also useful. But a debugger will not "find bugs" for you - it just allows you to see step by step what is happening in your code - you still have to figure out what is wrong with it...

    As to which compiler/IDE is better, it depends on who you ask, what the person's preference is. Microsoft certainly have a pretty slick and comprehensive product. But it's not the "latest" version in version 6 - the current version, I believe is 8 or 9. (I use Version 7 "Visual studio .Net" when I do Windows stuff, gcc for Linux-type-stuff).

    gcc, which is the compiler behind Dev, is a very good compiler for sure, and a recent gcc version will have a more modern compiler than Microsofts version 6.

    I have never used Dev itself, as I tend to use Emacs as my "IDE".

    --
    Mats

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you want to try out the latest Microsoft Environment, you can actually get a "Visual Studio Express" as a free downoad from Microsofts website - go to Microsoft.com and search for "visual studio express download". It's not a SMALL download, if I remember right, but not hideously large either.

    It's not got all the tools and utilities that are in the "commercial" package, but it's good enough for most non-commercial development you may want to do.

    --
    Mats

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I much prefer Dev-C++. MSVC 6 is so old that variables declared in for loops have their scope extended past the end of the for loop. That is, you can do this:
    Code:
    for(int x = 0; x < 10; x ++) {
        std::cout << "Number " << x << std::endl;
    }
    
    std::cout << "Did " << x << " numbers." << std::endl;
    It's most annoying when you have several loops with the same counter, like this:
    Code:
    for(int x = 0; x < 10; x ++) {
        /* ... */
    }
    
    for(int x = 0; x < 10; x ++) {
        /* ... */
    }
    MSVC 6 refuses to compile that, because it thinks you're going
    Code:
    int x;
    for(x = 0; x < 10; x ++) {
        /* ... */
    }
    
    int x;
    for(x = 0; x < 10; x ++) {
        /* ... */
    }
    which is a redefinition of x. There are lots of other problems with MSVC's compatibility. And I'm not aware of any compatibility problems with the latest version of Dev-C++'s gcc.

    But that's just my opinion.

    [edit] The Express edition of Visual Studio probably has better standards-compliance, but it doesn't come with an IDE. If you wanted to use it, you could perhaps download Code::Blocks (which I think can use MS compilers), or maybe configure MSVC 6's IDE to use the Express compiler. [/edit]

    Also, did you mean, a better compiler (i.e., more standard-compliant, better optimisations, etc) or a better IDE (i.e., fancier interface, code completion, etc)? I was assuming you meant the former.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    the Visual Studio Express is a complete IDE - because I downloaded it at work some time ago, and it definitely has an IDE - I even used it for the simple program I wanted to write (all of ten lines or so). I didn't do much more than that, because I didn't need it for anything else.

    [It is not legal to use the Express version to produce commercial code, but I took the approach that if I wanted to write a little tiny program to TEST something in a virtual machine, where the test code is just for my use within the company, it's probably not qualifying as "commercial code" - and it would have taken me about three weeks to get the approval of buying the $500 licensed version... ]

    --
    Mats

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by matsp View Post
    [It is not legal to use the Express version to produce commercial code, but I took the approach that if I wanted to write a little tiny program to TEST something in a virtual machine, where the test code is just for my use within the company, it's probably not qualifying as "commercial code" - and it would have taken me about three weeks to get the approval of buying the $500 licensed version... ]
    I'd say if it's used for a business purpose, it is quite clearly commercial code.

    Honestly, I would never do anything like that. Why should you take personal responsibility for breaking the license while your boss reaps the benefits? If something were to happen, he could just say you did it of your own volition (which you did). He gets paid, you get screwed.

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Hi,

    Thanks for all your help and adice. I now have the debugger going.

    Thanks again

    Tuurb046

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  2. Any tutorial about Dev C++ debugging feature?
    By asmileguo in forum C++ Programming
    Replies: 11
    Last Post: 09-09-2006, 06:59 PM
  3. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  4. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 01:05 AM
  5. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM