You are not logged in.
Pages: 1
I use OnBeforeException event:
TSynLog.Family.OnBeforeException := mormotLogOnBeforeException;
How to get call stack in this event method? Is possible?
Offline
This is a very complex code, and also uses non-public methods and values such as TSynMapFile:
unit SynLog;
[...]
implementation
[...]
var
ExeInstanceMapFile: TSynMapFile;
function GetInstanceMapFile: TSynMapFile;
begin
[...]
end;
Should I duplicate this code and these objects?
I would have to use the only available class method that forces a TSynMapFile instance in the background:
class procedure TSynMapFile.Log(W: TTextWriter; aAddressAbsolute: PtrUInt; AllowNotCodeAddr: boolean);
...but this method requires TTextWriter, which I don't want to use in this case.
Wouldn't it be possible to make new, public method converting the callstack into text form in mORMot itself?
Please consider this solution.
Last edited by jaclas (2020-06-08 18:48:56)
Offline
How else are you going to get readable stack trace? There's no avoiding TSynMapFile.
Offline
I don't want to avoid TSynMapFile, I want to avoid having to duplicate code with SynLog (and problems with two TSynMapFile instances!). I just want the SynLog module to have a public function to read the callstack. This function could be used by TSynLog and external code (as I need it now).
Besides, TSynMapFile class should have one global instance (it is currently private).
A good solution would be to add a static class function to the TSynMapFile class, eg.:
class function TSynMapFile.GetCallStackAsStr(const CallStack: PPtrUInt) : TStrings;
or global function in a module, like this:
function GetCallStackAsStr(const CallStack: PPtrUInt) : TStrings;
This functionality would GREATLY extend the usability of SynLog! Even without a rest of mORMot!
Last edited by jaclas (2020-06-09 09:51:10)
Offline
I use TSynLog.Add.Log(all StackTrace, ...) and was very helpful.
Esteban
Offline
@EMartin
Once again... I need to get and pass a call stack to my code as a text/string, how does your example solve my problem?
Offline
The simplest solution is using the TSynLogFamiliy.EchoCustom:
/// can be set to a callback which will be called for each log line
// - could be used with a third-party logging system
// - EchoToConsole or EchoCustom can be activated separately
// - you may even disable the integrated file output, via NoFile := true
property EchoCustom: TOnTextWriterEcho read fEchoCustom write SetEchoCustom;
The EchoCustom receives the Level and the formated text, so you could use that text to do whatever you want.
Offline
Are you suggesting that I should read and parse the whole log to get a potential exception? Really?
I need to catch an exception, decode the call stack and send it somewhere... what you're recommending is a lot of over-the-top ideas.
I want SynLog (or other part of mormot) to let me convert the callstack (from OnBeforeException level) to thong with its internal tricks.
So, I just want Arnaud to refactor the code a bit and give external access to callstack conversion (using a private TSynMapFile instance)
Last edited by jaclas (2020-06-10 09:58:49)
Offline
Are you suggesting that I should read and parse the whole log to get a potential exception? Really?
I need to catch an exception, decode the call stack and send it somewhere... what you're recommending is a lot of over-the-top ideas.
I want SynLog (or other part of mormot) to let me convert the callstack (from OnBeforeException level) to thong with its internal tricks.
So, I just want Arnaud to refactor the code a bit and give external access to callstack conversion (using a private TSynMapFile instance)
You don't need to parse the whole log, just handle the levels that report exceptions (sllExceptionOS and sllException).
If you need another implementation, is not hard to extract all internal exception stack processing from
// this is the main entry point for all intercepted exceptions
procedure SynLogException(const Ctxt: TSynLogExceptionContext);
Anyway, since SynLog does not get callstack for delphi win64 I used JCLDebug (give it a look, although it has another disadvantages).
Offline
Arnaud, I know you have been very busy lately with changes in SQLite, but please read my above posts and think about making available in the interface section (public) of the methods to get/convert call stack... please :-)
Offline
Please try https://synopse.info/fossil/info/9a73c48c5d
Offline
Thanks Arnaud!
I still have a problem with the callstack, with the OnBeforeException event (from TSynLogFamily), it is almost empty, there is only a line calling the exception. The problem is probably not in the callstack extraction itself, because the EStackCount value of the aExceptionContext object is zero.
See:
Offline
Stack frames are active of course.
When I set result to True in OnBeforeException (so, SynLog catches and log an exception) then I get in log all data from call stack:
20200617 18310722 EXC EPathNotFoundException ("some example exception") [] at
6629ca Main.TfrmMain.btnMakeExceptionClick (96) stack trace API
6629ca Main.TfrmMain.btnMakeExceptionClick (96)
544d65 Vcl.Controls.TControl.Click (7537)
5492c0 Vcl.Controls.TWinControl.WndProc (10280)
55dec5 Vcl.StdCtrls.TButtonControl.WndProc (5308)
[...]
Offline
Arnaud, I prepare very simple example (dpr with 65 lines), please check this code and callstack readed from OnBeforeException event level:
I get this result (first part is result od event, second part is standard SynLog catching exsception log):
--- mormotLogOnBeforeException -------- begin --------
Exception class: Exception
line #0: onBeforeExceptionTest.InsideProc (38)
--- mormotLogOnBeforeException --------- end ----------
20200623 16272444 EXC Exception ("test exception from inside procedure") [] at
54cc89 onBeforeExceptionTest.InsideProc (38) stack trace API 54cc89 onBeforeEx
ceptionTest.InsideProc (38) 54ccec onBeforeExceptionTest.OutsideProc (43) 54ccf8
onBeforeExceptionTest.VeryOutsideProc (48) 54ce24 onBeforeExceptionTest.Main (5
8)
Why in OnBeforeException (where I use new introduced TSynMapFile.FindStackTrace() method) I can't get full stack?
Offline
Pages: 1