views:

764

answers:

5

I want to debug an application in Linux. The application is created in C++. The GUI is created using QT. The GUI is linked with a static library that can be treated as the back end of the application.

I want to debug the static library but am not sure how to do that.

I tried using gdb

gdb GUI

But how can I attach the library?

Has anyone had experience in debugging libraries in linux?

+6  A: 

gdb will automatically debug functions in the library when they are called. just call it like

gdb ./foo
run

:) . Be sure you build foo with debugging flags (-g3 will enable all debugging stuffs for gcc :). You should not optimize when debugging (pass at most -O1 to gcc, do not optimize further). It can confuse the debugger.

Johannes Schaub - litb
+2  A: 

You can Try KDbg, DDD - Data Display Debugger, Code::Blocks

Ulike DDD, others are IDE with debugger integrated but core debugger [gdb] remains same in those IDE. only thing is that you will get oragnized view of debugger view in GUI.

Also try Eclipse+CDT pluggin. it's also good.

mahesh
+5  A: 

If you want to debug the library code itself, you'll need to build the library with the -g compiler flag (as well as building the executable with -g as litb pointed out). Otherwise gdb will step through your code fine but will throw up its hands each time you make a library call.

Sam Stokes
+1  A: 

A little-known alternative is gdbtui which uses a curses based interface.

BugSlayer
A: 

You can also use Kdbg or ddd