Say I'm writing a hypothetical debugger. A debugger wants to set breakpoints and watchpoints (both software and hardware) and what not. When a tracee hits a breakpoint a SIGTRAP
is generated.
But using ptrace
, it too, can "generate" SIGTRAP
signals, which leads me to this question - is there a way to immediately differentiate between a SIGTRAP caused by some ptrace request? It would allow for not having to "scan" all the breakpoints the debugger might have potentially set, to see if the SIGTRAP was caused by a breakpoint it set or by some ptrace request.
Sure, one way would be to store some meta data/state, representing if the tracer has issued a ptrace request - but this is fragile (very, very fragile) as anything might have happened between issuing the request and seeing the signal (from the tracer's perspective). Many of the (if not all) of the PTRACE_O_...
(so called PTRACE_EVENT stops
) settings can be inspected via some bit shifting, but these are events reported "automatically"; they don't come after some issued ptrace request.