This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A useful patch?
- To: gcc at gcc dot gnu dot org
- Subject: A useful patch?
- From: Andrew Haley <aph at pasanda dot cygnus dot co dot uk>
- Date: 10 Apr 2000 14:53:22 -0000
Recently, I had a great deal of trouble with an application I was
debugging. It turned out that the sj/lj exception handler chain was
becoming deranged, and at some point a long time after the corruption
occurred, the program would crash. This is a very hard problem to
debug.
I wrote tons of tracing code and eventually found the problem by
adding a trap that triggers if the exceptioion handler chain is popped
by the wrong function (any function other than the one that did the
corresponding DHC push).
This patch is potentially useful to anyone with problems in this area.
But what should I do with it? If I wrap the code in
#ifdef SJLJ_EXECPTION_DEBUG or somesuch is it likely to be acceptable?
I've appended a rough (and untested) version of what I have in mind.
If this sort of thing is acceptable I'll finish it up and submit it.
Andrew.
Index: expr.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/expr.c,v
retrieving revision 1.412
diff -c -4 -p -r1.412 expr.c
*** expr.c 1999/10/14 11:55:02 1.412
--- expr.c 2000/04/10 14:29:10
*************** expand_expr (exp, target, tmode, modifie
*** 8374,8381 ****
--- 8374,8399 ----
case POPDHC_EXPR:
{
rtx dhc = get_dynamic_handler_chain ();
+
+ #ifndef DONT_USE_BUILTIN_SETJMP
+
+ #ifndef BUILTIN_SETJMP_FRAME_VALUE
+ #define BUILTIN_SETJMP_FRAME_VALUE virtual_stack_vars_rtx
+ #endif
+ int jmp_buf_frame_offset = 2 * GET_MODE_SIZE (Pmode);
+ rtx lab = gen_label_rtx ();
+ rtx saved_frame_pointer
+ = validize_mem (gen_rtx_MEM
+ (Pmode, gen_rtx_PLUS
+ (Pmode, GEN_INT (jmp_buf_frame_offset), dhc)));
+ do_compare_rtx_and_jump (saved_frame_pointer, BUILTIN_SETJMP_FRAME_VALUE,
+ NE, 1, Pmode, NULL_RTX, 0, lab, NULL_RTX);
+ emit_library_call (terminate_libfunc, 0, VOIDmode, 0);
+ emit_barrier ();
+ emit_label (lab);
+ #endif
emit_move_insn (dhc, validize_mem (gen_rtx_MEM (Pmode, dhc)));
return const0_rtx;
}