0

For a class assignment we needed to write a compiler. This includes an optimizer portion. In other words, we take in a file with some "code". An output file is generated. In the second step we take in the outputted code and remove any "dead" code and re-output to a second file. I have some problems with the optimizer portion and would like to use gdb. But I can't get gdb to operate properly with the input and output files arguments. The way we would normally run the optimizer is:

./optimize <tinyL.out> optimized.out

where tinyL.out is the file outputted in the first step and optimized.out is the file I want to output with the new optimized and compiled code.

I have searched Google for the solution and the tips I have found do not seem to work for my situation. Most people seem to want to only accept an input file and not output a separate file as I need to do.

Any help is appreciated (of course)

EFiore
  • 105
  • 1
  • 9
  • 1
    Does this answer your question? [How do I run a program with commandline arguments using GDB within a Bash script?](https://stackoverflow.com/questions/6121094/how-do-i-run-a-program-with-commandline-arguments-using-gdb-within-a-bash-script) – imz -- Ivan Zakharyaschev Mar 05 '20 at 15:38

2 Answers2

1

I'm not exactly sure what you're asking. But since I'm not yet able to comment everywhere, I write this answer with a guess and edit/delete if necessary.

When GDB is started and before you start the program you wish to debug, set the arguments you want to use with set args.

A reference to the documentation.

Felix Lechenbauer
  • 140
  • 1
  • 3
  • 9
0

You just need to do the file redirection within gdb.

gdb ./optimize
(gdb) run < tinyL.out > optimized.out

https://stackoverflow.com/a/2388594/5657035

laverya
  • 242
  • 4
  • 12