You are not logged in.
I have application build with many dynamic loaded modules (dll). (loaded on need)
I tested TSynLog and discovered that after using SafeLoadLibrary automatic handling of exceptions doesn't work.
It happens because of overwriting RtlUnwindProc by SafeLoadLibrary -> _StartLib (System.pas).
So using TSynLog.Family.Level:= LOG_VERBOSE in begining of program setup RtlUnwindProc and SafeLoadLibrary restore orginal RtlUnwind.
Is it possible to use TSynLog with automatic handling of exception in application which is using dynamic loading libraries ?
Offline
With which version of the Delphi compiler?
I don't see any overwriting of RtlUnwindProc in SafeLoadLibrary itself. It may be in the library itself, which calls _startlib...
Have you some sample code ( publish e.g. it on https://pastebin.com ) to reproduce the issue?
Online
Thank you for quick reply.
I use Delphi 10 Seatle (Win32).
Here is example based on sample 11 - Exception logging
example program code (LibraryTest - procedure Test dynamically linked) - https://pastebin.com/g5yCSLWH
example library code (MyLibrary - procedure Test only raise exception) - https://pastebin.com/4yzGmz7p
You can see what is happening watching address RtlUnwindProc.
After TSynLog.Family.Level := LOG_VERBOSE; there is a change -> RtlUnwindProc is set (RTLUnwindProc := @SynRtlUnwind;)
After SafeLoadLibrary RtlUnWindProc is restored to orginal address
(SaveLoadLibrary System.pas -> _StartLib ->
version CPUX86
MOV EAX, offset RaiseException
MOV RaiseExceptionProc, EAX
MOV EAX, offset RTLUnwind
MOV RTLUnwindProc, EAX
version CPUX64 -> not assembler so more readable (for me)
// Setup exception handler
RaiseExceptionProc := @RaiseException;
RTLUnwindProc := @RTLUnwind;
)
Procedure statically linked (procedure Test; external 'MyLibrary.dll';) is working because
library is loaded first and then after TSynLog.Family.Level := LOG_VERBOSE; address is already setup correctly.
Another issue is how to use TSynLog, what is the best practise.
I'dont want add duplicatiing code (SynCommons, SynLog) to program and every dll so I built package mormot.bpl with SynCommons, SynLog and used it like runtime package in my program and dll.
It works ok. But in such case there is problem with locating map files. TSynMapFile uses fMapFile := GetModuleName(hInstance); and finding mormot.bpl instead exe or dll name.
Offline
Hi,
I think TSynlog is a wonderful tools . So we are trying to use TSynlog but it seems we have the same problem when we load dynamically a DLL.
Do you have a solution ?
Thanks
Offline
I run into this case too, same thing happen with version "Class: TSynLog 1.18.4001 FTS3"
Is there any news about it?
Thanks
Offline
Don't use packages, if you want to reduce the .dll file size.
If you want small executables and libraries, use FPC or a Delphi version prior to 2010.
Packages made sense to add components to the Delphi IDE when there was a few MB of RAM, but now it is not the case any more.
And sharing code between main exe and libraries induces some unneeded dependency between them.
But if someone is willing to debug the package support, feel free to contribute!
Online