rushi
rushi

Reputation: 535

How to Debug a C code that is compiled using a Makefile

I am asked to debug a C code containing a number of .c files and is complied using a Makefile on a Redhat Linux system. I want to debug that whole code. How to go about it? What changes do i need to make in the Makefile?

I am using gcc as the compiler.

Upvotes: 3

Views: 2105

Answers (3)

jasonkim
jasonkim

Reputation: 706

Add -g option in your makefile in order to invoke gdb debugger in the future.The way you debug on gdb is like : gdb yourprogram,then you will be redirected to another interface.type "run yourarguments" to start off debugging

Upvotes: 2

Vijay
Vijay

Reputation: 67231

First you need to add the flag "-g" during compilation(make this change in the makefile.if already present then no need). this will open up the symbols for debugging the code.

use the debugging tools available like gdb, dbx, mdb which ever is available in your system.

many resources are available for debugging. one of them is here

Upvotes: 2

f00l
f00l

Reputation: 59

If you're using GCC as compiler add to the CFLAGS variable the -g option. Then you'll be able to debug the resulting executable using the gdb command.

Upvotes: 5

Related Questions