Bug 44381

Summary: Debugger crash with domain unloading and VSTU
Product: [Mono] Runtime Reporter: Jonathan Chambers <joncham>
Component: DebuggerAssignee: Zoltan Varga <vargaz>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

Description Jonathan Chambers 2016-09-15 18:00:55 UTC
Hello,

I am hitting a crash with a recent master based branch debugging Unity embedded Mono with Visual Studio Tools for Unity.

1. During domain unload the debugger agent processes a `EVENT_KIND_ASSEMBLY_UNLOAD` event for an assembly being unloaded (was only in the unloaded domain). Note at this point the domain is already unloaded, most importantly the domain vtable cache on each MonoClass has been cleared for this domain.

2. The debugger agent thread gets a `CMD_ASSEMBLY_GET_OBJECT` command from VSTU. This calls `mono_assembly_get_object_checked` which attempts to construct an object for the assembly, including creating a new vtable from the already unloaded domain using the domain allocator.

3. We create this vtable and cache it in the MonoClass based on the unloaded domain’s id.

4. Domain unloads, domain allocator memory freed, new domain is created with *same id*

5. Attempt to create another assembly object and get a corrupt vtable


I can try to create a repro case independent of Unity/VSTU, but am have not done so currently.
Comment 1 Zoltan Varga 2016-11-17 19:19:50 UTC
Fixed in master/4.8, we now return an ERR_UNLOADED error in this case when GetAssemblyObject () is called after receiving an AssemblyUnload event.