Path: utzoo!attcan!uunet!mcsun!unido!rwthinf!cip-s01!pmk From: pmk@cip-s01.informatik.rwth-aachen.de (Michael Keukert) Newsgroups: comp.lang.pascal Subject: Re: Help with stack overflow Keywords: turbo error trapping help stack Message-ID: <2577@rwthinf.UUCP> Date: 12 Apr 90 11:09:43 GMT References: <22863@uflorida.cis.ufl.EDU> Sender: news@rwthinf.UUCP Reply-To: pmk@cip-s01.UUCP (Michael Keukert) Distribution: comp Organization: Informatik RWTH Aachen Lines: 87 In article <22863@uflorida.cis.ufl.EDU> dor@beach.cis.ufl.edu (Douglas R. Oosting) writes: >I have a fairly large communications program in Turbo 5.0 which just >(apparently) dumped with a stack overflow. Ouch. How can I trap something >like this? I have the ExitPtr pointer set to a FAR routine {$F+} that >has no local variables (everything called in it is global to that unit) > Hi, There are three variables, which are useful to you. ExitProc has to be set on the (far-compiled) error handling routine, like you already did it. For the others: ExitProc := @own_exit_proc_name; ExitCode get`s a number between 0 and 255 which will indicate, what error occured. ErrorAddr is a pointer variable, which includes the segment and offset of the address where the error occured. You now have to declare your own, error handling procedure, which has to be far-compiled and whic mustn`t use external parameters. Within the procedure, you can reference other procedure or use as much variables you like. DANGER!!!! The normal TPascal exit-procedure HAS TO BE executed also, because it closes the files, reconstructs the interrupt vectors etc. So you have to save the original pointer first: SaveExitProc := ExitProc; Within your own procedure, you can set ErrorAddr to NIL. Doing this will cause no other errors. This means, your own procedure isn`t itself interrupted by a runtime error. Don`t forget to reload the exitproc BEFORE exiting your own procedure: ExitProc := SaveExitProc; Now a tiny example: {$f+} PROCEDURE myexit; VAR i:INETEGER; BEGIN WRITELN(`Error Number : `,ExitCode); ErrorAddr := NIL; ExitProc := SaveExitProc; END; {$F-} BEGIN {main} SaveExitProc := ExitProc; ExitProc := @myexit; [...] END. If you want to get the address of ErrorAddr, use this: TYPE errorptr = segment:word; offset:word; end; WRITELN (`Error at : `,errorptr(erroraddr).segment,`:`,errorptr(erroraddr).offset; This is known as TYPECASTING and allows you, to enable the compiler-range check. For example: VAR a:BYTE; b:STRING; a:=12; b:=STRING(a); For the results of typecasting, the programmer has to take care. No garantees are given ;-) OK, hope I helped you.... --------------------------------------------------------------------------- Michael Keukert, Elsasstrasse 58, D-5100 Aachen, FRG, Tel: +49 241 513297 Q Fido: Michael Keukert@Maus AC 2:242/2 ZNet:MICHAEL_KEUKERT!AC@ZERMAUS.ZER Twenty bucks per day plus expenses - hundred in advance. (Sam Spade)