Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!lsuc!hcr!larry From: larry@hcr.UUCP Newsgroups: comp.unix.wizards Subject: Re: Stack trace from inside a program . . . Message-ID: <2925@hcr.UUCP> Date: Mon, 9-Nov-87 10:04:03 EST Article-I.D.: hcr.2925 Posted: Mon Nov 9 10:04:03 1987 Date-Received: Tue, 10-Nov-87 02:40:19 EST References: <151@ncifcrf.UUCP> <7741@steinmetz.steinmetz.UUCP> Reply-To: larry@hcr.UUCP (Larry Philps) Organization: HCR Corporation, Toronto Lines: 27 Keywords: dbx 'where' C innards In article <7741@steinmetz.steinmetz.UUCP> dawn!stpeters@steinmetz.UUCP (Dick St.Peters) writes: >In article <151@ncifcrf.UUCP> randy@ncifcrf.UUCP (The Computer Grue) writes: >> I have a question for the net: how would one go about writing a C >> function that would give you a stack trace of all calls to that >> function? > >I did this once under VMS. The experience strongly suggests such a >function would be machine-, system-, and even compiler-dependent. >(It was different for the two C compiler I had.) > >True in general? Yup. It definitely depends on the format of the call frame, which itself is hardware dependent. It does not have to be compiler dependent, but that depends on the compiler writer. If you want object files from different compilers to be able to link together, both better just stick to the machine spec. Anyway, the easiest way to do this is to go find the source to adb, sdb, dbx, or whatever on your machine and find the routine that implements the stack trace. Steal it and modify it to fit into your machine. Just put a couple of "asm" instructions at the front to get the stack pointer and frame pointer registers into some local variable, and you are set. If you don't have the source to any of these programs, read the machine and/or compiler spec, and find out the format of a call frame. Sorry.