1

I'm writing a unit test harness and would like to establish the behavior that if the child process segfaulted, I want to re-run it again under GDB.

The general approach is to execute all tests in parallel, this is done by assembling the commands together and piping the commands into xargs -P 0 -L 1 -I CMD bash -c CMD, and then I want to catch any of these inner processes that segfaulted, and re-run them sequentially under gdb. Note that this is a different thing than catching their return values, which I will continue to treat for test pass/fail purposes.

Obviously a segfaulting test is a failing test... the point is to make it automagically produce a gdb session with the segfault caught, for maximum productivity :)

I know that the WTERMSIG macro can be used in C to check if a child process segfaulted once it exits. I could certainly write a small C/C++ helper program to implement this determination for me but it would be nice if there was a built in way to do this with bash.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • 1
    Maybe related?: [What error code does a process that segfaults return?](https://stackoverflow.com/questions/14599670/what-error-code-does-a-process-that-segfaults-return) – James Brown Jul 14 '21 at 08:30
  • 1
    For a simple command in `bash`, if the command terminates with a signal, its return value would be `128+n` where n is the signal number (11 for SIGSEGV), so I'd expect checking if the return value is 139 would be enough. Note that xargs itself will return 125 if the command is killed by a signal. – Hasturkun Jul 14 '21 at 11:15
  • Very helpful comments, thanks. Definitely good to know about these halfway house solutions. – Steven Lu Jul 14 '21 at 18:20

0 Answers0