【问题标题】:How to fix getting "sigsegv" when trying to debug a simple nasm assembly program尝试调试简单的 nasm 汇编程序时如何修复“sigsegv”
【发布时间】:2019-07-27 15:09:19
【问题描述】:

我在 win10 64 位家庭主机上运行一个虚拟机。在虚拟机上我安装了 ubuntu 18.04 64 位。

我从网站下载了一个示例汇编程序,与我从“Assembly language step-by-step”学习的书相关。

这是程序:

; vim: ft=nasm
;
; Build using these commands (works on 32-bit Linux)
;    nasm -f elf -g -F stabs eatsyscall.asm
;    ld -o eatsyscall eatsyscall.o
;
; Build on 64-bit Linux: (Linux 3.13.7-1-ARCH #1 x86_64 GNU/Linux)
;    nasm -f elf64 -g -F stabs eatsyscall.asm
;    ld -o eatsyscall eatsyscall.o
;
; Build on OSX (although the instructions are not valid for its architecture)
;    nasm -f macho eatsyscall.asm 
;    ld -arch i386 -macosx_version_min 10.5 -no_pie -e _start -o eatsyscall eatsyscall.o
;

section .data                 ; contains initialized data

EatMsg: db "Eat at Joe's!",10
EatLen  equ $ - EatMsg

section .bss                  ; contains uninitialized data

section .text                 ; contains code

global _start                 ; entry point found by linker (default is _start)

_start:
  nop                         ; needed to allow debugging with gdb - lldb not properly working ATM
  mov eax,4                   ; Specify sys_write syscall
  mov ebx,1                   ; specify file descriptor: stdout
  mov ecx,EatMsg              ; pass message offset
  mov edx,EatLen              ; pass message length
  int 80H                     ; make syscall to output text to stdout

  mov eax,1                   ; specify exit syscall
  mov ebx,0                   ; return code of zero
  int 80H                     ; make syscall to terminate program

当我尝试使用 kdbg 或直接使用 gdb 进行调试时,同样会发生 2 件奇怪的事情(对我来说很奇怪,但可能只是我完全没有经验):

  1. 当我尝试在第 29 行“mov eax, 4”处设置断点时 - 调试器并不止于此。只有当我从上述行开始一个接一个地放置 3 个断点时,它才会停止。

  2. 当调试器停止时,如果我尝试执行单步执行命令,调试器会告诉我程序以“SIGSEGV”信号终止 - 分段错误。调试程序没有终止,但我正在尝试调试的程序。

我尝试在网上搜索此内容,但找不到与我遇到的问题相关的任何内容。

我们将不胜感激。

【问题讨论】:

    标签: linux assembly x86-64 nasm


    【解决方案1】:

    解决了!

    显然问题在于使用了错误的调试信息类型。 解决这个问题的命令是:

    nasm -f elf64 -g -F dwarf eatsyscall.asm -o eatsyscall.o
    

    代替:

    nasm -f elf64 -g -F stabs eatsyscall.asm -o eatsyscall.o
    
    

    这个问题的答案给了我线索: Message while debugging using gdb: Single stepping until exit from function _start

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-23
      • 2011-04-10
      • 1970-01-01
      • 2019-09-11
      • 2021-01-08
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      相关资源
      最近更新 更多