From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2811 invoked by alias); 9 Mar 2005 16:48:26 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 2664 invoked from network); 9 Mar 2005 16:48:14 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 9 Mar 2005 16:48:14 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j29GmEHl010094 for ; Wed, 9 Mar 2005 11:48:14 -0500 Received: from potter.sfbay.redhat.com (potter.sfbay.redhat.com [172.16.27.15]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j29GmDn19074 for ; Wed, 9 Mar 2005 11:48:13 -0500 Received: from cygbert.vinschen.de (vpn50-54.rdu.redhat.com [172.16.50.54]) by potter.sfbay.redhat.com (8.12.8/8.12.8) with ESMTP id j29GmB5s029172 for ; Wed, 9 Mar 2005 11:48:12 -0500 Received: by cygbert.vinschen.de (Postfix, from userid 500) id 7355B57D8B; Wed, 9 Mar 2005 17:48:03 +0100 (CET) Date: Wed, 09 Mar 2005 16:48:00 -0000 From: Corinna Vinschen To: gdb-patches@sources.redhat.com Subject: [RFA] exceptions.h: Fix definition of TRY_CATCH Message-ID: <20050309164803.GN2839@cygbert.vinschen.de> Reply-To: gdb-patches@sources.redhat.com Mail-Followup-To: gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2i X-SW-Source: 2005-03/txt/msg00145.txt.bz2 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.