简体   繁体   中英

GDB how to set break point in linked files?

So lets say I have my main file: main.c, linked with file1.c and file2.c where file1 and file2 include their header files: file1.h, file2.h

I compiled them together like so:

gcc main.c file1.c file2.c

which creates the ./a.out executable to be run.

In GDB how do I set a break point in my main.c? I've tried

b main.c

which gave me this output:

Make break-point pending on future shared library load? yes or no

to which I responded yes but it never sets a break-point anywhere even after I say b 232 : the line number, I even tried b main 232 and b main.c 232 but non of these work either..

What you want is the following (see GDB doc ):

break main.c:232

And don't forget to compile with -g , otherwise line number information will not be present in the generated program.

As an alternative to @MarcoBonelli's answer you can use

break main.c:main

or since there cannot be more than one main function in a project you can simply use

break main

this has the advantage of not having to search for the line number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM