From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9541 invoked by alias); 22 Apr 2003 17:05:15 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 9534 invoked from network); 22 Apr 2003 17:05:15 -0000 Received: from unknown (HELO localhost.redhat.com) (66.30.197.194) by sources.redhat.com with SMTP; 22 Apr 2003 17:05:15 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 081E22B2F; Tue, 22 Apr 2003 13:05:13 -0400 (EDT) Message-ID: <3EA57648.5080704@redhat.com> Date: Tue, 22 Apr 2003 17:05:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.2) Gecko/20030223 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jason Molenda Cc: Daniel Jacobowitz , =?ISO-8859-1?Q?Gerrit_Bruchh=E4?= =?ISO-8859-1?Q?user?= , gdb@sources.redhat.com Subject: Re: backtrace C-API References: <8ECA5848-745C-11D7-8838-000393D457E2@apple.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-SW-Source: 2003-04/txt/msg00247.txt.bz2 > > On Monday, April 21, 2003, at 02:04 PM, Andrew Cagney wrote: > > On Fri, Apr 18, 2003 at 02:33:27PM +0200, Gerrit Bruchhäuser wrote: > Hello, > is there any C-API function in libgdb.a (or some other library) which > returns a call stack (something 'bt' like)? > No; but you might find backtrace() useful if you're on a > glibc-supported platform. > > But there probably should. How hard is it to create a `target-self' that uses local memory, and a jump-buf for registers? The tricky bit, I see, is the symbol table assuming a single global structure. > > > This falls into the category of Nasty Hack, but I helped someone on our compiler group with a similar problem a long time ago. I had them add a call at the site of interest which (a) got the current process' pid, (b) wrote a little gdb command script into a /tmp file which would attach to the process, bt, and detach, (c) ran system ("gdb --command=/tmp...") in the function, and (d) removed the file from /tmp. > > I'm sure there are better ways to handle all this, but it took about five minutes to do all this correctly -- for a one-off problem, it wasn't a bad solution. They captured stdout, massaged the output a bit, and had the info they needed. It's actually a well accepted technique. I first learnt about it on a web page somewhere. Andrew