如何设置断点的一个文件的项目,其中有许多文件具有相同的名称?

我想在第45行的 service.cpp 文件上的 gdb 中设置一个断点,我这样做了:

gdb> break service.cpp:45

问题是我的应用程序中有许多 service.cpp 文件,而且它没有选择我感兴趣的那个。如何指定正确的 service.cpp 文件?

97998 次浏览

Specify the full path:

gdb> break /Full/path/to/service.cpp:45

In addition to @Carl 's answer,
In case anyone gets No source file named /Full/path/to/service.c like @Tobias, make sure to add the debugging -g flag to main and the source file you want to access, like main.c and foo.c.

Then make sure main uses the -g compiled operable file, wich might mean you'd have to update and relink a library, for instance.

Just give same trailing components that differs the file from others :

filename:linenum Specifies the line linenum in the source file filename. If filename is a relative file name, then it will match any source file name with the same trailing components. For example, if filename is `gcc/expr.c', then it will match source file name of /build/trunk/gcc/expr.c, but not /build/trunk/libcpp/expr.c or /build/trunk/gcc/x-expr.c.

https://www.zeuthen.desy.de/dv/documentation/unixguide/infohtml/gdb/Specify-Location.html