1

I'm trying to run binaries built with clang's address sanitizer under the control of ptrace, and I'm having a problem with spurious SIGTRAPs.

My program uses ptrace in the standard manner: child does ptrace(PT_TRACE_ME,...) then exec; parent waits for SIGTRAP in child that indicates the call to exec was made; parent does ptrace(PT_CONTINUE,...) to set the child running.

This all works fine for normal binaries. When running a binary built with the address sanitizer, on the other hand, after doing the PT_CONTINUE to resume the process, the child process receives an unexpected SIGTRAP straight away.

This can be demonstrated using gdb, which interacts with ptrace in a similar sort of way.

Build a simple test program:

$ echo 'int main(){return 50;}' | clang -fsanitize=address -o test -xc -
$ ./test
$ echo $?
50

Run it in gdb:

$ ggdb ./test
<<snip>>
(gdb) run

(Ignore messages about symbols.)

Note that the process has not exited with code 062, but has stopped with a SIGTRAP:

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007fff5fc01000 in ?? ()

To run the process, continue it manually.

(gdb) continue
Continuing.
[Inferior 1 (process 14536) exited with code 062]

This is all very well for interactive use, but it's a bit tiresome for automated tests, because you need special handling for the address sanitizer builds. I'd much rather keep my test processes the same across all build types if possible.

Anybody know what is going on here?

I'm using clang-700.1.76 (from Xcode). (And gdb 7.9.1 (from MacPorts) - but this looks like a more general problem as my own code suffers from it too.)

I couldn't reproduce this in Linux (gcc 4.8.4/clang 3.8.0, gdb 7.7.1).

Tom Seddon
  • 2,648
  • 1
  • 19
  • 28
  • It looks as if OS X asan builds re-exec themselves, judging by the output you get after setting the verbosity option, and (as requested by PT_TRACE_ME) this is what causes the SIGTRAP. I'd love a proper answer though. (For now, I'm just building the tracer with the sanitizer on, and my test binaries with the sanitizer off.) – Tom Seddon Nov 20 '15 at 17:52

0 Answers0