This Python exception handling library shows a great stacktrace, I hope it can give some inspiration to @madExcept and others. I especially like the function parameter values are shown in the stack trace, but not sure it's possible with Delphi.

This Python exception handling library shows a great stacktrace, I hope it can give some inspiration to @madExcept and others. I especially like the function parameter values are shown in the stack trace, but not sure it's possible with Delphi.
https://github.com/Qix-/better-exceptions

Comments

  1. You just can't get the function parameters nor the source code line with a compiled executable!

    ReplyDelete
  2. A. Bouchez jcldebug can get the source line using the map file. It's beyond me why that functionality isn't available in Delphi out of the box.

    ReplyDelete
  3. I love EurekaLog (and I hate it when it's not available for a new Delphi version).

    ReplyDelete
  4. Delphi (and all optimized binaries) ofttimes mutates the parameters as part of optimizations, so you cannot get the value at entry point without "saving" the parameters somewhere.

    I suppose you could get "close" in Delphi by compiling with optimizations off, stack frames off, and running your binary inside a debugger. Not sure it would be worth the trouble though, might as well go for a script language directly, you'll gain plenty of other debugging niceties.

    ReplyDelete
  5. Eric Grange We've turned to stuffing context info into a TArray buffer which is added to any exception logging. That will at least give us a bit more to work from when trying to reproduce a problem.

    ReplyDelete
  6. The debugger tries to get the parameter values in the stack, but is often wrong because of what Eric Grange mentions.

    I like the idea by Lars Fosdal on storing context as you can tailor that to your needs. Be sure not to cause exceptions filling that context though (:

    ReplyDelete
  7. Jeroen Wiert Pluimers It is fairly brute force. A threadvar and simple methods to add to, clear and retrieve the buffer. Simple, but it works. Well, there was that one time where we forgot to clear in a loop... Let's just say there were copious amounts of context for that first error.

    ReplyDelete
  8. Jeroen Wiert Pluimers I remember I saw a c# library which can inject any code into any methods at the beginning or at the end. I don't remember its name nor I know if it's possible with Delphi, or it's completely another thing not relating to stack tracing here? Forgive me didn't dug into this field deep enough :P

    ReplyDelete
  9. Edwin Yip - Injection is possible in .NET intermediate code, but way harder in a compiled language such as as Delphi. You could in theory use a preprocessor to inject code into the source code before compilation - but then you would run into issues when debugging.

    ReplyDelete
  10. Lars Fosdal I think so, I guess it depends on the reflection feature of the .net framework.

    ReplyDelete
  11. Edwin Yip there are even tools on the .NET platform that do full IL rewriting to do this. You need a great detours library on Windows to get that done well for native code.

    ReplyDelete
  12. Thomas Mueller This was not my point. I know that you can get the source code line number (I've implemented it in SynLog, in a more efficient way than jcldebug), but not the source code itself!
    This functionality is out-of-the box in FPC, BTW.

    ReplyDelete
  13. A. Bouchez Can it unwind the stack to give you the full context of execution?

    ReplyDelete
  14. Lars Fosdal Do you mean in FPC? Yes, you have the stack trace, on all supported platforms. :)
    See e.g. http://wiki.freepascal.org/Logging_exceptions

    ReplyDelete
  15. Lars Fosdal Do you mean with FPC? Yes, on all supported platforms - see wiki.freepascal.org - Logging exceptions - Free Pascal wiki

    ReplyDelete
  16. A. Bouchez I was thinking of the SynLog code.

    ReplyDelete
  17. Lars Fosdal Yes, of course, even with Delphi 5 or under Kylix. See https://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_16
    Including source code line numbers. And in fact, the .map content is embedded and compressed in a very efficient way - better than alternatives I know.

    ReplyDelete

Post a Comment