Skip to content

SymReader.GetMethodFromDocumentPosition doesn't always return the best method #196

Description

@KirillOsenkov

This logic to pick a single method from a line doesn't always return the best method and depends on the order of methods in the metadata table.

foreach (var (methodId, version) in methods)
{
if (candidate.Id.IsDefault || methodId < candidate.Id)
{
candidate = (methodId, version);
}
}

Methods can overlap, for example lambda bodies inside methods. An interesting case is that all instance fields initializers are unified into the constructor method, and the span of that ctor method starts at the beginning of the first field to the end of the last field (or the actual constructor itself). Same for static ctor.

Because of the way the overlapping methods are split into "layers" by PartitionToNonOverlappingSubsequences the methods with a smaller span usually end up in higher layers.

The current logic seems to pick the method that appears higher in the metadata table. Instead, it should pick the method with the smaller span (distance between the first and the last line). I think this is always just the last method.

I know that the correct way to do this is to use the GetMethodsFromDocumentPosition and then select the best match yourself, but feels like GetMethodFromDocumentPosition could always reliably return the correct method and it currently doesn't.

Microsoft.DiaSymReader.PortablePdb.dll!Microsoft.DiaSymReader.PortablePdb.SymReader.GetMethodFromDocumentPosition Line 498

Activity

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

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