I have an issue with gdb that I cannot quite figure out in Debian Linux (Jessie/Testing). When attempting to debug an assembly program, I cannot get gdb to accept input redirection. Here is the code I am attempting to debug:
#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
I compile it using these commands:
as -gstabs -o foo.o foo.s
ld -o foo foo.o
Then I run gdb like this:
gdb foo
(gdb) r <test.in 1>test1.out
When I run this on my laptop running Debian Jessie with gdb 7.6.2 installed, it segfaults. However, when I run this on a Debian Linux server (running sid, same gdb version), the code does what it is supposed to. I have already turned this in, but I am curious as to why it segfaults on my laptop. Any ideas?