GDB 可以使用静态链接库重新加载可执行文件吗?
通常,当使用 gdb 时,我可以停止执行并重建可执行文件并重新启动,而不会丢失断点。当我使用具有静态链接库的可执行文件尝试此操作时,我收到一条错误,指出我无法在构建过程中打开可执行文件。
一个具体的例子:
库文件:
libtest.h:
int square(int a);
libtest.c:
int square(int a) {
return a * a;
}
库是用以下内容编译的:
gcc -g -c libfile.c
ar rcs libtest.a libfile.o
主文件 ac 包含:
#include <stdio.h>
#include <stdlib.h>
#include "libfile.h"
int main() {
printf( "2 squared is %d\n", square(2) );
return 0;
}
项目是这样编译和链接的:
gcc -g -c a.c
gcc a.o -g --static -L. -ltest -o gdb_test
如果我将生成的文件 gdb_test 加载到 gdb 中,那没关系如果它正在运行,则不会。只要 gdb 打开,后续构建就会在链接步骤中失败:
/usr/bin/ld: cannot open output file gdb_test: Permission denied
有解决办法吗?我希望能够使用 gdb,而不必重新启动它并丢失我的断点。
Normally when using gdb I can stop execution and rebuild the executable and restart without loosing my breakpoints. When I try this with an executable that has a statically linked library I get an error stating that I cannot open the executable file during the build.
A concrete example:
The library files:
libtest.h:
int square(int a);
libtest.c:
int square(int a) {
return a * a;
}
The library is compiled with:
gcc -g -c libfile.c
ar rcs libtest.a libfile.o
Main file a.c contains:
#include <stdio.h>
#include <stdlib.h>
#include "libfile.h"
int main() {
printf( "2 squared is %d\n", square(2) );
return 0;
}
The project is compiled and linked like this:
gcc -g -c a.c
gcc a.o -g --static -L. -ltest -o gdb_test
If I load the resulting file gdb_test into gdb it doesn't matter if it is running it not. As long is gdb is open a subsequent build will fail during the link step:
/usr/bin/ld: cannot open output file gdb_test: Permission denied
Is there a way around this? I would like to be able to work with gdb without having to restart it and loose my breakpoints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是 GDB 或 GCC 版本的问题;它对我有用:
我的系统是 Debian/Sid/amd64。 GCC 是(Debian 4.6.2-9); ld = binutils = ar 是 GNU 黄金(Debian 2.22 的 GNU Binutils); GDB 是 GNU gdb (GDB) 7.3.50.20111117-cvs-debian; Gnu Libc 是(Debian EGLIBC 2.13-24)。内核是 Linux 版本 3.1.0-1-amd64 (Debian 3.1.5-1)
我可以从 gdb 内部重新编译该程序并运行它:
It is probably a matter of versions of GDB or GCC; it works for me:
My system is Debian/Sid/amd64. GCC is (Debian 4.6.2-9); ld = binutils = ar is GNU gold (GNU Binutils for Debian 2.22); GDB is GNU gdb (GDB) 7.3.50.20111117-cvs-debian; Gnu Libc is (Debian EGLIBC 2.13-24). Kernel is Linux version 3.1.0-1-amd64 (Debian 3.1.5-1)
And I am able to recompile the program from inside gdb and to run it:
这不太可能与
GDB
或ld
(或它们的版本),并且肯定与您对存档库的使用无关。发生这种情况的可能性更大,因为您正在使用一些“奇怪的”文件系统。也许您正在使用
NTFS
或CIFS
挂载?df .
说什么?This is unlikely to be related to either
GDB
orld
(or their versions), and is most certainly not related to your use of archive library.Much more likely this is happening because you are using some "strange" filesystem. Perhaps you are using
NTFS
orCIFS
mount? What doesdf .
say?