使用GDB调试x86 NASM程序时无法打开文件

问题描述 投票:0回答:1

这是从我的代码中读取文件的简化示例:

section .data
    filename db 'txt.txt', 0x00

section .bss
    fd resd 0x01
    buff resb 0x100

section .text
    global _start

_start:
    ; open file
    mov eax, 0x05     ; SYS_OPEN
    mov ebx, filename
    xor ecx, ecx
    mov edx, 0o400    ; r--------
    int 0x80

    ; check if file was opened successfully
    cmp eax, 0x00
    js _exit
    
    mov [fd], eax    ; copy file descriptor

    ; read file
    mov eax, 0x03    ; SYS_READ
    mov ebx, [fd]
    mov ecx, buff
    mov edx, 0x100
    int 0x80

    ; close file
    mov eax, 0x06    ; SYS_CLOSE
    mov ebx, [fd]
    int 0x80

_exit:
    mov eax, 0x01    ; SYS_EXIT
    mov ebx, 0x00
    int 0x80

当我编译并运行程序时,文件读取成功,但是当我通过GDB启动调试过程时,打开文件后

eax
寄存器中出现负数,而不是文件描述符,这表明出现错误

assembly x86 gdb nasm
1个回答
0
投票
问题在于,运行 GDB 时必须指定要打开的文件的完整路径,例如

${fileDirname}/<filename>


    

© www.soinside.com 2019 - 2024. All rights reserved.