gdb error- "not in executable format: file format not recognized"

时间:2019-03-19 15:04:52

标签: debugging assembly gdb x86-64

When trying to debug (after compiling and linking) assembly 86-64x program called hello_world, I got a gdb error "not in executable format: file format not recognized".

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

I use Ubuntu 64x OS and gdb 8.1.0 64x.

I have looked for other answers, but couldn't understand what to do or the solution was for mac OS.

When running

`ubuntu@ubuntu:~$ file hello_world

I got

hello_world: ASCII text

After looking this answer I understood that gdb doesn't know what to do with this file, but I didn't figure out how to change the file's format.

My hello_world program:

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

I have compiled and linked using the next commands:

   ubuntu@ubuntu:~$ nasm -felf64 hello_world
   ubuntu@ubuntu:~$ ld hello_world.o

1 个答案:

答案 0 :(得分:5)

   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的创建。

相关问题