1

So I am relatively new to coding so please forgive improper vocab. What I am basically trying to do is create a script for, or perhaps enter commands into, GDB so that it can run my code with the input file of a test case over and over. Basically, I am working on a project right now that makes heavy usage of semaphores and mutexes, and somewhere, every once in a blue moon, my code breaks due to race conditions. If I could have gdb run my test case continuously until my code reached a seg fault, this would be ideal.

PS- Please be specific as to what I must do, I am not great at dissecting answers that have heavy technical answers.

Thank You!

4

2 回答 2

1

最简单的解决方案是期望脚本。Expect 是一个自动与公开文本终端界面的程序交互的程序。

示例可在http://en.wikipedia.org/wiki/Expect获得

脚本应该像

#!/usr/bin/expect

# start gdb
spawn gdb yourprogram

while {1} {

# wait for gdb to start, expect the (gdb) to appear
expect "(gdb)"

# send command to run your program
send "run your_args\n"

expect {
    "Program exited normally."    {continue}  # just run again
    "(Some error message)"        {interact}  # start to debug
}

}
于 2013-06-09T03:38:14.060 回答
0

您可以使用 GDB 脚本来自动化您的 GDB 会话。GDB 宏编码语言由 gdb 命令以及基本的循环语句和条件语句组成。

您可以在此处找到有关它的信息

http://www.adacore.com/adaanswers/gems/gem-119-gdb-scripting-part-1/

自动化 GDB 调试会话的最佳方法是什么?

于 2015-06-22T09:21:07.043 回答