4

So, when I run my program, I do

./a.out < SampleData

How would I debug my program while still being able to pass in the SampleData file?

Thanks

Edited: I tried doing

gdb ./a.out
run < SampleData

when I do it, it runs my program, outputs what it normally outputs, then leaves me with:

"[Inferior 1 (process 19460) exited with code 03]"

What?

3 Answers 3

6

You can also do the redirection inside of gdb.

gdb a.out
# ...
(gdb) run < SampleData

EDIT based on update:

This text:

[Inferior 1 (process 19460) exited with code 03]

is a message from gdb itself. Inferior is the name given to a process being debugged by gdb. Here, there is only 1 (but there can be more than one). The exit code is the code your program terminated with. If your main() function completed, it's the value that it returned. If you called exit(), it's the value you passed. These values are often useful for passing information about if your program succeeded or failed back to the caller (such as a shell).

I'd suggest checking EXIT_SUCCESS and EXIT_FAILURE in C (which indicate a successful/failed run respectively). Many programs define additional exit codes to indicate specific errors.

Since the value here is 03, which is an unusual exit code, I'd suggest maybe your main() is missing a return statement at the end?

Sign up to request clarification or add additional context in comments.

2 Comments

main is a special case function where if no return is specified, the function returns 0 (or the equivalent of exit(0) happens or some such equivalent, I can't remember which). This was introduced in C99 I think.
@dreamlax Yeah, it's kind of an odd exception but it's only in C99 and onward. Could also be that the code wrongly defined main() to return void.
1
gdb --args ./a.out < SampleData

Comments

0

When using the run command in GDB, you can use the normal input redirection:

$ gdb ./a.out
(gdb) run < SampleData

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.