The attached patch sets the trapno field of sigcontext (on x86) by mapping a decent value for the trap number out of the signal/code values from the siginfo.
Created attachment 14369 [details] Patch