【发布时间】:2019-03-19 15:04:51
【问题描述】:
在尝试调试(在编译和链接之后)名为 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
我使用 Ubuntu 64x 操作系统和 gdb 8.1.0 64x。
我一直在寻找其他答案,但不明白该怎么做,或者解决方案是针对 mac OS。
运行时
`ubuntu@ubuntu:~$ file hello_world
我明白了
hello_world: ASCII text
看了answer之后,我明白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
我已使用以下命令编译和链接:
ubuntu@ubuntu:~$ nasm -felf64 hello_world
ubuntu@ubuntu:~$ ld hello_world.o
【问题讨论】:
-
你使用什么命令来构建这个文件,来自什么来源?前 10 行是什么样的?
head hello_world。如果它是真的 ASCII 文本,请将其发布在您的问题中,以便我们告诉您它实际上是什么类型的文件。实际的 ELF 可执行文件永远不会被误认为是 ASCII 文本——它们以二进制的非 ASCII“幻数”开头。 -
正如彼得问的,你是如何组装和链接的?您是否加载了正确的文件(链接器的输出)?
-
所以,
hello_world是您的来源。您真的应该按照惯例将其命名为hello_world.asm。ld默认生成名为a.out的输出,因此将其加载到gdb中。您可以使用-o选项指定其他名称。确保不要覆盖您的输入:)
标签: debugging assembly gdb x86-64