From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25419 invoked by alias); 4 Jun 2014 16:05:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25385 invoked by uid 89); 4 Jun 2014 16:05:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pd0-f171.google.com Received: from mail-pd0-f171.google.com (HELO mail-pd0-f171.google.com) (209.85.192.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Jun 2014 16:05:26 +0000 Received: by mail-pd0-f171.google.com with SMTP id y13so6272128pdi.30 for ; Wed, 04 Jun 2014 09:05:24 -0700 (PDT) X-Received: by 10.68.110.3 with SMTP id hw3mr46021852pbb.144.1401897923895; Wed, 04 Jun 2014 09:05:23 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id su8sm11547123pbc.72.2014.06.04.09.05.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jun 2014 09:05:23 -0700 (PDT) From: Doug Evans To: Gary Benson Cc: gdb-patches@sourceware.org, Andrew Burgess , Eli Zaretskii , Florian Weimer , Mark Kettenis , Pedro Alves , Tom Tromey Subject: Re: [PATCH 2/2 v3] Demangler crash handler References: <20140604100755.GA7570@blade.nx> <20140604100957.GC7570@blade.nx> Date: Wed, 04 Jun 2014 16:05:00 -0000 In-Reply-To: <20140604100957.GC7570@blade.nx> (Gary Benson's message of "Wed, 4 Jun 2014 11:09:57 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg00175.txt.bz2 Hi. A few comments inline. Gary Benson writes: > This patch wraps calls to the demangler with a segmentation fault > handler. The first time a segmentation fault is caught a core file > is generated and the user is prompted to file a bug and offered the > choice to exit or to continue their GDB session. A maintainence > option is provided to allow the user to disable the crash handler > if required. > > Eli pointed out that SIGSEGV is an ANSI-standard signal but I found > various other SIGSEGV checks in GDB so I have left the preprocessor > conditionals intact for consistency. I hope this is ok. > > > gdb/ > 2014-06-04 Gary Benson > > * utils.h (dump_core): New declaration. > * utils.c (dump_core): Make non-static. > * cp-support.c (signal.h): New include. > (catch_demangler_crashes): New flag. > (SIGJMP_BUF): New define. > (SIGSETJMP): Likewise. > (SIGLONGJMP): Likewise. > (gdb_demangle_jmp_buf): New static global. > (gdb_demangle_signal_handler): New function. > (gdb_demangle): If catch_demangler_crashes is set, install the > above signal handler before calling bfd_demangle, and restore > the original signal handler afterwards. Display the offending > symbol and call demangler_warning the first time a segmentation > fault is caught. > (_initialize_cp_support): New maint set/show command. > > [...] > > +/* Stack context and environment for demangler crash recovery. */ > + > +static SIGJMP_BUF gdb_demangle_jmp_buf; > + > +/* Signal handler for gdb_demangle. */ > + > +static void > +gdb_demangle_signal_handler (int signo) > +{ > + static int core_dumped = 0; > + > + if (!core_dumped) > + { > + if (fork () == 0) > + dump_core (); IIUC you're skipping the can_dump_core() check. If the user has set ulimit -c 0, I think that needs to be obeyed. I realize can_dump_core may call fprintf which we can't do here, but you could still IMO call getrlimit. IWBN to still call can_dump_core (or whatever) so that the implementation of the check is still tucked away in a function. > + > + core_dumped = 1; > + } > + > + SIGLONGJMP (gdb_demangle_jmp_buf, signo); > +} > + > +#endif > + > /* A wrapper for bfd_demangle. */ > > char * > gdb_demangle (const char *name, int options) > { > - return bfd_demangle (NULL, name, options); > + char *result = NULL; > + int crash_signal = 0; > + > +#if defined (SIGSEGV) && defined (HAVE_WORKING_FORK) > +#if defined (HAVE_SIGACTION) && defined (SA_RESTART) > + struct sigaction sa, old_sa; > + > + if (catch_demangler_crashes) > + { > + sa.sa_handler = gdb_demangle_signal_handler; > + sigemptyset (&sa.sa_mask); > + sa.sa_flags = 0; > + sigaction (SIGSEGV, &sa, &old_sa); > + } > +#else > + void (*ofunc) (); > + > + if (catch_demangler_crashes) > + ofunc = (void (*)()) signal (SIGSEGV, gdb_demangle_signal_handler); > +#endif > + > + if (catch_demangler_crashes) > + crash_signal = SIGSETJMP (gdb_demangle_jmp_buf); > +#endif > + > + if (crash_signal == 0) > + result = bfd_demangle (NULL, name, options); > + > +#if defined (SIGSEGV) && defined (HAVE_WORKING_FORK) > + if (catch_demangler_crashes) > + { > +#if defined (HAVE_SIGACTION) && defined (SA_RESTART) > + sigaction (SIGSEGV, &old_sa, NULL); > +#else > + signal (SIGSEGV, ofunc); > +#endif > + > + if (crash_signal != 0) > + { > + static int error_reported = 0; > + > + if (!error_reported) For myself as a user I'd like the warning for every demangle failure. [I'd throttle it by unique symbols though.] > + { > + demangler_warning (__FILE__, __LINE__, > + _("unable to demangle '%s' " > + "(demangler failed with signal %d)"), > + name, crash_signal); > + > + error_reported = 1; > + } > + > + result = NULL; > + } > + } > +#endif > + > + return result; > }