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!

ckjavi70
  • 168
  • 3
  • 10

2 Answers2

1

The simplest solution is expect script. Expect is a program to automate interactions with programs that expose a text terminal interface.

Examples are available at http://en.wikipedia.org/wiki/Expect

The script should be like

#!/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
}

}
Naruil
  • 2,300
  • 11
  • 15
0

You can use GDB scripts in order to automate your GDB sessions.The GDB macro coding language consists of gdb commands along with basic looping statements and conditional statements.

You can find information about it here

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

What are the best ways to automate a GDB debugging session?

Community
  • 1
  • 1
Suryansh
  • 193
  • 2
  • 12