views:

109

answers:

2

Hi,

I am using linux, gcc, c. I have a make file.

I want to debug my module. How can I do it?

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

+8  A: 

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.

anon
There's also a graphical interface for gdb named ddd that can be useful if you're having a hard time with getting used to gdb.
wasatz
+1 just to add - http://stackoverflow.com/questions/2588853/the-community-driven-gdb-primer
N 1.1
+1 for DDD - wish I could give more
Mawg
i have large no of .c file.according to you i have to include them all.is there any shortest way.
ambika
@ambika Just ad the -g to the CFLAGS macro in your makefile
anon
Don't forget -Wall option and making it compile clean.
Tadeusz A. Kadłubowski
A: 

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- DD is great - for visualizing the contents of arrays/matrices, and - imo - especially if you have linked lists

Mawg