linux - 使用断点和符号调试时的gdb问题

标签 linux assembly x86 gdb nasm

我用 Nasm 编写程序集,我想用 gdb 调试程序,但是当我设置断点并运行程序时它不起作用。

程序编译和链接都很好,问题是 gdb。

编译命令如下:

 nasm -f elf64 -F dwarf -g   types.asm
 nasm -f elf64 -F dwarf -g   functions.asm
 nasm -f elf64 -F dwarf -g   Hello.asm
 ld -g -o Hello Hello.o functions.o types.o

这是我要调试的文件 Hello.asm:

 %include "functions.asm"
 section .bss
     res: resb 1
     fout: resb 1

 section .text
    global _start:     ;must be declared for linker (ld)

 section .data
      msg db 'Hello, world!', 0xa  ;string to be printed
      len equ $ - msg     ;length of the string 
      filename db 'hello.txt'

  _start:               ;tells linker entry point
       mov ecx,5
       mov edx,4
       call sum
       mov [res],eax
       mov  edx,1     ;message length
       mov  ecx,res  ;message to write
       mov  ebx,1       ;file descriptor (stdout)
       mov  eax,4       ;system call number (sys_write)
       int  0x80        ;call kernel
       write_string msg,len
       create_file filename
       mov [fout],eax
       close_file [fout]


       call print_msg

       mov  eax,1       ;system call number (sys_exit)
       int  0x80       ;call kernel

  sum:
     mov eax,ecx
     add eax,edx
     add eax,'0'
     ret

接下来我打开 gdb:

gdb Hello
(gdb) break _start
Function «_start» not defined
¿Compilación de breakpoint pendiente hasta futura cargada de biblioteca compartida? (y or [n]) y     
 Punto de interrupción 1 (_start) pendiente.
(gdb) run  
 Starting program: /asm/Hello 
 9Hello, world!
 Hello, world!from another file
 [Inferior 1 (process 5811) exited with code 01]
 (gdb) 

最佳答案

我解决了它,我只将位置部分 .data 更改为部分 .text 并且调试器工作。我不知道为什么,但现在 gdb 使用 .start。

关于linux - 使用断点和符号调试时的gdb问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53744380/

相关文章:

c++ - Eclipse 无法完全解析 Eigen C++ 库,但可以编译

linux - 在 Linux 上通过 USB 发送原始数据

linux - 期望脚本处理 RSA 指纹 key

c - 如何编译这个汇编代码?

assembly - INT13H(非扩展)是否能够访问每个柱面超过 16 个磁头的驱动器?

c - 在DOS下处理以太网中断

c - x86 add 和 addl 操作数相加错误?

linux - 由于 "Device or resource busy",rmdir 失败

c++ - 如何使用汇编程序(x64 OS)获取进程环境 block (PEB)地址?

assembly - MASM 不会插入带有某些 CPU 和 FPU 指令组合的 x87 WAIT 前缀