As title.

I know we can use gdb to execute file.

But how to use GDB if the program have multiple .c files?

2 Answers 2


For my example, "mainP.c" will be our main program, and "secondP.c" will be your secondary file. I am assuming your "mainP" calls "secondP" at some time during the execution of the program.

This is how I would do it:

gdb ./mainP
break secondP.c:1 //breaking at first line in secondP
run ./mainP

First you run gdb for your mainP, and the you set a breakpoint at the first line of secondP.

When your mainP calls secondP, gdb will break into secondP.


I've figure it out!

Just use GDB for the program with main function.

And then set breakpoint in the other program's function.

But.. how to run at other program's first line? remain unsolved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .