Repository navigation
Fix null CustomDebugInfos in PdbDocument constructors - #585
Open
pcshrosbree wants to merge 1 commit into
Open
pcshrosbree wants to merge 1 commit into
pcshrosbree wants to merge 1 commit into
Conversation
new PdbDocument() and the six-argument constructor left CustomDebugInfos null; only Initialize(SymbolDocument) assigned it. The Portable PDB writer reads CustomDebugInfos.Count for every document, so writing a PDB that contains such a document threw NullReferenceException, and a caller could not add custom debug info to a new document. Create the list in those two constructors. The partial document that PdbState creates to look up an existing document still allocates no list, and documents read from a PDB still get theirs in Initialize().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #584
new PdbDocument()and the six-argument constructor leftCustomDebugInfosnull. Writing a Portable PDB that contains such a document then threwNullReferenceExceptioninMetadata.AddCustomDebugInformationList. This PR creates the list in those two constructors.Why this shape: 628db9b replaced the field initializer with an assignment in
Initialize(SymbolDocument). WhenPdbStatereads a PDB, it creates a partial document for each lookup (including one per sequence point) and callsInitializeonly for documents it has not seen before. So a lookup that finds an existing document allocates no list. This change keeps that: the private constructor behind the partial document is untouched, and documents read from a PDB still get their list inInitialize. Restoring the field initializer would allocate a list on every lookup. Making the writer null-tolerant would still leavedoc.CustomDebugInfos.Add(...)throwing on a new document.What I ran (dnlib's net6.0 build, .NET SDK 10.0.401, Linux x64):
Trueand throwsNullReferenceExceptionat master. With this change it printsFalseand writes the module and the PDB.new PdbDocument { ... }gives the same result.CustomDebugInfos.Addthrows. With this change, the PDB has one CustomDebugInformation row whose parent is that document, with the same blob.SizeOfDatafield, because I wrote them to different directories.Read, not run: the Windows PDB writer also dereferences the null list, when it emits a new document that a method's sequence point uses.
WindowsPdbWriter.Add(PdbDocument)callsTryGetCustomDebugInfo, which readsCustomDebugInfos.Count. I couldn't run that path, because it needs the native DiaSymReader and I'm on Linux.dnlib has no test project, so this PR adds no test. Here is the repro: