Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA] exceptions.h: Fix definition of TRY_CATCH
Date: Wed, 09 Mar 2005 16:48:00 -0000	[thread overview]
Message-ID: <20050309164803.GN2839@cygbert.vinschen.de> (raw)

Hi,


this patch

  http://sourceware.org/ml/gdb/2005-01/msg00064.html

unfortunately breaks Cygwin.

The reason is the way how TRY_CATCH is defined as a macro:

  #define TRY_CATCH(EXCEPTION,MASK) \
     for (EXCEPTIONS_SIGSETJMP \
             (*exceptions_state_mc_init (uiout, &(EXCEPTION), (MASK))); \
          exceptions_state_mc_action_iter () ; ) \
      while (exceptions_state_mc_action_iter_1 ())

it calls EXCEPTIONS_SIGSETJMP (aka sigsetjmp on systems supporting it),
without bothering how sigsetjmp is defined on the host system.

Cygwin's (as well as RTEMS') sigsetjmp is defined in newlib's machine/setjmp.h
as a macro, too:

  #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
               sigprocmask (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
               setjmp (env))

If you inspect it, you'll see that the first parameter `env' is evaluated
three times.  Since the first parameter is a call to the function
exceptions_state_mc_init(), the result is that three new catcher structures
are created.  But only one of them, the last one which has been created,
is correctly iniitialized by the call to exceptions_state_mc_action_iter(). 
I guess you see what will happen at one point.  A non-initialized catcher
is current when the function exceptions_state_mc_action_iter_1() is called
==> internal_error.

Note that this is *not* a flaw in newlib or Cygwin.  It's perfectly fine
that setjmp and sigsetjmp are defined as macros as above, see
http://www.opengroup.org/onlinepubs/009695399/functions/setjmp.html and
http://www.opengroup.org/onlinepubs/009695399/functions/sigsetjmp.html,
so the usual macro expansion restrictions apply.

Conclusion:  The actual problem is that the sigjmp_buf is created in a
function call which is the first parameter to sigsetjmp.

Solution: Don't do it. :-)

A patch is below.  Tested on Cygwin and Linux.


Ok to check in?


Corinna


	* exceptions.h (TRY_CATCH): Define setjmp/sigsetjmp macro save.

Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.11
diff -u -p -r1.11 exceptions.h
--- exceptions.h	8 Feb 2005 23:44:06 -0000	1.11
+++ exceptions.h	9 Mar 2005 15:14:41 -0000
@@ -115,10 +115,13 @@ int exceptions_state_mc_action_iter_1 (v
   */
 
 #define TRY_CATCH(EXCEPTION,MASK) \
-    for (EXCEPTIONS_SIGSETJMP \
-           (*exceptions_state_mc_init (uiout, &(EXCEPTION), (MASK))); \
-         exceptions_state_mc_action_iter (); ) \
-      while (exceptions_state_mc_action_iter_1 ())
+     { \
+       EXCEPTIONS_SIGJMP_BUF *buf = \
+	 exceptions_state_mc_init (uiout, &(EXCEPTION), (MASK)); \
+       EXCEPTIONS_SIGSETJMP (*buf); \
+     } \
+     while (exceptions_state_mc_action_iter ()) \
+       while (exceptions_state_mc_action_iter_1 ())
 
 /* *INDENT-ON* */
 

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.


             reply	other threads:[~2005-03-09 16:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-09 16:48 Corinna Vinschen [this message]
2005-03-09 17:40 ` Daniel Jacobowitz
2005-03-09 17:54   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050309164803.GN2839@cygbert.vinschen.de \
    --to=vinschen@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox