使用 GDB 时,如何查看 GDB 停止在哪条 C(而非汇编)指令上?

发布于 2024-12-11 04:50:27 字数 381 浏览 1 评论 0原文

看,问题是我应该使用可执行驱动程序 (vdriver) 来测试我编写的 C 源文件 (myfile.c),其中包含驱动程序将使用的方法集合。我使用 gcc 将它们编译在一起(以及它们依赖的任何文件),然后运行“gdb vdriver”

显然,我在 myfile.c 中的某处遇到了段错误。 “dissasemble”生成的汇编代码甚至可以在汇编中显示整个方法,并指向刚刚出现段错误的指令。

错误的这一行会更有效。

但是,运行命令“list *$eip”会导致:

    No source file for address 0x804a3d3

然而,由于汇编代码的复杂性(和长度),我认为查看 C 中发生段 知道如何进行这项工作吗?

See, the problem is that I'm supposed to use an executable driver program (vdriver) to test the C source file I wrote (myfile.c) containing a collection of methods the driver program will use. I used gcc to compile them together (and also any files they depend on) and then ran "gdb vdriver"

Apparently, I am getting a segfault somewhere in myfile.c. The "dissasemble"-produced assembly code can even display the whole method in assembly and point to which instruction just segfaulted.

However, due to the complexity (and length) of the assembly code, I think it would be much more effective to view this line where the segfault occurred in C.

However, running the command "list *$eip" results in:

    No source file for address 0x804a3d3

Does anyone know how to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2024-12-18 04:50:27

使用调试信息进行编译。

gcc -ggdb -c source.c -o source.o ...

更新:您似乎在调用 GCC 时也遇到了问题。我建议编写一个 Makefile,并快速浏览一下 GCC 手册以了解 -c-o 的含义。

CC = gcc
CFLAGS = -ggdb -Wall # or whatever flags you want, read the manual

# List all files, with *.c changed to *.o (Make will figure the rest out)
my_app : file1.o file2.o file3.o file4.o
        $(CC) -o my_app $^
# The above line should start with a tab, not spaces

clean :
        rm -f my_app *.o

# List dependencies like this (technically optional)
# But if you don't do it, "make" might not re-make things that need it
file1.o : file1.c header.h header2.h
file2.o : file2.c header.h

Compile with debugging info.

gcc -ggdb -c source.c -o source.o ...

Update: It looks like you're having trouble invoking GCC as well. I suggest writing a Makefile, and taking a quick look through the GCC manual for what -c and -o mean.

CC = gcc
CFLAGS = -ggdb -Wall # or whatever flags you want, read the manual

# List all files, with *.c changed to *.o (Make will figure the rest out)
my_app : file1.o file2.o file3.o file4.o
        $(CC) -o my_app $^
# The above line should start with a tab, not spaces

clean :
        rm -f my_app *.o

# List dependencies like this (technically optional)
# But if you don't do it, "make" might not re-make things that need it
file1.o : file1.c header.h header2.h
file2.o : file2.c header.h
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文