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
https://github.com/Qix-/better-exceptions
You just can't get the function parameters nor the source code line with a compiled executable!
ReplyDeleteA. 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.
ReplyDeleteplus.google.com - Why Delphi (like other developer environments) natively not included full cal...
ReplyDeleteI love EurekaLog (and I hate it when it's not available for a new Delphi version).
ReplyDeleteDelphi (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.
ReplyDeleteI 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.
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.
ReplyDeleteThe debugger tries to get the parameter values in the stack, but is often wrong because of what Eric Grange mentions.
ReplyDeleteI 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 (:
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.
ReplyDeleteJeroen 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
ReplyDeleteEdwin 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.
ReplyDeleteLars Fosdal I think so, I guess it depends on the reflection feature of the .net framework.
ReplyDeleteEdwin 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.
ReplyDeleteThomas 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!
ReplyDeleteThis functionality is out-of-the box in FPC, BTW.
A. Bouchez Can it unwind the stack to give you the full context of execution?
ReplyDeleteLars Fosdal Do you mean in FPC? Yes, you have the stack trace, on all supported platforms. :)
ReplyDeleteSee e.g. http://wiki.freepascal.org/Logging_exceptions
Lars Fosdal Do you mean with FPC? Yes, on all supported platforms - see wiki.freepascal.org - Logging exceptions - Free Pascal wiki
ReplyDeleteA. Bouchez I was thinking of the SynLog code.
ReplyDeleteLars 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
ReplyDeleteIncluding source code line numbers. And in fact, the .map content is embedded and compressed in a very efficient way - better than alternatives I know.
/sub
ReplyDelete