Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links to source code #183

Open
hailstorm75 opened this issue Dec 7, 2021 · 7 comments
Open

Links to source code #183

hailstorm75 opened this issue Dec 7, 2021 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@hailstorm75
Copy link
Owner

hailstorm75 commented Dec 7, 2021

Describe the solution you'd like
The generated document should have links to the source code of the given type and its members.

Additional context
GitHub links to source code have the following format: https://github.com/user/repository/blob/branch/path/to/source.file#L12

GitLab links are similar:
https://gitlab.com/user/repository/-/blob/branch/path/to/source.file#L12

...where L12 means line 12

@hailstorm75 hailstorm75 added the enhancement New feature or request label Dec 7, 2021
@hailstorm75 hailstorm75 self-assigned this Dec 7, 2021
@hailstorm75
Copy link
Owner Author

@hailstorm75
Copy link
Owner Author

@hailstorm75
Copy link
Owner Author

So far, no functioning way of extracting the line numbers has been found. The only viable option is to parse source code files; however, this defeats the purpose of extracting member information via reflection.

@hailstorm75
Copy link
Owner Author

SharpPdb

var pdbManaged = SharpPdb.Managed.PdbFileReader.OpenPdb(string.Format(path, "pdb"));

var funToken = 100663301;
var function = pdbManaged.GetFunctionFromToken(funToken);

IPdbSequencePoint sequencePoint = function.SequencePoints[0];
Assert.Equal(0, sequencePoint.Offset);
Assert.Equal(22, sequencePoint.StartLine);
Assert.Equal(22, sequencePoint.EndLine);
Assert.Equal(23, sequencePoint.StartColumn);
Assert.Equal(24, sequencePoint.EndColumn);

var sources = pdb.Functions.SelectMany(f => f.SequencePoints).Select(sp => sp.Source).GroupBy(s => s.Name).Select(sg => sg.First());
Assert.Single(sources);
IPdbSource source = sources.First();
Assert.Equal("/home/travis/build/southpolenator/WinDbgCs_dumps/Source/Clr/SharedLibrary/SharedLibrary.cs", source.Name);

@hailstorm75
Copy link
Owner Author

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dnlib.DotNet;
using SharpPdb.Managed;

var results = new Dictionary<string, (string, int)[]>();

const string path = @"";

foreach (var file in Directory.EnumerateFiles(path, "*.pdb", SearchOption.AllDirectories))
{
  var module = ModuleDefMD.Load(file.Replace(".pdb", ".dll"));
  var tokens = module.GetTypes().SelectMany(t => t.Methods).ToDictionary(x => x.MDToken.Raw);

  var pdbFile = PdbFileReader.OpenPdb(file);
  var sequencePoints = pdbFile.Functions
    .Where(x => x.SequencePoints.Any())
    .Select(x => (tokens[(uint)x.Token].Name.String, x.SequencePoints.First().StartLine))
    .ToArray();
  if (sequencePoints.Length == 0)
    continue;

  results.Add(file, sequencePoints);
}

hailstorm75 added a commit that referenced this issue Jan 2, 2022
hailstorm75 added a commit that referenced this issue Jan 7, 2022
hailstorm75 added a commit that referenced this issue Jan 16, 2022
@hailstorm75
Copy link
Owner Author

The core functionality and UI is implemented; however, the results are inaccurate and there are rarely any links extracted...

@hailstorm75
Copy link
Owner Author

Some of the PDB's are source from obj\Debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant