How do I run a program with commandline arguments using GDB within a Bash script?

后端 未结 8 2026
半阙折子戏
半阙折子戏 2020-11-27 23:52

When running a program on GDB, usually, the arguments for the program are given at the run command. Is there a way to run the program using GDB and as well as g

相关标签:
8条回答
  • 2020-11-28 00:53

    You can run gdb with --args parameter,

    gdb --args executablename arg1 arg2 arg3
    

    If you want it to run automatically, place some commands in a file (e.g. 'run') and give it as argument: -x /tmp/cmds. Optionally you can run with -batch mode.

    gdb -batch -x /tmp/cmds --args executablename arg1 arg2 arg3
    
    0 讨论(0)
  • 2020-11-28 00:54

    Much too late, but here is a method that works during gdb session.

    gdb <executable>

    then

    (gdb) apropos argument

    This will return lots of matches, the useful one is set args.

    set args -- Set argument list to give program being debugged when it is started.
    

    set args arg1 arg2 ...

    then

    r

    This will run the program, passing to main(argc, argv) the arguments and the argument count.

    0 讨论(0)
提交回复
热议问题