Sign in with
Sign up | Sign in
Your question

On debugging...

  • Programming
  • Linux
Last response: in Linux/Free BSD
May 25, 2007 3:50:35 AM

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)

More about : debugging

a b 5 Linux
May 25, 2007 4:31:49 AM


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!
Related resources
a b 5 Linux
May 26, 2007 4:24:44 PM

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.
May 26, 2007 10:48:05 PM

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:

a b 5 Linux
May 27, 2007 7:20:57 AM

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.
a b 5 Linux
May 28, 2007 10:35:01 AM

: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.

May 28, 2007 8:00:04 PM

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++?

May 29, 2007 12:31:27 AM

I'm a poor man :( 

I'm learning VB .NET.... Find it suprisingly good to use. Shame I cannot use it for linux :cry: 
May 29, 2007 12:37:24 AM

I am not certain i understand what you mean by that last comment. How is it that learning 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.
a b 5 Linux
May 29, 2007 12:54:26 AM

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: 
a b 5 Linux
May 30, 2007 5:36:28 AM

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.
May 30, 2007 6:24:17 AM

Thanks! I am going to have to keep that little trick in mind. :D 

May 31, 2007 3:28:48 AM

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...
a b 5 Linux
May 31, 2007 3:53:02 AM

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 = '';
my @recip_list = ('', '');
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.


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.









$timeout = 3;
$old = ini_set('default_socket_timeout', $timeout);
$file = fopen('', '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

May 31, 2007 3:53:45 AM

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.

May 31, 2007 4:02:06 AM

Linux_0, allow me to submit the following:

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

a b 5 Linux
May 31, 2007 4:24:01 AM

:lol:  :lol:  :lol: 
June 1, 2007 3:21:04 AM

Private Sub TB_Quantity_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TB_Quantity.GotFocus
Dim PMFile As String = (Application.StartupPath + "\data\pmf.csv") ' Product Master File for barcode comparison
Dim objReader As New System.IO.StreamReader(PMFile) ' Where to read PMF from
Dim PMArray(4) As String ' Array for line splitting
Dim DataLine As String ' Line of Product Master File
Dim ICheck As Boolean ' Input barcode check
Dim MCheck As Boolean ' Match barcode check

' Check Input for Barcode
If TB_Barcode.Text.Trim = "" Then
ICheck = False
MsgBox("No Barcode Entered!", MsgBoxStyle.Exclamation, "Input Error!")
ICheck = True
PB_FileRead.Visible = True
' Split Read Line and put in Array
DataLine = objReader.ReadLine()
If DataLine = Nothing Then
'Dirty Trick :-P
PB_FileRead.Value = PB_FileRead.Value + 1
PMArray = DataLine.Split(",")
PMArray(0) = Replace(PMArray(0), """", "")
PMArray(1) = Replace(PMArray(1), """", "")
PMArray(2) = Replace(PMArray(2), """", "")
PMArray(3) = Replace(PMArray(3), """", "")
PMArray(4) = Replace(PMArray(4), """", "")
End If
Loop Until PMArray(3) = TB_Barcode.Text Or PMArray(4) = TB_Barcode.Text Or DataLine = Nothing
End If

If PMArray(3) = TB_Barcode.Text Or PMArray(4) = TB_Barcode.Text Then
If ICheck = True Then
MCheck = True
' Dirty code test...
End If
End If

If MCheck = True Then

TB_Pcode.Text = PMArray(0)
TB_VBarcode.Text = TB_Barcode.Text
TB_PDescription.Text = PMArray(2)
' Make the following visible
TB_VBarcode.Visible = True
' TB_Pcode.Visible = True
TB_PDescription.Visible = True
LBL_Verify.Visible = True
PB_FileRead.Value = 0
BTN_Next.Visible = True
If CB_Speed.Checked Then ' Speed Scan Check
End If
' Error message
MCheck = False
PB_FileRead.Value = 0
PB_FileRead.Visible = False
MsgBox("No Match Found", MsgBoxStyle.Exclamation, "Error!")
End If
End Sub

One small section of my program I wrote for work :)  I find this relatively easy to work with... What I can't do with good programming, I'll bodge with superior bodging skills and work arounds :lol: 
a b 5 Linux
June 2, 2007 9:26:17 PM

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 );

a b 5 Linux
June 2, 2007 9:29:45 PM

PS Perl is written in C integrates well with C and makes it easier to write C :D