There are several ways.
A really old-fashioned way is to crack a loop in your program main, for example:
volatile int zzz;
...
int main() {
while (!zzz) sleep (1);
Then run the script. In a separate window, run gdb for the program you want to debug, and use it attachto join the sleeping program. Then you can set breakpoints, etc. And finally
(gdb) set var zzz = 1
(gdb) cont
A little newer ("new", as in "he has been in gdb for at least 10 years"), so edit your script and put gdb --argsin front of the program you want to debug. However, this method does not always work. By the way, it does not handle redirects.
, . "" . :
$ gdb /bin/sh
(gdb) set args arguments-to-the-script
(gdb) set detach-on-fork off
(gdb) set target-async on
(gdb) set non-stop on
(gdb) set pagination off
- :
(gdb) add-inferior -exec program-you-want-to-debug
... . run - !