Skip to content

GCRoot.EnumerateRootPaths does not return any elements #1474

Description

@raffaeler

Starting with .NET 10 I cannot find root paths anymore.

I created a small repro where I open a dump and try to find this well-known object (obj in the example) that is held in a static field of type List.

If I walk the references starting from the static field, I reach the object, therefore the dump is ok. But if I try the code below (which I took from the GCRoot demo and is supposed to walk backwards the tree), it does not find anything.

I read this note in a comment of GCRoot but I do not believe it is the culprit

// On .NET 10+ statics live in a single Object[] handle and stack roots may not include locals, so
// without these handles only 1 root path would exist.

Am I doing anything wrong?

    private void EnumPathv3(ClrHeap heap, ClrObject obj)
    {
        var targetAddress = obj.Address;

        GCRoot gcroot = new(heap, [targetAddress]);

        foreach ((ClrRoot root, GCRoot.ChainLink path) in gcroot.EnumerateRootPaths())
        {
            Console.Write($"{root} -> ");

            // Walk the chain of objects from the root to the target.
            GCRoot.ChainLink? link = path;
            while (link is not null)
            {
                Console.Write($"{link.Object:x}");
                link = link.Next;
                if (link is not null)
                    Console.Write(" -> ");
            }

            Console.WriteLine();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions