lks9 / src-tracer

Other
0 stars 0 forks source link

signal and setjmp instrumentation #38

Closed lks9 closed 4 months ago

lks9 commented 1 year ago

An interruption (by a signal) might occur anywhere.

With setjmp() is specified as a nonlocal jump target (#57).

lks9 commented 4 months ago

"Add the signal number to the trace when calling an interrupt handler function" can never be implemented because of race condition. This would not be "signal safe" as this is called in the unix jargon.

The only thing we could do is to add the signal number to a separate trace file. So the trace of the interrupt handler function would be separate. This would require to pause the tracing, call _TRACE_OPEN in the interrupt handler function and before finishing call _TRACE_CLOSE and resume the original tracing. It is possible to implement it that way! Retracing would be very hard, and I could imagine that it is only possible to retrace parts of it.

Anyway, setjmp/longjmp works and it is clear that it is not clear how to solve the signals part. So I am closing this issue.

lks9 commented 4 months ago

Workarounds for signal/interrupt handler treatment:

  1. Do not record signal handlers. Be careful to exclude all source files containing signal handlers from instrumentation, then we are sure to avoid any race conditions and the recorded trace won't be corrupted. The drawback is that we don't know that an interrupt had even happened at some point. So retracing might not always work as desired.
  2. Do not record anything outside the signal handler. Only record a signal handler. We can safely instrument everything if we are sure to start and end tracing with _TRACE_OPEN() and _TRACE_CLOSE() in the signal handler only. Since some time, such instrumentation is possible with instrumenter.py --record SIGNAL_HANDLER where SIGNAL_HANDLER is the name of the signal handler function. The main function will no longer be recorded then. Retracing the signal handler (only) should work as desired.
  3. (not yet implemented!) Record outside the signal handler, pause tracing inside the signal handler, start a new trace in the signal handler only, properly finish the new trace and resume tracing outside. Drawbacks, currently without solutions: How to relate both traces with each other (where was the outer trace interrupted?) while staying async-signal-safe? How to do the retracing?