0 debugging assembly gdb x86-64
当尝试调试(在编译和链接之后)名为hello_world的程序集86-64x程序时,出现gdb错误“不是可执行文件格式:无法识别文件格式”。
ubuntu@ubuntu:~$ gdb hello_world
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/home/ubuntu/hello_world": not in executable format: File format not recognized
Run Code Online (Sandbox Code Playgroud)
我使用Ubuntu 64x操作系统和gdb 8.1.0 64x。
我一直在寻找其他答案,但不知道该怎么办,或者该解决方案是针对Mac OS的。
跑步时
`ubuntu@ubuntu:~$ file hello_world
Run Code Online (Sandbox Code Playgroud)
我有
hello_world: ASCII text
Run Code Online (Sandbox Code Playgroud)
看完这个答案后,我知道gdb不知道如何处理该文件,但我不知道如何更改文件格式。
我的hello_world程序:
global _start
section .text
_start:
mov rax,1
mov rdi,1
mov rsi,message
mov rdx,13
syscall
mov rax,60
xor rdi,rdi
syscall
section .data
message: db "Hello, World",10
Run Code Online (Sandbox Code Playgroud)
我已经使用以下命令进行了编译和链接:
ubuntu@ubuntu:~$ nasm -felf64 hello_world
ubuntu@ubuntu:~$ ld hello_world.o
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)ubuntu@ubuntu:~$ nasm -felf64 hello_world ubuntu@ubuntu:~$ ld hello_world.o
hello_world 是您的源文件;这就是您运行NASM的目的。通常你会命名NASM源文件hello_world.asm,像一个C hello_world.c。
的默认输出文件ld是a.out,因此您的命令创建了一个名为的可执行文件a.out。如果要创建一个名为的可执行文件hello_world,则需要使用
ld -o hello_world hello_world.o。
(除非您首先将其重命名为,否则这将覆盖您的源代码.asm。这就是为什么约定在源文件上使用扩展名的原因。)
通过运行ls -lcrt按inode-change时间对目录列表进行排序,可能会得到提示。您将a.out在底部看到,之后hello_world.o会提示您ld创建的是而不是hello_world。