Linux(64 位)、nasm 和 gdb
我正在搜索其他线程但没有运气。 我的问题也许很简单但令人沮丧。 我正在 64 位 Ubuntu 11.04 上编译两个文件:
nasm -f elf64 -g file64.asm
gcc -g -o file file.c file64.o
然后我使用 gdb 调试生成的可执行文件。 有了C,一切就OK了。 但是,在调试汇编时,源代码对调试器“不可见”。我得到以下输出:
(gdb) step
Single stepping until exit from function line,
which has no line number information.
0x0000000000400962 in convert ()
快速调查:
objdump --source file64.o
显示程序集源代码(和行信息)包含在文件中。
为什么我在调试会话中看不到它?我做错了什么? 这些问题是在迁移到 64 位 Ubuntu 后出现的。在 32 位 Linux 中它可以工作(正如它应该的那样)。
I was searching other threads without luck.
My problem is perhaps simple but frustrating.
I'm compiling two files on 64-bit Ubuntu 11.04:
nasm -f elf64 -g file64.asm
gcc -g -o file file.c file64.o
Then I debug the resulting executables with gdb.
With C, everything is OK.
However, when debugging assembly, the source code is "not visible" to the debugger. I'm getting the following output:
(gdb) step
Single stepping until exit from function line,
which has no line number information.
0x0000000000400962 in convert ()
A quick investigation with:
objdump --source file64.o
shows that the assembly source code (and line information) is contained in the file.
Why can't I see it in a debug session? What am I doing wrong?
These problems arose after moving to 64-bit Ubuntu. In the 32-bit Linux it worked (as it should).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
借助 NASM,我在使用 dwarf 调试格式时在 gdb 中获得了更好的体验。然后,gdb 将汇编源代码视为任何其他语言(即,不需要反汇编命令)
(版本 2.03.01 及更高版本会自动启用
-g
,如果-F
为指定。)我正在使用 NASM 版本 2.10.07。我不确定这是否有影响。
With NASM, I've had much better experience in gdb when using the dwarf debugging format. gdb then treats the assembly source as if it were any other language (i.e., no disassemble commands necessary)
(Versions 2.03.01 and later automatically enable
-g
if-F
is specified.)I'm using NASM version 2.10.07. I'm not sure if that makes a difference or not.
GDB 是一个源代码级(或符号)调试器,这意味着它应该与“高级编程语言”一起工作......但事实并非如此!
但是等一下,因为从调试器的角度来看,调试 ASM 程序比高级语言容易得多:几乎没有什么可做的!程序二进制文件总是包含汇编指令,只是以机器格式编写,而不是 ascii 格式。
GDB 可以为您转换它。不要执行
list
来查看代码,而是使用disassemble
来查看函数代码:或使用
x/5i $pc
来查看 5 i 在您的 $pc 指令之后使用
stepi
(si
) 代替step
和nexti
(ni
) 而不是next
。display $pc
也可用于在下级停止时打印当前的pc
(即,在每个nexti
/stepi
之后)代码>.GDB is a source-level (or symbolic) debugger, which means that it's supposed to work with 'high-level programming languages' ... which is not you're case!
But wait a second, because, from a debugger's point of view, debugging ASM programs is way easier than higher level languages: there's almost nothing to do! The program binary always contains the assembly instruction, there're just written in their machine format, instead of ascii format.
And GDB has the ability to convert it for you. Instead of executing
list
to see the code, usedisassemble
to see a function code:or
x/5i $pc
to see 5 i nstruction after your $pcthen use
stepi
(si
) instread ofstep
andnexti
(ni
) instead ofnext
.display $pc
could also be useful to print the currentpc
whenever the inferior stops (ie, after eachnexti
/stepi
.对于那些在 NASM 上遇到问题的人(该错误到目前为止尚未修复):只需下载 NASM git 存储库并切换到版本 2.7,这可能是最后一个运行良好的版本,即支持 gdb。从源代码构建这个过时的版本只是一种解决方法(例如,您不支持最新的 ISA),但对于大多数学生来说已经足够了。
For anyone else stuck with the broken things on NASM (the bug is not fixed so far): just download the NASM git repository and switch to version 2.7, which is probably the last version that works fine, i.e. supports gdb. Building from source this outdated version is only a workaround (you don't have support for the last ISA for example), but it's sufficient for most students.
GDB 可能不知道在哪里搜索源文件。尝试用
directory
明确地告诉它。GDB might not know where to search for your source files. Try to explicitly tell it with
directory
.