2

I am trying to debug a C program which has scanf statements ,using Mingw gdb. I followed this post to compile the program and start the debugger using below commands

gcc -g -o sample sample.c 
gdb sample.exe            

and created the break point at main using break main. As my program needs an integer and string as input through scanf, I followed this post and created a file named input , with the contents

1
"InputString"

and run the program using debugger using

run < input

gdb doesn't seem to start the program and gives the following message

Starting program: F:\spoj\sample.exe < input
Don't know how to run.  Try "help target".

Please help me understand where I am going wrong.

Community
  • 1
  • 1
quirkystack
  • 1,387
  • 2
  • 17
  • 42

1 Answers1

3

I use the following format to provide command line args to a program being run under gdb:

<shell> gdb a.out
gdb> set args "what ever you would provide on the command line"
gdb> run
lsk
  • 532
  • 4
  • 5
  • 1
    I have to take the input at runtime using scanf so I am looking for a gdb option which gives the prompt to enter the input. As per my understanding, your program takes command line arguments. – quirkystack Jul 25 '13 at 00:43
  • 1
    If you know the input you are going to enter via scanf, then you can provide them via set args? If you only know this data at runtime, then one option is to read the input from the program itself i.e. can you write a loop in sample.exe to read the input from a file with a specific name? The input you are providing to scanf() can be redirected to a file so that sample.exe can read it. Best I can do. – lsk Jul 25 '13 at 03:02
  • Thanks.I didnt think of the option. I will try that. Upvoted the answer for now. 'll wait if I could get any better option. – quirkystack Jul 25 '13 at 03:20