我使用yasm进行代码组装,并链接到我的C++程序中,但是我无法在汇编语言文件中的符号中设置gdb中的断点。如何使用gdb调试使用yasm组装的代码?
的命令行可能不是非常具有启发性,但在这里我们去:
"g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -std=c++11 -I"$HOME/usr/include" -c -o "bin/gcc-4.7/debug/main.o" "main.cpp"
yasm -g dwarf2 -f elf64 -o bin/gcc-4.7/debug/mandel.o mandel.yasm
"g++" -L"$HOME/usr/lib" -Wl,-R -Wl,"$HOME/usr/lib" -Wl,-rpath-link -Wl,"$HOME/usr/lib" -o "bin/gcc-4.7/debug/mandel" -Wl,--start-group "bin/gcc-4.7/debug/main.o" "bin/gcc-4.7/debug/mandel.o" -Wl,-Bstatic -Wl,-Bdynamic -lboost_system -lboost_thread -Wl,--end-group -g
这一切都建立无事,而程序运行。但是当我尝试将它加载到gdb中进行调试时,我似乎无法在yasm文件中的任何函数上放置断点。例如,我在那里有一个名为MandelRect的函数。下面是GDB显示我在哪里,它是从所谓的某处主:
(gdb) disassemble 0x404ada,0x404af0
Dump of assembler code from 0x404ada to 0x404af0:
0x0000000000404ada <main()+474>: mov %rax,%rdi
0x0000000000404add <main()+477>: callq 0x409980 <MandelRect>
0x0000000000404ae2 <main()+482>: movq $0x0,-0x18(%rbp)
0x0000000000404aea <main()+490>: jmp 0x404b1c <main()+540>
0x0000000000404aec <main()+492>: mov -0x18(%rbp),%rdx
End of assembler dump.
这里的GDB向我展示它的地址是:
(gdb) info address MandelRect
Symbol "MandelRect" is at 0x409980 in a file compiled without debugging.
这里的GDB暂时无法将断点就可以了:
(gdb) break MandelRect
Function "MandelRect" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
如果我在正确的地址放置一个断点,当执行到达函数时,我不能按指令逐步执行它。它只是从标签到标签,尽我所能(烦恼)告诉。
显然 - 也许吧? - 这与gdb坚持认为该文件是在没有调试的情况下编译有关。但似乎有相关的.o文件和二进制文件中的符号:
~/tests/mandel/bin/gcc-4.7/debug% nm mandel.o | grep MandelRectAsm
0000000000000000 R MandelRectAsm
~/tests/mandel/bin/gcc-4.7/debug% nm mandel | grep MandelRectAsm
000000000040a340 R MandelRectAsm
~/tests/mandel/bin/gcc-4.7/debug% objdump -t mandel.o | grep -i MandelRectAsm
0000000000000000 g .txt 0000000000000000 MandelRectAsm
~/tests/mandel/bin/gcc-4.7/debug% objdump -t mandel | grep -i MandelRectAsm
000000000040a340 g .txt 0000000000000000 MandelRectAsm
那么我该如何解决这个问题?我误解了一些东西,还是yasm -g
坏了?有没有人设法让yasm的调试信息与gdb一起工作?
(系统是Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux
)
我会尝试mandel.o&madel上的nm&objdump -g,以查看调试信息丢失/损坏的位置。 – dbrank0 2014-10-27 08:35:48
感谢您的建议。我已经更新了这个问题。 'objdump -g'没有为我打印任何文件,因为我试过它的任何文件(比如,除了说文件是elf64-x86-64),所以我使用了'objdump -t'代替。 – 2014-10-28 23:41:22