linux - gdb 不接受输入重定向

标签 linux assembly x86 gdb debian

我在 Debian Linux (Jessie/Testing) 中无法完全解决 gdb 的问题。尝试调试汇编程序时,我无法让 gdb 接受输入重定向。这是我尝试调试的代码:

#The program reverses the input given to it.  For example "123456789" will 
#become "987654321"

.global _start

readme:
    pushw $0          #allocate 2 bytes onto the stack
    movl $3,%eax      #system call for read
    movl $0,%ebx      #stdin
    movl %esp,%ecx    #read to stack pointer
    movl $1,%edx      #number of bytes to read
    int  $0x80        #execute instruction

    cmpl $0,%eax      #check number of bytes read
    jz  returnme      #jump to label 'returnme' if zero bytes are read

writeme:
    call readme       #recursive call to continue to next character

    movl $4,%eax      #system call for write
    movl $1,%ebx      #stdout
    movl %esp,%ecx    #write what is in the stack pointer
    movl $1,%edx      #write one byte
    int  $0x80        #execute instruction

returnme:
    popw %ax          #clean up
    ret               #return to line after previous call

_start:
    call readme       #call subroutine readme

endit:
    movl $1,%eax      #These lines are for exiting the program
    movl $0,%ebx
    int  $0x80

我使用这些命令编译它:

as -gstabs -o foo.o foo.s
ld -o foo foo.o

然后我像这样运行 gdb:

gdb foo
(gdb) r <test.in 1>test1.out

当我在运行 Debian Jessie 并安装了 gdb 7.6.2 的笔记本电脑上运行它时,它会出现段错误。然而,当我在 Debian Linux 服务器上运行它时(运行 sid,相同的 gdb 版本),代码会执行它应该做的事情。我已经上交了这个,但我很好奇为什么它会在我的笔记本电脑上出现段错误。有什么想法吗?

最佳答案

我通常不会回答我自己的问题,但我弄清楚了为什么它不起作用。使用 64 位操作系统时,as 和 ld 应该知道您何时尝试编译和链接 32 位文件。出于某种原因,这在过去工作得很好。然而,对于这个程序,它没有(我想我过去只是幸运)。无论如何,对上述命令的更正:

as --32 -gstabs foo.s -o foo.o 
ld -m elf_i386 foo.o -o -foo

是程序正常工作所必需的。特别是当我试图将 64 位操作系统下的汇编代码编译和链接到 32 位可执行文件时。

关于linux - gdb 不接受输入重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23188969/

相关文章:

assembly - 在 x86 程序集的过程中调用 ret 指令的位置是否重要

c - 将 asm 嵌入到 C 编程中

c++ - 用 sse 累加整数 vector

c - 堆栈缓冲区溢出文章中的奇怪地址

javascript - 如何在我的 PC 上本地测试基于 AJAX 的代码?

linux - 在Linux中,属于内核数据段的物理内存页是否可交换?

linux - GNU 排序 - 用于比较的默认算法是什么?

linux - 将两个文件与公共(public)列合并

assembly - 当 x86-64 linux 内核需要运行 x86-32 程序时,它做了什么?

gcc - Asm 代码说明