Search code examples
c#visual-studiodebuggingdiagnosticsclrmd

Can I use ClrMD to traverse only the objects that are used by the process in the fore ground?


Currently I could get all the objects that are present in heap using the below code using ClrMD. Is it posible to get only the set of objects that are used in the target process(i.e only the objects that are WITHIN to the souce code of the target process).

var types = heap.EnumerateObjectAddresses()
           .GroupBy(obj => heap.GetObjectType(obj).Name)
           .Select(group => new { Key = group.Key, Count = group.Count() })
           .OrderBy(type => type.Count);

foreach (var type in types)
Console.WriteLine("{0} {1}", type.Key, type.Count);
Console.ReadLine();

Solution

  • As far as I know, VS profile tool has the feature to collect the all callers (objects, functions) of a function while the program is running. is it what you want to get?

    Reference:

    How to list all calls of a function at runtime?

    Update:

    CLrMD does have classes for enumerating the PDB information. I suggest you try using the DataTarget class to enumerate the parameters/locals of a stack frame. They’ll have to add code to the DataTarget class to do so, as it doesn’t look like it currently supports it.