28

I am writing a C language program on Linux and compiling it using GCC.

I also use a Make file.

I want to debug my program. I don't want to debug a single file, I want to debug the whole program.

How can I do it?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
ambika
  • 39
  • 2
  • 4
  • 7

4 Answers4

34

Compile your code with the -g flag, and then use the gdb debugger. Documentation for gdb is here, but in essence:

gcc -g -o prog myfile.c another.c

and then:

gdb prog

If you want a user-friendly GUI for gdb, take a look at DDD or Insight.

7

I guess that you are building from the command line.

You might want to consider an IDE (Integrated Development Environment), such as KDevelop or Eclipse, etc (hint - Eclipse ... ECLPISE ... E C L I PS E).

Use an IDE to edit your code, refactor your code, examine your code - class tree, click a variable, class or function to jump to declaration, etc, etc

And - of course - to debug:

  • run your code in the IDE
  • set breakpoints to stop at particular lines
  • or just step through, a line at a time
  • examine the call stack to see how you go there
  • examine the current values of variables, to understand your problem
  • change the values of those variables and run to see what happens
  • and more, more, more

p.s as wasatz mentioned- DDD is great - for visualizing the contents of arrays/matrices, and - imo - especially if you have linked lists

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
1

You can use gdb-based simple and useful GUI "Nemiver". It can debug your whole module comprising many source files.

enter image description here

Dennis V
  • 574
  • 7
  • 19
0

Try cgdb

cgdb is a lightweight curses (terminal-based) interface to the GNU Debugger (GDB). In addition to the standard gdb console, cgdb provides a split screen view that displays the source code as it executes. The keyboard interface is modeled after vim, so vim users should feel at home using cgdb.

github repository

pmg
  • 106,608
  • 13
  • 126
  • 198