2

I find that whenever I start gdb I almost always type in:

>>> b *main
>>> r

And then the program 'starts'. Is there a way I can automatically invoke this, either in a settings, or in the gdb invocation itself, such as something like:

$ gdb file.o -cmd "b *main; r"
1
  • 2
    Instead of b main followed by r, you could also just use start. Commented Oct 4, 2020 at 0:56

1 Answer 1

4

You can specify startup commands via command line:

gdb -ex 'b main' -ex r --args ls -l
Sign up to request clarification or add additional context in comments.

4 Comments

thanks that works great: gdb file.o --ex 'b main' --ex 'r'. Is it possible to combine multiple commands on a line in gdb or do you have to separate all commands on their own line?
@David542 No, AFAIK it is not possible to combine commands in single line.
ok thanks, and then finally, what does the --args ls -l do? I assume that would pass arguments to gdb ? (or are the args passed to the script itself?)
@David542 --args tells gdb that it needs to invoke the program which comes after --args with given arguments (ls -l in my example). It's not really related to your question so can be removed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.