How to have gdb exit if program succeeds, break if program crashes?

前端 未结 7 1956
挽巷
挽巷 2020-12-10 02:23

I seem to have some kind of multithreading bug in my code that makes it crash once every 30 runs of its test suite. The test suite is non-interactive. I want to run my test

相关标签:
7条回答
  • 2020-12-10 02:50

    The easiest way is to use the Python API offered by gdb:

     def exit_handler(event):
         gdb.execute("quit")
    
     gdb.events.exited.connect(exit_handler)
    

    You can even do it with one line:

    (gdb) gdb.events.exited.connect(lambda x : gdb.execute("quit")
    

    You can also examine the return code to ensure it's the "normal" code you expected with event.exit_code.

    You can use it in conjuction with --eval-command or --command as mentioned by @acm to register the event handler from the command line, or with a .gdbinit file.

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