Subject: Re: single stepping a setcontext
To: None <>
From: Christos Zoulas <>
List: tech-kern
Date: 11/21/2006 18:32:21
In article <>,
Nick Hudson  <> wrote:
>While looking through the results of a gdb testsuite output on i386 I noticed 
>that the single stepping through the return from a signal handler (via 
>__sigtramp_siginfo_2) doesn't work. Everything works until the setcontext 
>call where the PSL_T bit is restored from the original context and the trap 
>never occurs. There are two solutions I can see
>	1) use the PSL_T bit from the trapframe when doing a setcontext instead of
>	   from the mcontext.
>	2) preserve the PSL_T bit for all syscalls
>I've attached patches for both options.
>Does anyone see any problems with either? Which is more preferable?

FreeBSD does the following for traced syscalls:

	 * Traced syscall.
	if ((orig_tf_eflags & PSL_T) && !(orig_tf_eflags & PSL_VM)) {
		frame.tf_eflags &= ~PSL_T;
		ksi.ksi_signo = SIGTRAP;
		ksi.ksi_code = TRAP_TRACE;
		ksi.ksi_addr = (void *)frame.tf_eip;
		trapsignal(td, &ksi);

It also treats PSL_RF specially upon return from signal which we don't.
I am not sure if we should be playing with PSL_T in the setcontext code,
and I don't see other archs that support traps play with the trap bit in
syscall, but then I did not look hard enough.