Skip to content

Commit 5ac12c3

Browse files
committed
Addressed feedback
1 parent 45d6e88 commit 5ac12c3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/DotNet/Pdb/PdbCustomDebugInfo.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,17 @@ protected virtual void InitializeDocuments() =>
11441144
Interlocked.CompareExchange(ref documents, new List<PdbDocument>(), null);
11451145
}
11461146

1147-
class PdbTypeDefinitionDocumentsDebugInfoMD : PdbTypeDefinitionDocumentsDebugInfo {
1147+
sealed class PdbTypeDefinitionDocumentsDebugInfoMD : PdbTypeDefinitionDocumentsDebugInfo {
11481148
readonly ModuleDef readerModule;
11491149
readonly IList<MDToken> documentTokens;
11501150

11511151
protected override void InitializeDocuments() {
11521152
var list = new List<PdbDocument>(documentTokens.Count);
1153-
for (var i = 0; i < documentTokens.Count; i++) {
1154-
if (readerModule.PdbState.tokenToDocument.TryGetValue(documentTokens[i], out var document))
1155-
list.Add(document);
1153+
if (readerModule.PdbState is not null) {
1154+
for (var i = 0; i < documentTokens.Count; i++) {
1155+
if (readerModule.PdbState.tokenToDocument.TryGetValue(documentTokens[i], out var document))
1156+
list.Add(document);
1157+
}
11561158
}
11571159
Interlocked.CompareExchange(ref documents, list, null);
11581160
}

src/DotNet/Pdb/PdbDocument.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public sealed class PdbDocument : IHasCustomDebugInformation {
5353
public IList<PdbCustomDebugInfo> CustomDebugInfos => customDebugInfos;
5454
IList<PdbCustomDebugInfo> customDebugInfos;
5555

56+
/// <summary>
57+
/// Gets the Metadata token of the document if available.
58+
/// </summary>
59+
public MDToken? MDToken { get; internal set; }
60+
5661
/// <summary>
5762
/// Default constructor
5863
/// </summary>
@@ -86,6 +91,7 @@ internal void Initialize(SymbolDocument symDoc) {
8691
customDebugInfos = new List<PdbCustomDebugInfo>();
8792
foreach (var cdi in symDoc.CustomDebugInfos)
8893
customDebugInfos.Add(cdi);
94+
MDToken = symDoc.MDToken;
8995
}
9096

9197
/// <summary>

src/DotNet/Pdb/PdbState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ PdbDocument Add_NoLock(PdbDocument doc) {
124124
if (docDict.TryGetValue(doc, out var orig))
125125
return orig;
126126
docDict.Add(doc, doc);
127+
if (doc.MDToken.HasValue)
128+
tokenToDocument.Add(doc.MDToken.Value, doc);
127129
return doc;
128130
}
129131

@@ -148,6 +150,8 @@ public bool Remove(PdbDocument doc) {
148150
#if THREAD_SAFE
149151
theLock.EnterWriteLock(); try {
150152
#endif
153+
if (doc.MDToken.HasValue)
154+
tokenToDocument.Remove(doc.MDToken.Value);
151155
return docDict.Remove(doc);
152156
#if THREAD_SAFE
153157
} finally { theLock.ExitWriteLock(); }
@@ -189,6 +193,7 @@ public List<PdbDocument> RemoveAllDocuments(bool returnDocs) {
189193
theLock.EnterWriteLock(); try {
190194
#endif
191195
var docs = returnDocs ? new List<PdbDocument>(docDict.Values) : null;
196+
tokenToDocument.Clear();
192197
docDict.Clear();
193198
return docs;
194199
#if THREAD_SAFE

0 commit comments

Comments
 (0)