Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux x86程序集正在从文件到堆栈读取字节,但gdb找不到字节_Linux_Assembly_X86 - Fatal编程技术网

Linux x86程序集正在从文件到堆栈读取字节,但gdb找不到字节

Linux x86程序集正在从文件到堆栈读取字节,但gdb找不到字节,linux,assembly,x86,Linux,Assembly,X86,我有一些汇编代码,它从文件中读取4个字节并将它们存储在堆栈中,然后将这些4个字节显示给stdout,代码工作正常,但当我使用gdb查看代码正在执行的操作时,尝试在堆栈中查找这些4个字节时,我找不到它们 (gdb) p $esp $1 = (void *) 0xbffff6bc

我有一些汇编代码,它从文件中读取4个字节并将它们存储在堆栈中,然后将这些4个字节显示给stdout,代码工作正常,但当我使用gdb查看代码正在执行的操作时,尝试在堆栈中查找这些4个字节时,我找不到它们

(gdb) p $esp                                                                  
$1 = (void *) 0xbffff6bc                                                            
(gdb) x/4 $esp                                                                                     
0xbffff6bc: 0 1 0 -1073743777                         
文件的前4个字节是:

cat nummers.txt|od -c
0000000   3  \n   1  \n   2  \n   3  \n
0000010
守则:

%macro write 2
    mov eax,4       ; write syscall
    mov ebx,STDOUT  ; stdout
    mov edx,%2      ; number of bytes
    mov ecx,%1      ; buffer
    int 80h     ; call kernel
%endmacro

section .data   
    filename    db 'nummers.txt' ; just use lenth of string
    filename_len    equ $-filename   ; here we use a constant
    STDOUT      equ 1    ; stdout

section .bss
    buffer      resb 4
section .text
global _start   
    _start:

    ;; read first byte from file to know how many elements there are
    mov eax,5       ; syscall open
    mov ebx,filename    ; filename
    mov ecx,0       ; read-only
    int 80h     ; call kernel

    sub esp,4       ; subtract 4 bytes from stack.
    mov eax,3       ; syscall read
    mov ebx,eax     ; file descriptor
    mov ecx,esp         ; location for storing 4 bytes
    mov edx,4       ; read 4 bytes
    int 80h     ; call the kernel

    mov eax,4
    mov ebx,STDOUT
    mov ecx,esp
    mov edx,4
    int 80h
    call ret        
    ret:    
    mov eax,1
    mov ebx,1
    int 80h

谢谢你的帮助

即使在这个简短的汇编程序中,您也几乎达到了可能的最高错误计数。文件名未以0字节结尾。你没有检查开放通话的结果。当文件大小为8时,您试图读取4个字节。最后,您正在重用esp,希望它的值没有改变。

来自gdb的示例输出?@BlackBear更多示例输出?在我调用int 80h读取文件之后,esp看起来是这样的:(gdb)p$esp$1=(void*)0xbfffff6bc(gdb)x/4$esp 0xbfff6bc:01 0-1073743777在哪里中断?在将4移动到eax的指令上的第二个int 80h之后调用readi break应该中断。1)
filename
不是以零结尾的。2) 您不检查sys\u open是否成功。3) 在将eax用作“文件描述符”之前,您可以更改它。修复这些,然后再试一次。好的,我不检查返回值,字符串确实没有终止。。但是我的4字节在哪里?代码还把它们打印到标准输出?