Skip to content

Better diagnostic for collected delegate #9418

Closed

Description

Current version of CoreCLR contains code for supporting MDAs. It is compiled and some parts of it were removed as dead. MDAs are very useful to detect application bugs that related to transitions beetween managed and unmanaged code, for example, to detect calls of collected delegates.

I've tried to enable current implementation of MDAs in coreclr (dotnet/coreclr#15464):

  • I've added xmlparser project to coreclr
  • I've added some previously deleted files (mda.cpp, mdadac.cpp, etc.)

After several fixes CallbackOnCollectedDelegate MDA starts work for me:

$ COMPlus_MDA=1 ./corerun delegategc.dll
Press ESC to stop
register_callback:0x7fe44088316c ----
force GC!!!
upcall ----
A callback was made on a garbage collected delegate of type 'delegategc!DelegateGC.Program+Callback::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.StubHelpers.StubHelpers.CheckCollectedDelegateMDA(IntPtr pEntryThunk)
   at DelegateGC.Program.upcall()
   at DelegateGC.Program.MyView_KeyEvent(ConsoleKeyInfo keyInfo) in /home/kbaladurin/Desktop/dotnet/coredumps/lldb/dotnet/delegategc/Program.cs:line 65
   at DelegateGC.Program.Main(String[] args) in /home/kbaladurin/Desktop/dotnet/coredumps/lldb/dotnet/delegategc/Program.cs:line 85
Aborted (core dumped)

Is it correct approach to enable MDAs or have you another plans about it?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions