From patchwork Tue Sep 11 22:53:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 183209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 862CA2C0080 for ; Wed, 12 Sep 2012 08:54:17 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348008857; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=OJRTSVh9O8h+NsKdM88kyeG059w=; b=ElQOpLyYYFHXfhM smktdkQAucrR2es1VWyKyIy8dufNxTCkMWno/aauogEQKmk8ohz5aU8QLlqUXBx7 RHuQE/23ykcUfmJH37AVi/GxQhSqnf8lTAjEnoG0hetUZt3/TM+QtrDgaQbDvfet MErjGTHq/QhvgpQut+92w/TGGROs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=CYDRSztqAYxWvSlUEENG4s3aYOKDFYNAlQDOjJFRsqa/UHbS2WhMtV8yor7LrC /rnQVsYpnkd6okvuW5w2DVopttE3lvDlDpHTZ4c4s3eV9zKl5/Xs5rmjmro6X2Dw ZOsfAzj6pIL/i8/so13QzZGtnvxMiZjDkp5vDLbVOixgU=; Received: (qmail 2102 invoked by alias); 11 Sep 2012 22:54:13 -0000 Received: (qmail 2089 invoked by uid 22791); 11 Sep 2012 22:54:09 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=BAYES_40, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Sep 2012 22:53:49 +0000 Received: by daks35 with SMTP id s35so595809dak.20 for ; Tue, 11 Sep 2012 15:53:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=8hKCVMYEVUggB+Sxm0OQzttwMBIMKXqFWWuraTLUdbg=; b=UonN1/GVkXpGSCtMyHKW+bJmgvs9MywK8CqsnGjnBddWrOhStWCDLgxoHhwiVcUzaC Vk4zFXJFAaVZyVotCSuid4FzrW3227XkvHUVMR8y02K5k1k4di7Xlbu5E6Cv4DSd6zc3 p8b9q7ajlkHPTgkImwyNO+Lcboxfrp7qcEp2lsiJaHP3y8JLSGu2tZWJ6afdubVmAtyc 4kD7bXTlTtCnBLJPqJa3mAKMJkceUuReY9xkSPpwGz9NCp/LHVion9kwaaCQ+KRHpJcD FfCcGRfnPxp1beTzy1dwHpDi8nv0mkG39XTkDuhnXg1vdbhzsoZxRsjTdg/tbiFa7rID lb8A== Received: by 10.66.73.7 with SMTP id h7mr28598400pav.34.1347404029195; Tue, 11 Sep 2012 15:53:49 -0700 (PDT) Received: by 10.66.73.7 with SMTP id h7mr28598369pav.34.1347404028762; Tue, 11 Sep 2012 15:53:48 -0700 (PDT) Received: from coign.google.com ([2620:0:1000:2404:224:d7ff:fe8f:f634]) by mx.google.com with ESMTPS id uh7sm10448837pbc.35.2012.09.11.15.53.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 15:53:45 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org Subject: Backtrace library [1/3] Date: Tue, 11 Sep 2012 15:53:39 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm7jsZSYVsG8+JoUwZdAGRaDFkjvwejNUMU88IEjYLGgKJhzmj3wMinpmgx6b/huKvBVLByVvTmKtmIB+WM7W6ELLaGWVFCjRN/Q//cuIJx/8GH5ppjYWa4nF3b/5Se7RHrDRMMxcMD4eSqj7xh+BzuCiiSg4kYNtrv8461Iqvwe/EbFN/IRdNJ1i5ICarp6f5SRSCH X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I have finished the initial implementation of the backtrace library I proposed at http://gcc.gnu.org/ml/gcc/2012-08/msg00317.html . I've separated the work into three patches. These patches only implement the backtrace library itself; actual use of the library will follow in separate patches. This initial implementation only supports ELF and DWARF. The library is designed to work correctly for other cases, in the sense that it will report that it can not find any backtrace information. The library is designed to make it straightforward to add support for other object file formats and debugging formats. My intent is to commit the library with ELF/DWARF support and then support other people in extending it. In particular, adding support for Mach-O and PE with DWARF should be simple. This patch is the interface to and configury of libbacktrace. I've separated these out as the parts of libbacktrace that require the most review. The interface to libbacktrace is in the file backtrace.h. This is what callers will use. The file backtrace-supported.h is also available so that programs can see whether calling the backtrace library will work at all. The configury is fairly standard. Note that libbacktrace is built as both a host library (to link into the compilers) and as a target library (to link into libgo and possibly other libraries). Bootstrapped on x86_64-unknown-linux-gnu in conjunction with the other two patches. OK for mainline? Ian 2012-09-11 Ian Lance Taylor * Initial implementation. Index: libbacktrace/README =================================================================== --- libbacktrace/README (revision 0) +++ libbacktrace/README (revision 0) @@ -0,0 +1,23 @@ +The libbacktrace library +Initially written by Ian Lance Taylor + +The libbacktrace library may be linked into a program or library and +used to produce symbolic backtraces. Sample uses would be to print a +detailed backtrace when an error occurs or to gather detailed +profiling information. + +The libbacktrace library is provided under a BSD license. See the +source files for the exact license text. + +The public functions are declared and documented in the header file +backtrace.h, which should be #include'd by a user of the library. + +Building libbacktrace will generate a file backtrace-supported.h, +which a user of the library may use to determine whether backtraces +will work. See the source file backtrace-supported.h.in for the +macros that it defines. + +As of September 2012, libbacktrace only supports ELF executables with +DWARF debugging information. The library is written to make it +straightforward to add support for other object file and debugging +formats. Index: libbacktrace/backtrace.h =================================================================== --- libbacktrace/backtrace.h (revision 0) +++ libbacktrace/backtrace.h (revision 0) @@ -0,0 +1,165 @@ +/* backtrace.h -- Public header file for stack backtrace library. + Copyright (C) 2012 Free Software Foundation, Inc. + Written by Ian Lance Taylor, Google. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + (1) Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + (2) Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + (3) The name of the author may not be used to + endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. */ + +#ifndef BACKTRACE_H +#define BACKTRACE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The backtrace code needs to open the executable file in order to + find the debug info. On systems that do not support + /proc/self/exe, the program using the backtrace library needs to + tell the backtrace library the name of the executable to open. It + does so by calling backtrace_set_executable_name. The FILENAME + argument must point to a permanent buffer. */ + +extern void backtrace_set_executable_name (const char *filename); + +/* The type of the callback argument to the backtrace function. DATA + is the argument passed to backtrace. PC is the program counter. + FILENAME is the name of the file containing PC, or NULL if not + available. LINENO is the line number in FILENAME containing PC, or + 0 if not available. FUNCTION is the name of the function + containing PC, or NULL if not available. This should return 0 to + continuing tracing. The FILENAME and FUNCTION buffers may become + invalid after this function returns. */ + +typedef int (*backtrace_callback) (void *data, uintptr_t pc, + const char *filename, int lineno, + const char *function); + +/* The type of the error callback argument to backtrace functions. + This function, if not NULL, will be called for certain error cases. + The DATA argument is passed to the function that calls this one. + The MSG argument is an error message. The ERRNUM argument, if + greater than 0, holds an errno value. The MSG buffer may become + invalid after this function returns. + + As a special case, the ERRNUM argument will be passed as -1 if no + debug info can be found for the executable, but the function + requires debug info (e.g., backtrace, backtrace_pcinfo). The MSG + in this case will be something along the lines of "no debug info". + Similarly, ERRNUM will be passed as -1 if there is no symbol table, + but the function requires a symbol table (e.g., backtrace_syminfo). + This may be used as a signal that some other approach should be + tried. */ + +typedef void (*backtrace_error_callback) (void *data, const char *msg, + int errnum); + +/* Get a full stack backtrace. SKIP is the number of frames to skip; + passing 0 will start the trace with the function calling backtrace. + DATA is passed to the callback routine. If any call to CALLBACK + returns a non-zero value, the stack backtrace stops, and backtrace + returns that value; this may be used to limit the number of stack + frames desired. If all calls to CALLBACK return 0, backtrace + returns 0. The backtrace function will make at least one call to + either CALLBACK or ERROR_CALLBACK. This function requires debug + info for the executable. */ + +extern int backtrace (int skip, backtrace_callback callback, + backtrace_error_callback error_callback, void *data); + +/* The type of the callback argument to the simple backtrace function. + DATA is the argument passed to simple_backtrace. PC is the program + counter. This should return 0 to continue tracing. */ + +typedef int (*backtrace_simple_callback) (void *data, uintptr_t pc); + +/* Get a simple backtrace. SKIP is the number of frames to skip, as + in backtrace. DATA is passed to the callback routine. If any call + to CALLBACK returns a non-zero value, the stack backtrace stops, + and simple_backtrace returns that value. Otherwise + simple_backtrace returns 0. The backtrace_simple function will + make at least one call to either CALLBACK or ERROR_CALLBACK. This + function does not require any debug info for the executable. */ + +extern int backtrace_simple (int skip, backtrace_simple_callback callback, + backtrace_error_callback error_callback, + void *data); + +/* Print the current backtrace in a user readable format to a FILE. + SKIP is the number of frames to skip, as in backtrace. Any error + messages are printed to stderr. This function requires debug info + for the executable. */ + +extern void backtrace_print (int skip, FILE *); + +/* Given PC, a program counter in the current program, call the + callback function with filename, line number, and function name + information. This will normally call the callback function exactly + once. However, if the PC happens to describe an inlined call, and + the debugging information contains the necessary information, then + this may call the callback function multiple times. This will make + at least one call to either CALLBACK or ERROR_CALLBACK. This + returns the first non-zero value returned by CALLBACK, or 0. */ + +extern int backtrace_pcinfo (uintptr_t pc, backtrace_callback callback, + backtrace_error_callback error_callback, + void *data); + +/* The type of the callback argument to backtrace_syminfo. DATA and + PC are the arguments passed to backtrace_syminfo. SYMNAME is the + name of the symbol for the corresponding code. SYMVAL is the + value. SYMNAME will be NULL if no error occurred but the symbol + could not be found. */ + +typedef void (*backtrace_syminfo_callback) (void *data, uintptr_t pc, + const char *symname, + uintptr_t symval); + +/* Given PC, a program counter in the current program, call the + callback information with the symbol name and value describing the + function in which PC may be found. This will call either CALLBACK + or ERROR_CALLBACK exactly once. This returns 1 on success, 0 on + failure. This function requires the symbol table but does not + require the debug info. Note that if the symbol table is present + but PC could not be found in the table, CALLBACK will be called + with a NULL SYMNAME argument. Returns 1 on success, 0 on + error. */ + +extern int backtrace_syminfo (uintptr_t pc, + backtrace_syminfo_callback callback, + backtrace_error_callback error_callback, + void *data); + +#ifdef __cplusplus +} /* End extern "C". */ +#endif + +#endif Index: libbacktrace/configure.ac =================================================================== --- libbacktrace/configure.ac (revision 0) +++ libbacktrace/configure.ac (revision 0) @@ -0,0 +1,256 @@ +# configure.ac -- Backtrace configure script. +# Copyright (C) 2012 Free Software Foundation, Inc. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: + +# (1) Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# (2) Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. + +# (3) The name of the author may not be used to +# endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +AC_PREREQ(2.64) +AC_INIT(package-unused, version-unused,, libbacktrace) +AC_CONFIG_SRCDIR(backtrace.h) +AC_CONFIG_HEADER(config.h) + +AC_CANONICAL_SYSTEM +target_alias=${target_alias-$host_alias} + +libtool_VERSION=1:0:0 +AC_SUBST(libtool_VERSION) + +AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define -Wall -Wno-portability]) + +AM_MAINTAINER_MODE + +AC_ARG_WITH(target-subdir, +[ --with-target-subdir=SUBDIR Configuring in a subdirectory for target]) + +# We must force CC to /not/ be precious variables; otherwise +# the wrong, non-multilib-adjusted value will be used in multilibs. +# As a side effect, we have to subst CFLAGS ourselves. +m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS]) +m4_define([_AC_ARG_VAR_PRECIOUS],[]) +AC_PROG_CC +m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) + +AC_SUBST(CFLAGS) + +AC_PROG_RANLIB + +AC_PROG_AWK +case "$AWK" in +"") AC_MSG_ERROR([can't build without awk]) ;; +esac + +LT_INIT([disable-shared]) +AM_PROG_LIBTOOL + +backtrace_supported=yes + +if test -n "${with_target_subdir}"; then + # We are compiling a GCC library. We can assume that the unwind + # library exists. + AM_ENABLE_MULTILIB(, ..) + BACKTRACE_FILE="backtrace.lo simple.lo" +else + AC_CHECK_HEADER([unwind.h], + [AC_CHECK_FUNC([_Unwind_Backtrace], + [BACKTRACE_FILE="backtrace.lo simple.lo"], + [BACKTRACE_FILE="nounwind.lo" + backtrace_supported=no])], + [BACKTRACE_FILE="nounwind.lo" + backtrace_supported=no]) +fi +AC_SUBST(BACKTRACE_FILE) + +AC_ARG_ENABLE([backtrace-threads], + AC_HELP_STRING([--enable-backtrace-threads], + [Specify that the backtrace library will be used by threaded programs]), + [case "$enableval" in + yes) backtrace_threads=yes ;; + no) backtrace_threads=no ;; + *) AC_MSG_ERROR([Unknown argument to --enable-backtrace-threads/--disable-backtrace-threads]) ;; + esac], + [if test -n "${with_target_subdir}"; then + backtrace_threads=yes + else + backtrace_threads=no + fi]) + +ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \ + -Wmissing-prototypes -Wold-style-definition \ + -Wmissing-format-attribute -Wcast-qual], + [WARN_FLAGS]) + +if test "x$GCC" = "xyes"; then + WARN_FLAGS="$WARN_FLAGS -Werror" +fi + +AC_SUBST(WARN_FLAGS) + +GCC_CHECK_UNWIND_GETIPINFO + +# When building as a target library, shared libraries may want to link +# this in. We don't want to provide another shared library to +# complicate dependencies. Instead, we just compile with -fPIC. +PIC_FLAG= +if test -n "${with_target_subdir}"; then + PIC_FLAG=-fPIC +fi +AC_SUBST(PIC_FLAG) + +# The library needs to be able to read the executable itself. Compile +# a file to determine the executable format. The awk script +# filetype.awk prints out the file type. +AC_CACHE_CHECK([output filetype], +[libbacktrace_cv_sys_filetype], +[filetype= +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([int i;], [int j;])], + [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`], + [AC_MSG_FAILURE([compiler failed])]) +libbacktrace_cv_sys_filetype=$filetype]) + +# Match the file type to decide what files to compile. +FORMAT_FILE= +case "$libbacktrace_cv_sys_filetype" in +elf*) FORMAT_FILE="elf.lo" ;; +*) AC_MSG_WARN([could not determine output file type]) + FORMAT_FILE="unknown.lo" + backtrace_supported=no + ;; +esac +AC_SUBST(FORMAT_FILE) + +# ELF defines. +elfsize= +case "$libbacktrace_cv_sys_filetype" in +elf32) elfsize=32 ;; +elf64) elfsize=64 ;; +esac +AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64]) + +BACKTRACE_SUPPORTED=0 +if test "$backtrace_supported" = "yes"; then + BACKTRACE_SUPPORTED=1 +fi +AC_SUBST(BACKTRACE_SUPPORTED) + +if test "$backtrace_threads" = "yes"; then + if test -n "${with_target_subdir}"; then + THREAD_FILE=gthread.lo + else + THREAD_FILE=thread.lo + fi +else + THREAD_FILE=nothread.lo +fi +AC_SUBST(THREAD_FILE) + +AC_CHECK_HEADERS(sys/mman.h) +if test "$ac_cv_header_sys_mman_h" = "no"; then + have_mmap=no +else + if test -n "${with_target_subdir}"; then + # When built as a GCC target library, we can't do a link test. We + # simply assume that if we have mman.h, we have mmap. + have_mmap=yes + else + AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no]) + fi +fi +if test "$have_mmap" = "no"; then + VIEW_FILE=read.lo + ALLOC_FILE=alloc.lo +else + VIEW_FILE=mmapio.lo + AC_PREPROC_IFELSE([ +#include +#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON) + #error no MAP_ANONYMOUS +#endif +], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo]) +fi +AC_SUBST(VIEW_FILE) +AC_SUBST(ALLOC_FILE) + +BACKTRACE_USES_MALLOC=0 +if test "$ALLOC_FILE" = "alloc.lo"; then + BACKTRACE_USES_MALLOC=1 +fi +AC_SUBST(BACKTRACE_USES_MALLOC) + +AC_CACHE_CHECK([whether tests can run], + [libbacktrace_cv_sys_native], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])], + [libbacktrace_cv_sys_native=yes], + [libbacktrace_cv_sys_native=no], + [libbacktrace_cv_sys_native=no])]) +AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes") + +if test "${multilib}" = "yes"; then + multilib_arg="--enable-multilib" +else + multilib_arg= +fi + +AC_CONFIG_FILES(Makefile backtrace-supported.h) + +# We need multilib support, but only if configuring for the target. +AC_CONFIG_COMMANDS([default], +[if test -n "$CONFIG_FILES"; then + if test -n "${with_target_subdir}"; then + # Multilibs need MULTISUBDIR defined correctly in certain makefiles so + # that multilib installs will end up installed in the correct place. + # The testsuite needs it for multilib-aware ABI baseline files. + # To work around this not being passed down from config-ml.in -> + # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually + # append it here. Only modify Makefiles that have just been created. + # + # Also, get rid of this simulated-VPATH thing that automake does. + cat > vpsed << \_EOF + s!`test -f '$<' || echo '$(srcdir)/'`!! +_EOF + for i in $SUBDIRS; do + case $CONFIG_FILES in + *${i}/Makefile*) + #echo "Adding MULTISUBDIR to $i/Makefile" + sed -f vpsed $i/Makefile > tmp + grep '^MULTISUBDIR =' Makefile >> tmp + mv tmp $i/Makefile + ;; + esac + done + rm vpsed + fi + fi +], +[ +# Variables needed in config.status (file generation) which aren't already +# passed by autoconf. +SUBDIRS="$SUBDIRS" +]) + +AC_OUTPUT Index: libbacktrace/backtrace-supported.h.in =================================================================== --- libbacktrace/backtrace-supported.h.in (revision 0) +++ libbacktrace/backtrace-supported.h.in (revision 0) @@ -0,0 +1,54 @@ +/* backtrace-supported.h.in -- Whether stack backtrace is supported. + Copyright (C) 2012 Free Software Foundation, Inc. + Written by Ian Lance Taylor, Google. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + (1) Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + (2) Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + (3) The name of the author may not be used to + endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. */ + +/* The file backtrace-supported.h.in is used by configure to generate + the file backtrace-supported.h. The file backtrace-supported.h may + be #include'd to see whether the backtrace library will be able to + get a backtrace and produce symbolic information. */ + + +/* BACKTRACE_SUPPORTED will be #define'd as 1 if the backtrace library + should work, 0 if it will not. Libraries may #include this to make + other arrangements. */ + +#define BACKTRACE_SUPPORTED @BACKTRACE_SUPPORTED@ + +/* BACKTRACE_USES_MALLOC will be #define'd as 1 if the backtrace + library will call malloc as it works, 0 if it will call mmap + instead. This may be used to determine whether it is safe to call + the backtrace functions from a signal handler. In general this + only applies to calls like backtrace and backtrace_pcinfo. It does + not apply to backtrace_simple, which never calls malloc. It does + not apply to backtrace_print, which always calls fprintf and + therefore malloc. */ + +#define BACKTRACE_USES_MALLOC @BACKTRACE_USES_MALLOC@ Index: libbacktrace/filetype.awk =================================================================== --- libbacktrace/filetype.awk (revision 0) +++ libbacktrace/filetype.awk (revision 0) @@ -0,0 +1,3 @@ +# An awk script to determine the type of a file. +/\177ELF\001/ { if (NR == 1) { print "elf32"; exit } } +/\177ELF\002/ { if (NR == 1) { print "elf64"; exit } } Index: libbacktrace/Makefile.am =================================================================== --- libbacktrace/Makefile.am (revision 0) +++ libbacktrace/Makefile.am (revision 0) @@ -0,0 +1,98 @@ +# Makefile.am -- Backtrace Makefile. +# Copyright (C) 2012 Free Software Foundation, Inc. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: + +# (1) Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# (2) Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. + +# (3) The name of the author may not be used to +# endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +ACLOCAL_AMFLAGS = -I .. -I ../config + +AM_CFLAGS = $(WARN_FLAGS) $(PIC_FLAG) -I $(srcdir)/../include -I ../libgcc + +noinst_LTLIBRARIES = libbacktrace.la + +libbacktrace_la_SOURCES = \ + backtrace.h \ + dwarf.c \ + fileline.c \ + internal.h \ + posix.c \ + print.c + +BACKTRACE_FILES = \ + backtrace.c \ + simple.c \ + nounwind.c + +FORMAT_FILES = \ + elf.c \ + unknown.c + +THREAD_FILES = \ + thread.c \ + gthread.c \ + nothread.c + +VIEW_FILES = \ + read.c \ + mmapio.c + +ALLOC_FILES = \ + alloc.c \ + mmap.c + +EXTRA_libbacktrace_la_SOURCES = \ + $(BACKTRACE_FILES) \ + $(FORMAT_FILES) \ + $(THREAD_FILES) \ + $(VIEW_FILES) \ + $(ALLOC_FILES) + +libbacktrace_la_LIBADD = \ + $(BACKTRACE_FILE) \ + $(FORMAT_FILE) \ + $(THREAD_FILE) \ + $(VIEW_FILE) \ + $(ALLOC_FILE) + +libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD) + +# Testsuite. + +check_PROGRAMS = + +TESTS = $(check_PROGRAMS) + +if NATIVE + +btest_SOURCES = btest.c +btest_CFLAGS = $(AM_CFLAGS) -g -O +btest_LDADD = libbacktrace.la + +check_PROGRAMS += btest + +endif NATIVE