randy@ncifcrf.UUCP (The Computer Grue) (10/28/87)
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? Ie. about the same kind of output that you might get from doing a core dump at that point in the program and typing 'where' under dbx? I'd like to do this several times in a running image, so I don't want to actually cause the core dump. Any ideas? I'm running under Sun OS 3.4, but I would think that this kind of program could be used in outline on several different types of Unix systems. -- Randy -- Randy Smith @ NCI Supercomputer Facility c/o PRI, Inc. Phone: (301) 698-5660 PO Box B, Bldng. 430 Uucp: ...!uunet!mimsy!elsie!ncifcrf!randy Frederick, MD 21701 Arpa: elsie!ncifcrf!randy@mimsy.umd.edu
stpeters@dawn.steinmetz (Dick St.Peters) (11/01/87)
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? -- Dick St.Peters GE Corporate R&D, Schenectady, NY stpeters@ge-crd.arpa uunet!steinmetz!stpeters
larry@hcr.UUCP (11/09/87)
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.
gfm@devel.cats.oz (Graham Menhennitt) (11/12/87)
In article <2925@hcr.UUCP> larry@hcr.UUCP (Larry Philps) writes: > ..... It does not have to be compiler >dependent, but that depends on the compiler writer. Isn't that just a slight contradiction in terms?? -- Graham Menhennitt ACSnet: gfm@devel.cats.oz Networking II Project Manager UUCP: ...!uunet!munnari!devel.cats.oz!gfm Cats Co., Melbourne, Australia. Phone: +61 3 5224246