Why doesn’t debugger stop at breakpoint?


Remember to give the -g option to the compiler.

The problem

Tonight I was trying to make a toy example program and wanted to examine the memory of some structures.  I do this all the time at work, but we usually use Eclipse. Now for my toy program I wrote the 50 lines of C++ up in geany and noticed that if you hit F9 it will build such a simple program for you.  Bonus!  Ran the program and the output is as expected.  [By the way, at work and home I use linux.  Centos at work, Ubuntu at home].  So lets fire up a debugger and have a look at that memory.

Attracted to shiny things

Many moons ago when I started my first stint as a professional code monkey, Visual Studio 6 was the tool of choice . Now while I used to whinge about its many failings, I was deeply attracted to the integrated debugger.  That debugger really changed the way I chased down problems. Fast forward through time to tonight and I wanted to fire up a debugger.  So do I just use gdb?  Or do I fire up a graphical debugger.  I’m still partial to the shiny debugger so up I fire ddd.  ddd ran my code (as in output appeared) but for the life of me I could not get it to show me the source.  OK, no worries, it’s been a decade since I last used ddd, so let’s just jump ship and use kdbg.  Load up the executable and source, set some breakpoint, hit go and the program merrily wizzes past them like they didn’t exist!


Reluctantly I read the manual.  Luckily the manual is actually very short!  Unluckily the manual gave me no clue as to what was going wrong.  Next up, search the web. Thankyou to http://pascalg.wordpress.com/2007/03/10/debugging-cc-with-kdbg-kdevelop/ for the excellent comment

<quote>First you need to compile your c/c++ source with “-g”(this is very important). E.g gcc test.c -g </quote>

And there was my issue.  The default geany build command doesn’t specify -g in the options. Just in case you are wondering, the -g tells gcc to produce debugging information. kdbg now stops correctly and I bet ddd will too when I go back and try.

Tagged with: , ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: