Answer the question
In order to leave comments, you need to log in
Why can fgets behave strangely when debugging through gdbserver?
Actually the problem is this - there is a program that requests data from the user via fgets.
When working without a debugger, everything is ok. If you run it through gdbserver, then the first two (exactly two, always, no more, no less) fgets work as expected, and the third is simply "skipped".
What could it possibly be?
upd.
"Working" example:
#include <stdio.h>
#include <stdlib.h>
char tmp[255]={0};
int main(void) {
printf("Type somthing:");
if(NULL == fgets(tmp, sizeof(tmp)-1, stdin))
{
printf("Unable to read string\n");
}
printf("You write '%s'",tmp);
tmp[0]=0;
if(NULL == fgets(tmp, sizeof(tmp)-1, stdin))
{
printf("Unable to read string\n");
}
printf("You write '%s'",tmp);
tmp[0]=0;
if(NULL == fgets(tmp, sizeof(tmp)-1, stdin))
{
printf("Unable to read string\n");
}
printf("You write '%s'",tmp);
tmp[0]=0;
if(NULL == fgets(tmp, sizeof(tmp)-1, stdin))
{
printf("Unable to read string\n");
}
printf("You write '%s'",tmp);
tmp[0]=0;
return EXIT_SUCCESS;
}
Type somthing:
Test
Test// This echoes back what I type.
You write 'Test
'You write '
'
2nd try
2nd try// This echoes back what I type.
You write '2nd try
'You write '
'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question