jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.71k stars 619 forks source link

Preserve original PDB path in Debug header #947

Closed sbomer closed 2 months ago

sbomer commented 3 months ago

Upstreaming change from https://github.com/dotnet/cecil/pull/183

When writing debug symbols, Cecil places them into a .pdb file adjacent to the .dll in the output. It also uses the path of this output .pdb as the path to the PDB in the .dll's CodeView Debug Directory entry, which breaks scenarios using PathMap.

This change fixes the PDB path in the CodeView Debug Directory entry to preserve the original path if it was present in the input .dll (but doesn't otherwise affect where Cecil looks for or writes out .pdb files).

Fixes https://github.com/dotnet/runtime/issues/99594.

sbomer commented 2 months ago

Closing, see https://github.com/dotnet/cecil/pull/183 for context. Seems the supported way to do this is to provide a custom symbol writer.

@jbevain if you would be open to a solution that could be shared by different cecil consumers, I could re-open this and make it conditioned on a flag. But there's no obvious place to pass through settings from WriterParameters to the symbol writer, so it might need some more thought, or changes to the API.