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

后端 未结 8 2073
半阙折子戏
半阙折子戏 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:46

    gdb has --init-command where somefile has a list of gdb commands to run, I use this to have //GDB comments in my code, then `

    echo "file ./a.out" > run
    grep -nrIH "//GDB"|
        sed "s/\(^[^:]\+:[^:]\+\):.*$/\1/g" |
        awk '{print "b" " " $1}'|
        grep -v $(echo $0|sed "s/.*\///g") >> run
    gdb --init-command ./run -ex=r
    

    as a script, which puts the command to load the debug symbols, and then generates a list of break commands to put a break point for each //GDB comment, and starts it running

提交回复
热议问题