From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: C backtraces for Emacs Date: Fri, 24 Aug 2012 03:48:58 -0700 Organization: UCLA Computer Science Department Message-ID: <50375C1A.8000104@cs.ucla.edu> References: <502EDAF3.6030005@cs.ucla.edu> <5034A54F.6020006@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1345805348 24098 80.91.229.3 (24 Aug 2012 10:49:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Aug 2012 10:49:08 +0000 (UTC) Cc: Juanma Barranquero , Eli Zaretskii , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 24 12:49:08 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T4rRr-00020S-Ks for ged-emacs-devel@m.gmane.org; Fri, 24 Aug 2012 12:49:07 +0200 Original-Received: from localhost ([::1]:45848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4rRp-0000yM-Fz for ged-emacs-devel@m.gmane.org; Fri, 24 Aug 2012 06:49:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4rRl-0000yE-NJ for emacs-devel@gnu.org; Fri, 24 Aug 2012 06:49:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4rRj-0002Tj-RH for emacs-devel@gnu.org; Fri, 24 Aug 2012 06:49:01 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:36071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4rRg-0002TM-O7; Fri, 24 Aug 2012 06:48:57 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 9F20939E8019; Fri, 24 Aug 2012 03:48:55 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jUeQbIua-4Yk; Fri, 24 Aug 2012 03:48:53 -0700 (PDT) Original-Received: from [192.168.1.3] (pool-108-23-119-2.lsanca.fios.verizon.net [108.23.119.2]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 4259939E8017; Fri, 24 Aug 2012 03:48:53 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120714 Thunderbird/14.0 In-Reply-To: <5034A54F.6020006@cs.ucla.edu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152799 Archived-At: Bastien Roucari=C3=A8s mentioned that the 'backtrace' function and friends need the -lexecinfo linker flag on FreeBSD, so here's an updated version of the patch that does this. This affects only 'configure' and 'make', not Emacs itself. The NT and DOS builds are affected (a new makefile variable LIB_EXECINFO, which can be empty there) so I'm sending this to Eli and Juanma as a heads-up. =3D=3D=3D modified file 'ChangeLog' --- ChangeLog 2012-08-22 06:55:44 +0000 +++ ChangeLog 2012-08-24 10:43:12 +0000 @@ -1,3 +1,12 @@ +2012-08-24 Paul Eggert + + On assertion failure, print backtrace if available. + Merge from gnulib, incorporating: + 2012-08-24 execinfo: port to FreeBSD + 2012-08-22 execinfo: new module + * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. + * lib/execinfo.c, lib/execinfo.in.h, m4/execinfo.m4: New files. + 2012-08-22 Glenn Morris =20 * Makefile.in (install-arch-dep): If NO_BIN_LINK is non-null, =3D=3D=3D modified file 'admin/ChangeLog' --- admin/ChangeLog 2012-08-16 21:58:44 +0000 +++ admin/ChangeLog 2012-08-24 10:43:12 +0000 @@ -1,3 +1,8 @@ +2012-08-24 Paul Eggert + + On assertion failure, print backtrace if available. + * merge-gnulib (GNULIB_MODULES): Add execinfo. + 2012-08-16 Paul Eggert =20 Use ASCII tests for character types. =3D=3D=3D modified file 'admin/merge-gnulib' --- admin/merge-gnulib 2012-08-16 21:58:44 +0000 +++ admin/merge-gnulib 2012-08-22 08:59:10 +0000 @@ -28,7 +28,7 @@ GNULIB_MODULES=3D' alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 - dtoastr dtotimespec dup2 environ + dtoastr dtotimespec dup2 environ execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink =3D=3D=3D added file 'lib/execinfo.c' --- lib/execinfo.c 1970-01-01 00:00:00 +0000 +++ lib/execinfo.c 2012-08-22 08:59:10 +0000 @@ -0,0 +1,3 @@ +#include +#define _GL_EXECINFO_INLINE _GL_EXTERN_INLINE +#include "execinfo.h" =3D=3D=3D added file 'lib/execinfo.in.h' --- lib/execinfo.in.h 1970-01-01 00:00:00 +0000 +++ lib/execinfo.in.h 2012-08-22 08:59:10 +0000 @@ -0,0 +1,54 @@ +/* Information about executables. + + Copyright (C) 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see .= */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_EXECINFO_H +#define _GL_EXECINFO_H + +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_EXECINFO_INLINE +# define _GL_EXECINFO_INLINE _GL_INLINE +#endif + +_GL_EXECINFO_INLINE int +backtrace (void **buffer, int size) +{ + (void) buffer; + (void) size; + return 0; +} + +_GL_EXECINFO_INLINE char ** +backtrace_symbols (void *const *buffer, int size) +{ + (void) buffer; + (void) size; + return 0; +} + +_GL_EXECINFO_INLINE void +backtrace_symbols_fd (void *const *buffer, int size, int fd) +{ + (void) buffer; + (void) size; + (void) fd; +} + +_GL_INLINE_HEADER_END + +#endif =3D=3D=3D modified file 'lib/gnulib.mk' --- lib/gnulib.mk 2012-08-19 23:31:24 +0000 +++ lib/gnulib.mk 2012-08-22 08:59:10 +0000 @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=3D. --lib=3Dlibgnu --source-b= ase=3Dlib --m4-base=3Dm4 --doc-base=3Ddoc --tests-base=3Dtests --aux-dir=3D= build-aux --avoid=3Derrno --avoid=3Dfcntl --avoid=3Dfcntl-h --avoid=3Dfst= at --avoid=3Dmsvc-inval --avoid=3Dmsvc-nothrow --avoid=3Draise --avoid=3D= select --avoid=3Dsigprocmask --avoid=3Dsys_types --avoid=3Dthreadlib --ma= kefile-name=3Dgnulib.mk --conditional-dependencies --no-libtool --macro-p= refix=3Dgl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto= /md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 env= iron filemode getloadavg getopt-gnu gettime gettimeofday ignore-value int= props largefile lstat manywarnings mktime pselect pthread_sigmask readlin= k socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strt= oumax symlink sys_stat sys_time time timespec-add timespec-sub utimens wa= rnings +# Reproduce by: gnulib-tool --import --dir=3D. --lib=3Dlibgnu --source-b= ase=3Dlib --m4-base=3Dm4 --doc-base=3Ddoc --tests-base=3Dtests --aux-dir=3D= build-aux --avoid=3Derrno --avoid=3Dfcntl --avoid=3Dfcntl-h --avoid=3Dfst= at --avoid=3Dmsvc-inval --avoid=3Dmsvc-nothrow --avoid=3Draise --avoid=3D= select --avoid=3Dsigprocmask --avoid=3Dsys_types --avoid=3Dthreadlib --ma= kefile-name=3Dgnulib.mk --conditional-dependencies --no-libtool --macro-p= refix=3Dgl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto= /md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 env= iron execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-= value intprops largefile lstat manywarnings mktime pselect pthread_sigmas= k readlink socklen stat-time stdalign stdarg stdbool stdio strftime strto= imax strtoumax symlink sys_stat sys_time time timespec-add timespec-sub u= timens warnings =20 =20 MOSTLYCLEANFILES +=3D core *.stackdump @@ -150,6 +150,31 @@ =20 ## end gnulib module dup2 =20 +## begin gnulib module execinfo + +BUILT_SOURCES +=3D $(EXECINFO_H) + +# We need the following in order to create when the system +# doesn't have one that works. +if GL_GENERATE_EXECINFO_H +execinfo.h: execinfo.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/execinfo.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +execinfo.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES +=3D execinfo.h execinfo.h-t + +EXTRA_DIST +=3D execinfo.c execinfo.in.h + +EXTRA_libgnu_a_SOURCES +=3D execinfo.c + +## end gnulib module execinfo + ## begin gnulib module filemode =20 libgnu_a_SOURCES +=3D filemode.c =3D=3D=3D added file 'm4/execinfo.m4' --- m4/execinfo.m4 1970-01-01 00:00:00 +0000 +++ m4/execinfo.m4 2012-08-24 10:43:12 +0000 @@ -0,0 +1,31 @@ +# Check for GNU-style execinfo.h. + +dnl Copyright 2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_EXECINFO_H], +[ + AC_CHECK_HEADERS_ONCE([execinfo.h]) + + LIB_EXECINFO=3D'' + EXECINFO_H=3D'execinfo.h' + + if test $ac_cv_header_execinfo_h =3D yes; then + gl_saved_libs=3D$LIBS + AC_SEARCH_LIBS([backtrace_symbols_fd], [execinfo], + [test "$ac_cv_search_backtrace_symbols_fd" =3D "none required" |= | + LIB_EXECINFO=3D$ac_cv_search_backtrace_symbols_fd]) + LIBS=3D$gl_saved_libs + test "$ac_cv_search_backtrace_symbols_fd" =3D no || EXECINFO_H=3D'' + fi + + if test -n "$EXECINFO_H"; then + AC_LIBOBJ([execinfo]) + fi + + AC_SUBST([EXECINFO_H]) + AC_SUBST([LIB_EXECINFO]) + AM_CONDITIONAL([GL_GENERATE_EXECINFO_H], [test -n "$EXECINFO_H"]) +]) =3D=3D=3D modified file 'm4/gnulib-comp.m4' --- m4/gnulib-comp.m4 2012-08-19 23:31:24 +0000 +++ m4/gnulib-comp.m4 2012-08-22 08:59:10 +0000 @@ -53,6 +53,7 @@ # Code from module dtotimespec: # Code from module dup2: # Code from module environ: + # Code from module execinfo: # Code from module extensions: AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) # Code from module extern-inline: @@ -152,6 +153,7 @@ gl_UNISTD_MODULE_INDICATOR([dup2]) gl_ENVIRON gl_UNISTD_MODULE_INDICATOR([environ]) + gl_EXECINFO_H AC_REQUIRE([gl_EXTERN_INLINE]) gl_FILEMODE gl_GETLOADAVG @@ -534,6 +536,8 @@ lib/dtoastr.c lib/dtotimespec.c lib/dup2.c + lib/execinfo.c + lib/execinfo.in.h lib/filemode.c lib/filemode.h lib/ftoastr.c @@ -605,6 +609,7 @@ m4/clock_time.m4 m4/dup2.m4 m4/environ.m4 + m4/execinfo.m4 m4/extensions.m4 m4/extern-inline.m4 m4/filemode.m4 =3D=3D=3D modified file 'src/ChangeLog' --- src/ChangeLog 2012-08-24 04:37:57 +0000 +++ src/ChangeLog 2012-08-24 10:43:12 +0000 @@ -1,5 +1,11 @@ 2012-08-24 Paul Eggert =20 + On assertion failure, print backtrace if available. + * alloc.c [ENABLE_CHECKING]: Include . + (die) [ENABLE_CHECKING]: Print a backtrace if available. + * Makefile.in (LIB_EXECINFO): New macro. + (LIBES): Use it. + * buffer.c, buffer.h: Use bool for boolean. * buffer.c (reset_buffer_local_variables) (buffer_lisp_local_variables, Fset_buffer_modified_p) =3D=3D=3D modified file 'src/Makefile.in' --- src/Makefile.in 2012-08-20 23:57:35 +0000 +++ src/Makefile.in 2012-08-24 10:43:12 +0000 @@ -159,6 +159,8 @@ ## dbusbind.o if HAVE_DBUS, else empty. DBUS_OBJ =3D @DBUS_OBJ@ =20 +LIB_EXECINFO=3D@LIB_EXECINFO@ + SETTINGS_CFLAGS =3D @SETTINGS_CFLAGS@ SETTINGS_LIBS =3D @SETTINGS_LIBS@ =20 @@ -383,6 +385,7 @@ ## with GCC, we might need LIB_GCC again after them. LIBES =3D $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \ $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) $(DBUS_LIBS) \ + $(LIB_EXECINFO) \ $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS= ) \ $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ =3D=3D=3D modified file 'src/alloc.c' --- src/alloc.c 2012-08-21 23:39:56 +0000 +++ src/alloc.c 2012-08-22 08:59:10 +0000 @@ -6681,13 +6681,21 @@ } =20 #ifdef ENABLE_CHECKING + +# include + bool suppress_checking; =20 void die (const char *msg, const char *file, int line) { + enum { NPOINTERS_MAX =3D 500 }; + void *buffer[NPOINTERS_MAX]; + int npointers; fprintf (stderr, "\r\n%s:%d: Emacs fatal error: %s\r\n", file, line, msg); + npointers =3D backtrace (buffer, NPOINTERS_MAX); + backtrace_symbols_fd (buffer, npointers, STDERR_FILENO); abort (); } #endif