From owner-freebsd-hackers@freebsd.org Thu Jul 6 22:58:12 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1783AD940D0 for ; Thu, 6 Jul 2017 22:58:12 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-pg0-f44.google.com (mail-pg0-f44.google.com [74.125.83.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E3D4A82E87 for ; Thu, 6 Jul 2017 22:58:11 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-pg0-f44.google.com with SMTP id t186so7793963pgb.1 for ; Thu, 06 Jul 2017 15:58:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=mQeu+BJvQMsUCTeFtT18t5a+x08ImtXxot+2yyy/Mtw=; b=X+i72C9KYj+ZDFXTN2ZGDjsHdyf+94vTb1pVD00yw3KgdDYDMK7/u00Yyt+APpCnhS 525ra8kF9bOGlSEZxCmgbbEbb3oXy18eF6eeo5nASeF+8yZTBZNxHVvA8r4GCOwC59wf +i/eQZZFKtylZlz+A/cJ++uur6VUzorLW3olbln08EGiboqHP5CQWlFngAW0VS4MvfzH y26BZIXe6D1Bp8LiypIGGc+qt42qPo5pTMB2xWXFgmTdcj6lf45TdpjPdJXYm/ZLY6SO 1R/rsCVoA1ZRSPFB+1jwC9L/twq9Lure4k3qQL8OoQZZQWXsTH85dz7uvVJM4eijNOuY WU/w== X-Gm-Message-State: AIVw110U/ZYsNhGZuQSGdSPuCOTBOZce0Z6OlGlaomMKszHDuBfP3G4H jHRqlYN+frHgAGMKoRY= X-Received: by 10.98.78.88 with SMTP id c85mr28817062pfb.17.1499381885482; Thu, 06 Jul 2017 15:58:05 -0700 (PDT) Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com. [209.85.192.174]) by smtp.gmail.com with ESMTPSA id p15sm2388182pfi.99.2017.07.06.15.58.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jul 2017 15:58:05 -0700 (PDT) Received: by mail-pf0-f174.google.com with SMTP id e7so7775402pfk.0 for ; Thu, 06 Jul 2017 15:58:05 -0700 (PDT) X-Received: by 10.84.150.164 with SMTP id h33mr31500265plh.152.1499381885221; Thu, 06 Jul 2017 15:58:05 -0700 (PDT) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.100.146.15 with HTTP; Thu, 6 Jul 2017 15:58:04 -0700 (PDT) In-Reply-To: <4d662753-98bc-1275-9394-0cda95eedc65@xiplink.com> References: <4d662753-98bc-1275-9394-0cda95eedc65@xiplink.com> From: Conrad Meyer Date: Thu, 6 Jul 2017 15:58:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: libexecinfo backtrace() in a signal handler To: Marc Branchaud Cc: "freebsd-hackers@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jul 2017 22:58:12 -0000 On Thu, Jul 6, 2017 at 2:02 PM, Marc Branchaud wrote: > Howdy, > > (Please CC replies to me, as I am not subscribed. Apologies if I'm in the > wrong forum!) > > I'm trying to use libexecinfo's backtrace() in a SIGSEGV handler. It only > finds one single frame in the stack, for the signal handler function. > (Outside of the signal handler backtrace() does return the full stack from > the call point.) > > Is there any way to get the stack from where the SIGSEGV arose? A few hours > of Googling has proved fruitless. > > My overall goal is to intercept core-dumping signals to try to save a > textual backtrace instead of a full dump (as they can be quite large in my > application). So I'd also like to catch SIGBUS, and maybe SIGFPE too. Hi Marc, Signal handlers use a special stack frame that libexecinfo is too simple to understand. To get a stack from a signal handler, you might want to use libunwind instead. Best, Conrad