On debugging...

I guess this is really more of a programming question than a Linux question, but since Linux is pretty much the programmer's OS (for all its great tools) here goes...

Back in the day when I was programming in c/c++ in school, we used a windows IDE called CodeWarrior. Hopefully some of you are familiar with it? The thing that I really loved about that IDE is that it came with an awesome graphical debugger that allowed you to set breakpoints, run one statement at a time, run blocks of code, view the contents of all the program variables, etc. etc. . I am wondering if there is something analogous to this under a Linux environment (CodeWarrior is antiquated and freaking expensive!)? I am aware of several different debuggers in linux, but I am not sure which have GUI and which ones are easier to use or more powerful or what.

Also, if someone could point me towards some good resources on how to debug w/o all the graphical frills, I would like that. As it stands, I don't know the first thing about gdb, but I would kinda like to learn to write all my programs in vi, compile them on the command line w/ gcc and then debug w/ gdb. I guess by the time I could do that, I could consider myself a level two hardcore Linux badass! :wink:

Thanks for any help that you may or may not give me :D


P.S. In order that my earlier comment not sound too cocky, I am certain there are like 80 levels to being a hardcore Linux badass, and I only reached level one after learning how to install programs by compiling from source rather than via package managers. 8)
20 answers Last reply
More about debugging
  1. :-D

    I guess eclipse is one IDE and kdevelop another

    and then there's about a million more....


    Check to see which ones are apt-getable or yumable on your distro and give them a try!
  2. Check out DDD


    and this quick and dirty cheat sheet for GDB


    GL :-D
  3. Those are fine suggestions from linux_0. I only chime in to add my thoughts/experiences on the subject.

    I personally use Eclipse with the CDT (or C/C++ Developer Toolkit). This allows the autogeneration of Makefiles (or the use of manually-created/pre-existing ones) for easy distribution as a source package as well as hooking into gdb in any guise it may have (for example, avr-gdb/avarice for Atmel microcontroller debugging over JTAG or arm-gdm for debugging over a serial or ethernet connection, can you tell I like embedded work?), as well as allowing you to choose different compilers (again, allowing for easy cross-platform dev work).

    In regards to debugging, you can easily set and clear breakpoints simply by double-clicking the area next to a line that indicates whether there's a breakpoint there or not. A blue dot appears, indicating that you've set a breakpoint.

    You can then run the program under the chosen debugger and it gives you access to the contents of variables either by a window that has the current function's variable list or simply by overing the cursor over the variable in question. You can modify the value of a variable in-debug to correct for an error or test for other conditions.

    I haven't used KDevelop much, but I have heard great things about this IDE as well, so try a few out and see what works for you, as linux_0 suggested.
  4. thank you all for your help and suggestions :D. Someday I hope to learn to be a real guru and only use printf() to debug :wink:

  5. Quote:
    Someday I hope to learn to be a real guru and only use printf() to debug

    Ha, it's funny, that's how I started programming and debugging, I then learned how to use debugging tools, and in order to do kernel dev I use the kernel equivalent of printf (namely printk). Basically, find a tool that works for the job and use it.
  6. :lol: :lol:

    You mean every other line in your C and C++ programs isn't supposed to be an fprintf(); or cout <<endl; ?

    That's news to me.

  7. I know that in java the equivalent of printf() -- that is before they actually added printf() in 1.5 -- is System.out.println() and for debugging purposes you have Debug.print(). Although I have never used it before, I know that when you type the latter statement, it wont print that statement unless you explicitly turn on "debug mode". Is there somethign analogous to this in c/c++?

  8. I'm a poor man :(

    I'm learning VB .NET.... Find it suprisingly good to use. Shame I cannot use it for linux :cry:
  9. I am not certain i understand what you mean by that last comment. How is it that learning VisualBasic.net makes you poor?

    Also, I have never actually used visualbasic in any of its iterations. The last time i did programming in basic was several years ago on our old 486 in windows 3.1 on QBASIC. :wink:


    P.S. I am very excited because I just figured out how to get VI to do syntax highlighting for source code just like gedit has been doing. With this, I am one step closer to leaving gedit for vi.
  10. You can with mono however native languages tend to work a bit better and are more appropriate for most tasks.

    *sh, *csh, perl, php, python, tk/tcl can handle most scripting needs

    If you need to bring in the heavy guns native C and C++ are also available.

    You can also use java if you want / need to along with Pascal, Fortran, and a bunch of languages I'm forgetting.


    I'm a poor man :(

    I'm learning VB .NET.... Find it suprisingly good to use. Shame I cannot use it for linux :cry:
  11. The version of such a system in C/C++ is as follows

    #ifdef debug
    printf("Some debug message\n");

    Compile with -Ddebug, and all of the debug statements will show up; don't and they disappear. Not as fancy as java, but works quite well.
  12. Thanks! I am going to have to keep that little trick in mind. :D

  13. I've tryed learning a bit of python, but it just seems confusing to me. the commands just don't hold any meaning to me. I found VB .NET extremely simple to learn, commands and code are easy to remember and it's easy to debug.

    I just downloaded the Visual Studio 2005 Express of the M$ site and have had a lot of fun with it. Including using some script and some thinking to dial a number on my mobile phone via AT Commands sent through serial bluetooth to my phone :)

    Each time I look at Python or C/C++, I just get lost.... Maybe I'm just not ready for it....

    @Zorak: I said I was poor because I use VB .NET and a lot of people seem to demonize it because it's M$. I would like to use python, since it runs native in linux, but I just get confused and struggle. VB .NET I had my first program running in a day, which was a barcode scanning program, that recorded the barcode, quantity and then wrote it to a CSV file.... I had trouble getting python to work as a calculator using 'case' functions. :cry:

    Maybe someday my brain will work with Python...
  14. I would recommend perl / php and shell for you then.

    They are much friendlier than python :-D

    use strict;
    use Win32::NetAdmin;
    use Net::SMTP;

    my $dc = "\\\\x";
    my $from = 'x@x.com';
    my @recip_list = ('x@x.com', 'y@y.com');
    my $smtp_host = "x.x.x.x";
    my @users = ();
    my $VERSION = "1.2";

    my $smtp = Net::SMTP->new($smtp_host, Timeout => 30) || die "Can't connect to $smtp_host.\n";

    $smtp->mail($from) || die "cannot mail from.\n\n";


    $smtp->datasend("To:\tPerl Recipients\n");
    $smtp->datasend("Subject:\tPerl output of Users in the domain\n\n");

    Win32::NetAdmin::GetUsers($dc, undef, \@users) || die "GetUsers failed.\n";

    foreach (@users) {
    $smtp->datasend( "$_\n\n");


    =head1 NAME

    adminmail - This script grabs a list of all the users in a domain and emails the results to an email address.

    =head1 DESCRIPTION

    This program is useful for quickly getting a list of all the users on your domain. I wrote this program when our Notes
    administrator "Maddog" needed a list of users on the domain.

    =head1 README

    This script grabs a list of all the users in a domain and emails the results to an email address.


    This script has a few requirements. You will need the Win32::NetAdmin and Net::SMTP modules.
    You will also need to change the values for dc, from, recip_list, and smtp_host.



    =pod OSNAMES







    $timeout = 3;
    $old = ini_set('default_socket_timeout', $timeout);
    $file = fopen('http://example.com', 'r');
    ini_set('default_socket_timeout', $old);
    stream_set_timeout($file, $timeout);
    stream_set_blocking($file, 0);
    //the rest is standard



    echo "hello world";

    ls -al |sort -k 5 -r -n

  15. oh ok. Well, i have never used visual anything by M$. Not so much out of principle but because when I was learning programming, we always just used different IDEs than Visual studio. As for c/c++, it really isn't that hard to pick up. The hard part might be to make yourself think in terms of Object Oriented Programming, but that will be OK after you have some practice. Also, if you know java, it makes c/c++ much easier to pick up.

  16. Linux_0, allow me to submit the following:

    Wow, that perl looks horribly complicated and unlike my beloved C/C++/Java :P

  17. Some clever code from down under along with other examples :-D



    use Image::Magick;

    use warnings;
    use strict;

    my $dir = '/Users/peter/images';
    my $pdffile = '/Users/peter/newsletter.pdf';

    chdir( $dir ) or die "Cant chdir to $dir $!";
    while( <*.gif> ) {
    push @files, $_;

    my $pdf = Image::Magick->new();

    foreach $file ( sort @files ) {
    my $img = Image::Magick->new();
    $rc = $img->Read( $file );
    warn $rc if $rc;
    push @$pdf, $img;

    $pdf->Write( $pdffile );

  18. PS Perl is written in C integrates well with C and makes it easier to write C :D
Ask a new question

Read More

Programming Linux