Recent

Author Topic: Display line info or stack trace on crash  (Read 916 times)

pleumann

  • Jr. Member
  • **
  • Posts: 95
Display line info or stack trace on crash
« on: April 11, 2022, 10:08:16 am »
Hello,

I am working on a somewhat complex command line application that is mostly self-contained and on pre-OO language level (only unit in uses clause is DOS). I find it hard to debug the occasional 216 crash because only the address is displayed. I googled a bit (result:compile with "-gl") and also consulted the FPC site where I found this example:

https://www.freepascal.org/docs-html/user/userse58.html

It all does not work for me, though. I do compile with "-gl", but all I ever get is the address. I added SysUtils for a try, which got me a stack trace of addresses, but no line numbers either.

I guess I am doing something wrong, but I don't see what. I am using Free Pascal 3.2.2 on a MacBook Air M1 with latest OS, but I am quite sure I had the same issues on an Intel Mac before. Is it something that doesn't work on MacOS due to different executable format?

Cheers
Joerg

Thaddy

  • Hero Member
  • *****
  • Posts: 16201
  • Censorship about opinions does not belong here.
Re: Display line info or stack trace on crash
« Reply #1 on: April 11, 2022, 10:28:58 am »
You should compile with -glh not just gl.
If I smell bad code it usually is bad code and that includes my own code.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11951
  • FPC developer.
Re: Display line info or stack trace on crash
« Reply #2 on: April 11, 2022, 10:31:51 am »
No. The h  is for  heap (memory leak) debugging, not crashes.

Do you start the -gl compiled program from the terminal, to see if it prints the traceback there?

pleumann

  • Jr. Member
  • **
  • Posts: 95
Re: Display line info or stack trace on crash
« Reply #3 on: April 11, 2022, 12:08:05 pm »
Yes, I compile and run on the terminal (or in VSC, sometimes).


korba812

  • Sr. Member
  • ****
  • Posts: 443
Re: Display line info or stack trace on crash
« Reply #4 on: April 11, 2022, 12:48:52 pm »
Maybe exception come from RTL (possibly in the initialization/finalization section of your program) and you have RTL compiled without debugging information?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10561
  • Debugger - SynEdit - and more
    • wiki
Re: Display line info or stack trace on crash
« Reply #5 on: April 11, 2022, 01:58:47 pm »
IIRC I did read somewhere that the line info does not work for MacOS. Not sure if that still applies (or ever did, but afaik others had the issue too)
Also iirc that applied to using dwarf. But I don't know if stabs is still supported for any MacOS targets, nor if it would then work with stabs.


You can try if the IDE (Lazarus, not FP) can resolve the address stack dump. (This may be broken if you use fpc 3.3.1 /not tested, but other related functionality has been reported broken)

Copy the addresses.
Menu: View > Leaks and traces
"Paste" button
"Resolve" button => open the (exact identical) exe that did print the stack dump (you may have to open the exe inside the bundle, not sure)

If you are in luck, it will add the line numbers. If not, I am out of ideas.

pleumann

  • Jr. Member
  • **
  • Posts: 95
Re: Display line info or stack trace on crash
« Reply #6 on: April 18, 2022, 12:52:40 pm »
With a bit of delay (due to vacation) thanks everyone who responded. I was able to resolve my specific crash using less elaborate means (i.e. WriteLn). I have not been able to make line numbers work. Maybe I'll try again on Ubuntu once I have access to my Ubuntu box at work, so I can check whether it's a problem with the MacOS compiler or a user error. :)

 

TinyPortal © 2005-2018