Starting gdb with a command and its arguments

In a typical gdb session, we used following steps:

$ gdb program
(gdb) run program-arguments

But, if you want to give both of the program and its arguments in one step (this is especially usefull if you have a very long argument lists and frequently switching gdb or normal start), you can use --args option of the gdb:

$ gdb --args program program-arguments
(gdb) 

As you can see, run command (or short hand form as r) still required to start execution but at least, you don’t need to copy&paste arguments.

If you want to automatize a gdb session with gdb commands run, backtrace etc. you can write these commands in a file and start gdb with batch and x parameters as below:

$ gdb --batch -x commands.txt --args program program-arguments