Quantcast
Viewing all articles
Browse latest Browse all 5995

Why my gdb can't read the file by stdin? (very weird)

This is t.c, I use gcc t.c -o t -m32 -g to compile it:

#include <stdio.h>int main() {    char buffer[100];    printf("Please enter a string: ");    scanf("%99s", buffer);    printf("You entered: %s\n", buffer);    return 0;}

This is t.txt: 123

It can work well when I use pipeline or stdin in terminal:

muyigin@ysyx:~/Desktop$ cat t.txt | ./tPlease enter a string: You entered: 123============================================muyigin@ysyx:~/Desktop$ ./t < t.txtPlease enter a string: You entered: 123

BUT! It does't work in GDB, which seems it "can" work:

(gdb) file t(gdb) run < t.txtStarting program: /home/muyigin/Desktop/t1 < t.txt[Thread debugging using libthread_db enabled]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Please enter a string:

I have read many many answers since 2011, here are what I've tried:

(gdb) run < t.txt(gdb) r < t.txt(gdb) r < $(cat t.txt)(gdb) r < /home/muyigin/Desktop/t.txt(gdb) r < ~/Desktop/t.txt(gdb) start < t.txt

And I've tried use breakpoint.

I use ubuntu22.04 in VMware 17 pro, gdb version is GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1


Viewing all articles
Browse latest Browse all 5995

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>