From owner-freebsd-questions Fri May 24 04:15:33 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id EAA19069 for questions-outgoing; Fri, 24 May 1996 04:15:33 -0700 (PDT) Received: from diablo.ppp.de (diablo.ppp.de [193.141.101.34]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id EAA19052 for ; Fri, 24 May 1996 04:15:27 -0700 (PDT) Received: from allegro.lemis.de by diablo.ppp.de with smtp (Smail3.1.28.1 #1) id m0uMuop-000QYhC; Fri, 24 May 96 13:14 MET DST From: grog@lemis.de (Greg Lehey) Organisation: LEMIS, Schellnhausen 2, 36325 Feldatal, Germany Phone: +49-6637-919123 Fax: +49-6637-919122 Received: (grog@localhost) by allegro.lemis.de (8.6.9/8.6.9) id MAA08611; Fri, 24 May 1996 12:04:34 +0200 Message-Id: <199605241004.MAA08611@allegro.lemis.de> Subject: Re: stack trace library? To: msmith@atrad.adelaide.edu.au (Michael Smith) Date: Fri, 24 May 1996 12:04:34 +0200 (MET DST) Cc: archie@whistle.com, freebsd-questions@freebsd.org In-Reply-To: <199605230519.OAA07249@genesis.atrad.adelaide.edu.au> from "Michael Smith" at May 23, 96 02:49:14 pm X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Michael Smith writes: > > Archie Cobbs stands accused of saying: >> >> Does there exist a library with routines that a program (linked with -g) >> can use for doing stack crawls? > > 'man nlist' may help. > >> For example, suppose you >> >> signal(SIGSEGV, CatchBug); >> >> Then when CatchBug() is called, you want the program to display a >> stack trace from the point at which the signal occurred, a la gdb's >> "where" command. Then we could have self debugging programs! :-) > > Note that it would probably almost as easy to fork off a subprocess, start > gdb and attach it to the offending process, run a few commands in it, > detach it and exit. I think it would be easier. I was thinking of doing something like this recently. One of the biggest problems people have in debugging multiple processes is that you can't easily debug a process started by another (non-shell) process. Sure, you can attach to the process (wonderful feature!), but you can't catch it from the start, and you can't catch it if it gets a fatal signal. It occurred to me that it would be relatively simple to add a couple of environment variables, say, "START_DEBUGGER" and "TRAP_DEBUGGER". crt0.o (the 'start' function which calls main ()) would look for START_DEBUGGER. If it found it, it would spawn the debugger specified as the value of the variable, and let it control it. TRAP_DEBUGGER would work similarly as a default trap handler for terminating a process. Instead of terminating the process, it would cause it to spawn a debugger and transfer control of the process to it. What do people think? I could hack up a prototype pretty quickly if there's enough interest (and no show-stopping conceptual problems). Follow up to -hackers, please. Greg