-1

This is the Clang version of:


Running my application many times, programmatically, over a large number of possible inputs, I've occasionally encountered a segmentation fault.

I'd like each test invocation to be run under lldb so that I can get a backtrace for further debugging. If an invocation exits without a crash, I'd like lldb to automatically quit so that the test harness progresses to the next iteration. This way I can set the whole thing off over lunchtime and only have the suite interrupted when something crashes.

Bonus points for having lldb auto-quit in all cases, but first print a backtrace if the program crashed.

I'm currently able to automate at least the initial run command:

lldb -o run -f $CMD -- $ARGS
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

1 Answers1

2

I'm having difficulty finding an online command reference but it looks like the -batch command line option will get you the basic "exit on success/prompt on fail" behaviour.

For a backtrace and auto-quit on failure I think you need the --source-on-crash option...

-K <filename>  
--source-on-crash <filename>  
    When in batch mode, tells the debugger to source this file of lldb
    commands if the target crashes.

So, create the command file with something like...

echo -e 'bt\nquit' > lldb.batch

and then invoke as...

lldb --batch -K lldb.batch -o run -f $CMD -- $ARGS
G.M.
  • 12,232
  • 2
  • 15
  • 18
  • Pretty good! Only weakness I've seen so far is that the exit code doesn't appear to reflect that of the target. So my test harness doesn't quite know what's going on. Putting 'quit 1' in the batch file gets me partially there. – Lightness Races in Orbit Oct 31 '18 at 17:06
  • I guess the ideal solution would be, instead of `-batch`, a `--source-on-graceful-quit` with a batch file I can put `quit $exitCode` in or something – Lightness Races in Orbit Oct 31 '18 at 17:08
  • Maybe I should be using the Python bindings as a launcher – Lightness Races in Orbit Oct 31 '18 at 17:12
  • I'm afraid I can't really achieve anything more without resorting to python. Also, can you clarify what you mean by `"Putting 'quit 1' in the batch file gets me partially there."`? Using `quit 1` doesn't affect the exit code of `lldb` itself for me (`lldb` version 6.0.1) -- in fact, anything I type after `quit` appears to be completely ignored. – G.M. Oct 31 '18 at 19:16
  • The ability to set lldb's exit value is a recent addition. It will be in the 7 open source release. – Jim Ingham Oct 31 '18 at 23:16
  • There was a request recently for a --source-on-exit to go along with --source-on-crash. Specific to this problem, however: batch mode is really set up to just debug one process - I'm not really sure what would happen if you started up more than one. So it would make sense in batch mode to just automatically set lldb's exit code to that of the process that successfully exited. Feel free to file feature requests for this and if you really want it, it should be pretty easy to hack in. – Jim Ingham Oct 31 '18 at 23:17
  • @G.M. Regarding `quit 1` admittedly I saw it discussed online and didn't actually try it yet ^_^ – Lightness Races in Orbit Nov 01 '18 at 10:29