Invoke gdb to automatically pass arguments to the program being debugged

前端 未结 8 1797

I\'d like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finishe

8条回答
  •  隐瞒了意图╮
    2020-12-23 00:24

    After trying all of the answers here,

    1. The echo/cat hack, while clever, breaks quite a few important features of gdb. Most notably, all user prompts are answered automatically (so you don't get a chance to confirm potentially dangerous operations), and Ctrl+C (to stop a process that you are debugging) ends up killing cat, so you can't actually talk to gdb after that.
    2. The -x option is supposed to work, but I couldn't get it to work with my version of gdb, and it requires a temporary file.

    However, it turns out you can just use -ex, like this:

    gdb -ex "target remote localhost:1234"
    

    You can also specify -ex multiple times to run multiple commands!

提交回复
热议问题