2

Is it possible to run multiple commands in gdb such as the following:

# step instruction and then print what I want to see again
>>> si && x/bt $rsi

If so, how can it be done?

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    How about a [user-defined command](https://sourceware.org/gdb/onlinedocs/gdb/Define.html), would that work for you? – ssbssa Oct 03 '20 at 23:52
  • @ssbssa nah, I have a few of those, I just find myself often doing an `s`, `si` and then wanting to print a value right after that instruction. – David542 Oct 03 '20 at 23:54
  • 2
    I don't think it's possible to have multiple commands in one line. I guess the [Automatic Display](https://sourceware.org/gdb/current/onlinedocs/gdb/Auto-Display.html) is also not what you want. The [Ctrl-o binding](https://sourceware.org/gdb/onlinedocs/gdb/Command-Syntax.html) may or may not help you a bit thou. – ssbssa Oct 04 '20 at 00:04
  • @ssbssa thanks for the tip regarding Automatic Display, that works nicely for this: `display/bt $rsi`. – David542 Oct 04 '20 at 00:09
  • @ssbssa what's the difference between pressing `[enter]` and `ctrl-o` ? – David542 Oct 04 '20 at 00:11
  • 2
    In your case, if you did `si` and `x/bt $rsi` before, and they are now in your command history, you can go back in the history to `si` and press ctrl-o. This executes the command, just like [enter], but then automatically goes to the `x/bt $rsi` command. – ssbssa Oct 04 '20 at 00:15
  • @ssbssa want to post it as an answer and I'll accept it? – David542 Oct 04 '20 at 02:29
  • 1
    Possible duplicate of https://stackoverflow.com/q/1262639/72178. – ks1322 Oct 04 '20 at 08:45
  • 2
    [User-defined commands](https://sourceware.org/gdb/onlinedocs/gdb/Define.html) as mentioned by @ssbssa are the way to go, but for something quick and dirty [keyboard macros](https://sourceware.org/gdb/current/onlinedocs/gdb/Keyboard-Macros.html) are also a good option. – darcamo Oct 06 '20 at 19:54

1 Answers1

1

If your gdb includes python, follow this post to add a user command in your .gdbinit file: https://stackoverflow.com/a/51804606/11873710

Usage example:

(gdb) cmds echo hi ; echo bye
hi
bye
ken hicks
  • 321
  • 3
  • 3