From patchwork Thu Oct 11 11:53:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 190880 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 A11D22C0085 for ; Thu, 11 Oct 2012 22:54:14 +1100 (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=1350561258; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Cc:Subject:References:Date:In-Reply-To: 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=vsHzAhszTnv401Qk5XpS8d3e4H8=; b=nX/AGuFq2fscMIr9BOqqsjWTBQqQ/vIPZq/Vd81revbpo9VsDlxNFqXSkIlI19 cM8EoCbEgt8pvrYLgbUe1i8fQtonBp53bhPh0hpIresg2AcqUSZ8/mFU0thxJQmG wQH+3Zqn5SZgVc00AQjyTfL1RP+r5i69jnIMZ86/jWCT8= 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:Received:Received:Received:From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=nKFMBO54c36ym/bsSosdEGnm8oHIid25losAIdzb8SPbKyPQfGsYBpc+BDwfyL nox7AbAii2Rt49+jr14wBBGKAQS+wRLyWs8vC+ygknMdvlHjlbryslt3bFrqEj5U ohzMNNcxBZ4R4JL7dvUv2Q4+6f32eO2I4R6IiQwyTUESk=; Received: (qmail 14708 invoked by alias); 11 Oct 2012 11:54:06 -0000 Received: (qmail 14698 invoked by uid 22791); 11 Oct 2012 11:54:04 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from snape.CeBiTec.Uni-Bielefeld.DE (HELO smtp-relay.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 11 Oct 2012 11:53:56 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 146381F39; Thu, 11 Oct 2012 13:53:55 +0200 (CEST) Received: from smtp-relay.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Z+ioEyX4L1iw; Thu, 11 Oct 2012 13:53:52 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (manam.CeBiTec.Uni-Bielefeld.DE [129.70.161.120]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id DF8F11F33; Thu, 11 Oct 2012 13:53:45 +0200 (CEST) Received: (from ro@localhost) by manam.CeBiTec.Uni-Bielefeld.DE (8.14.5+Sun/8.14.5/Submit) id q9BBriqo016099; Thu, 11 Oct 2012 13:53:44 +0200 (MEST) From: Rainer Orth To: Ian Lance Taylor Cc: Gerald Pfeifer , gcc-patches@gcc.gnu.org Subject: Re: [libbacktrace] Use getexecname() on Solaris References: Date: Thu, 11 Oct 2012 13:53:44 +0200 In-Reply-To: (Ian Lance Taylor's message of "Fri, 5 Oct 2012 06:49:34 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (usg-unix-v) MIME-Version: 1.0 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 Ian Lance Taylor writes: > On Fri, Oct 5, 2012 at 4:21 AM, Rainer Orth wrote: >> >> I think this should work. The only complication might be that users of >> DEFAULT_PROCESS_FILENAME need to include on Solaris to get >> the declaration of getexecname(). Given that this header is already >> used unconditionally, its inclusion should probably be moved to either >> internal.h (which doesn't yet include anything) or backtrace.h. Ian, >> what do you prefer here? > > Definitely not backtrace.h. I think I would prefer that print.c > simply #include directly. Ok, here's the merged patch, tested on i386-pc-solaris2.10. Ok for mainline? Rainer 2012-10-05 Rainer Orth Gerald Pfeifer libbacktrace: * configure.ac: Check for getexecname. * configure: Regenerate. * config.h.in: Regenerate. * internal.h (DEFAULT_PROCESS_FILENAME): Define. * fileline.c (fileline_initialize): Use it. * print.c (error_callback): Likewise. Include . # HG changeset patch # Parent e43e8e91417064d0dcfb3b9ec0c2833d7ce00792 Use getexecname() on Solaris diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -260,6 +260,19 @@ fi AC_CHECK_DECLS(strnlen) +# Check for getexecname function. +if test -n "${with_target_subdir}"; then + case "${host}" in + *-*-solaris2*) have_getexecname=yes ;; + *) have_getexecname=no ;; + esac +else + AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no]) +fi +if test "$have_getexecname" = "yes"; then + AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.]) +fi + AC_CACHE_CHECK([whether tests can run], [libbacktrace_cv_sys_native], [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])], diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c --- a/libbacktrace/fileline.c +++ b/libbacktrace/fileline.c @@ -82,7 +82,8 @@ fileline_initialize (struct backtrace_st if (state->filename != NULL) descriptor = backtrace_open (state->filename, error_callback, data); else - descriptor = backtrace_open ("/proc/self/exe", error_callback, data); + descriptor = backtrace_open (DEFAULT_PROCESS_FILENAME, error_callback, + data); if (descriptor < 0) failed = 1; diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h --- a/libbacktrace/internal.h +++ b/libbacktrace/internal.h @@ -56,6 +56,14 @@ POSSIBILITY OF SUCH DAMAGE. */ # endif #endif +#ifdef __FreeBSD__ +# define DEFAULT_PROCESS_FILENAME "/proc/curproc/file" +#elif defined(HAVE_GETEXECNAME) +# define DEFAULT_PROCESS_FILENAME getexecname () +#else +# define DEFAULT_PROCESS_FILENAME "/proc/self/exe" +#endif + #ifndef HAVE_SYNC_FUNCTIONS /* Define out the sync functions. These should never be called if diff --git a/libbacktrace/print.c b/libbacktrace/print.c --- a/libbacktrace/print.c +++ b/libbacktrace/print.c @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include #include +#include #include "backtrace.h" #include "internal.h" @@ -73,7 +74,7 @@ error_callback (void *data, const char * name = pdata->state->filename; if (name == NULL) - name = "/proc/self/exe"; + name = DEFAULT_PROCESS_FILENAME; fprintf (stderr, "%s: libbacktrace: %s", name, msg); if (errnum > 0) fprintf (stderr, ": %s", strerror (errnum));