[英]How to fix getting “sigsegv” when trying to debug a simple nasm assembly program
我在win10 64位家庭主機上運行虛擬盒。 在虛擬盒子上,我已經安裝了ubuntu 18.04 64位。
我從與《我的匯編語言逐步學習》一書相關的網站上下載了一個示例匯編程序。
這是程序:
; 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件事(對我來說很奇怪,但可能完全是我的經驗不足):
當我嘗試在第29行“ mov eax,4”處設置斷點時,調試器不會在那里停止。 僅當我在上述行中一個接一個地放置3個斷點時,它才會停止。
當調試器確實停止時,如果我嘗試執行步進命令,則調試器會告訴我該程序以“ SIGSEGV”信號終止-分段錯誤。 調試程序不會終止,但是我要調試的程序。
我嘗試在線搜索此內容,但找不到與遇到的問題有關的任何內容。
所有幫助將不勝感激。
解決了!
顯然問題出在使用錯誤的調試信息類型。 解決此問題的命令是:
nasm -f elf64 -g -F dwarf eatsyscall.asm -o eatsyscall.o
代替:
nasm -f elf64 -g -F stabs eatsyscall.asm -o eatsyscall.o
這個問題的答案帶給我了線索: 使用gdb調試時的消息:單步執行,直到從函數_start退出
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.