dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.18k stars 355 forks source link

GetCodeHeapList DAC API returns 0 sized code heap #1634

Closed noahfalk closed 3 years ago

noahfalk commented 3 years ago

Repro:

  1. Create a HelloWorld .Net Core app v3.1 (probably other versions work too) that hangs waiting for Console.ReadLine() to return
  2. Run the app and let it hang
  3. Write this code using CLRMD replacing the PID with the pid of your app
using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.DacInterface;
using System;

namespace ConsoleApp46
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using DataTarget dt = DataTarget.AttachToProcess(39768, suspend: true);  // replace the PID here
            ClrRuntime runtime = dt.ClrVersions[0].CreateRuntime();
            SOSDac dac = runtime.DacLibrary.SOSDacInterface;
            JitManagerInfo[] jitMgrs = dac.GetJitManagers();
            foreach(JitManagerInfo jmi in jitMgrs)
            {
                JitCodeHeapInfo[] heaps = dac.GetCodeHeapList(jmi.Address);
            }

        }
    }
}

Expected behavior: heaps[i].Address should have a non-zero value for some index because some code was jitted Actual behavior: There is only one heap reported and it has a zero value Address property (which means 0 sized code)

Similar bad behavior can be reproed with SOS running the EEHeap command and observing part of the output saying:

Jit code heap:
LoaderCodeHeap:    0000000000000000(0:0) Size: 0x0 (0) bytes.
Total size:        Size: 0x0 (0) bytes.
hoyosjs commented 3 years ago

This is a dupe of #1108

noahfalk commented 3 years ago

Cool, closing this as a dupe of #1108