Stack capture in Free Pascal

I have a console application written in Free Pascal that, like most major applications, sometimes crashes. Since this application works live, I usually ask people to write me to the stack trace when it crashes - I distribute it with both debug and lineinfo. However, the application uses the FPC video.pas output, and sometimes stacktrace text output is not displayed.

Is there a way to intercept text that is written on unhandled exceptions with a stack, so I can write it to a file? I can’t just pass the standard error to a file, because the FPC video somehow doesn’t work with this, and I would also like people to just run the executable, not the batch or shell file.

As an example, I would like to catch this in a file or other output source:

ERangeError : Range check error
  $0048C0EA  TCELLS__GETCELL,  line 104 of dfmap.pas
  $004AD133  TDOOMGENERATOR__GENERATECITYDUNGEON,  line 397 of dfdungen.pas
  $004AF87D  TDOOMGENERATOR__GENERATE,  line 760 of dfdungen.pas
  $0041293B  TDOOM__RUN,  line 354 of doombase.pas
  $00401CD6  main,  line 51 of doomrl.pas

Any opportunity to make it clean?

+3
source share
1 answer

Two (system units) of the procedure variables are involved here:

  • Exceptproc that handles the exception
  • and backtracestrfunc , which processes the address to search for lineinfo.

Current iirc processing is layered

  • the system unit only completes with an error, but defines the above procedure variables to override this.
  • sysutils RTE exceptproc (sysutils.catchunhandledexception)
  • line ( stabs) linfodward (dwarf, 2.4.0+) backtracestrfunc, lineinfo.

:

  • sysutils.catchunhandledexception .
  • - , , ( )
  • functionanme exceptproc

, lineinfo , -gl

+2

Source: https://habr.com/ru/post/1726013/


All Articles