[PATCH] "Spurious" trace flags and debug traps

Eric PAIRE (e.paire@opengroup.org)
Mon, 21 Sep 1998 13:45:04 +0200


Hi!

3 weeks ago, Bernd Paysan sent an Email to complain that the spurious TF
fix needed to correct GDB attach/detach commands broke his self-debugging
program. After some reflection on how to set up a solution working for both
problems, I suggest the attached patch against 2.1.122 which detects the
spurious TF trap with another process flag (PF_DTRACE already used by m68k).

This flag is set when the tracing program sets the TF flag of the child
process, is tested for spurious SSTEP trap, and is only reset at execve()
system call (because the stack is cleaned up). I think that this is a much
cleaner long-term solution than the #ifdef Bernd suggested as a quick fix
for his problem.

> I just realized that the kernel now clears "spurious" trace flags and
> DR7 settings (patch from 2.1.113). Please back these changes out. They
> break my program (bigFORTH), which is an interactive language that can
> trace itself (and it must trace itself - ptracing by a parent process is
> not an option, since it's much more complicated to get to the "symbol"
> informations, and well, I presume it's slower, too).
>
> I see no obvious reason why a program should not be able to debug itself.
> Wine does so, too (it uses int3 to set breakpoints, and therefore works
> even with the current kernel).

Best regards,
-Eric
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ Eric PAIRE
Email : e.paire@gr.opengroup.org | THE Open GROUP - Grenoble Research Institute
Phone : +33 (0) 476 63 48 71 | 2, avenue de Vignate
Fax : +33 (0) 476 51 05 32 | F-38610 Gieres FRANCE
------ Cut Here ------ Cut Here ------ Cut Here ------ Cut Here ------
--- arch/i386/kernel/ptrace.c.OLD Thu Sep 17 08:09:57 1998
+++ arch/i386/kernel/ptrace.c Mon Sep 21 09:21:56 1998
@@ -541,6 +541,10 @@
if ((unsigned long) data > _NSIG)
goto out;
child->flags &= ~PF_TRACESYS;
+ if ((child->flags & PF_DTRACE) == 0) {
+ /* Spurious delayed TF traps may occur */
+ child->flags |= PF_DTRACE;
+ }
tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG;
put_stack_long(child, EFL_OFFSET, tmp);
child->exit_code = data;
--- arch/i386/kernel/traps.c.OLD Thu Sep 17 08:09:57 1998
+++ arch/i386/kernel/traps.c Mon Sep 21 10:03:05 1998
@@ -339,7 +339,7 @@

/* Mask out spurious TF errors due to lazy TF clearing */
if (condition & DR_STEP) {
- if ((tsk->flags & PF_PTRACED) == 0)
+ if ((tsk->flags & (PF_DTRACE|PF_PTRACED)) == PF_DTRACE)
goto clear_TF;
}

--- arch/i386/kernel/process.c.OLD Thu Sep 17 08:09:57 1998
+++ arch/i386/kernel/process.c Mon Sep 21 09:03:40 1998
@@ -791,6 +791,8 @@
goto out;
error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);
putname(filename);
+ if (error == 0 && (current->flags & PF_DTRACE) != 0)
+ current->flags &= ~PF_DTRACE;
out:
unlock_kernel();
return error;
--- include/linux/sched.h.OLD Thu Sep 17 08:25:20 1998
+++ include/linux/sched.h Mon Sep 21 11:21:38 1998
@@ -322,7 +322,7 @@
#define PF_MEMALLOC 0x00000800 /* Allocating memory */

#define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
-#define PF_DTRACE 0x00200000 /* delayed trace (used on m68k) */
+#define PF_DTRACE 0x00200000 /* delayed trace (used on m68k, i386) */

/*
* Limit the stack by to some sane default: root can always

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/