Skip to content

Commit 17667ba

Browse files
committed
Fixing bug where functions that were jitted after domain reload completed were not being picked up.
1 parent f74452c commit 17667ba

File tree

4 files changed

+88
-37
lines changed

4 files changed

+88
-37
lines changed

.idea/.idea.UnityMixedCallstack/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FuzzyRangeComparer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ struct Range
88
public ulong End;
99
public string Name;
1010
public string File;
11+
12+
public override string ToString()
13+
{
14+
return $"{File}::{Name} -- IP Range: {Start:X16} -> {End:X16}";
15+
}
1116
}
1217
class FuzzyRangeComparer : IComparer<Range>
1318
{

PmipReader.cs

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-

2-
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Globalization;
64
using System.IO;
@@ -13,8 +11,22 @@ public class PmipReader
1311
private static List<Range> _rangesSortedByIp = new List<Range>();
1412
private static List<Range> _legacyRanges = new List<Range>();
1513
private static FuzzyRangeComparer _comparer = new FuzzyRangeComparer();
16-
private static FileStream _fileStream;
17-
private static StreamReader _fileStreamReader;
14+
15+
private struct PmipStreams
16+
{
17+
public FileStream fileStream;
18+
public StreamReader fileStreamReader;
19+
20+
public void Dispose()
21+
{
22+
fileStreamReader.Dispose();
23+
fileStreamReader = null;
24+
fileStream.Dispose();
25+
fileStream = null;
26+
}
27+
}
28+
29+
private static Dictionary<string, PmipStreams> _currentFiles = new Dictionary<string, PmipStreams>();
1830

1931
public static void Sort()
2032
{
@@ -24,46 +36,56 @@ public static void Sort()
2436

2537
public static void DisposeStreams()
2638
{
27-
_fileStreamReader?.Dispose();
28-
_fileStreamReader = null;
29-
30-
_fileStream?.Dispose();
31-
_fileStream = null;
39+
foreach (PmipStreams streams in _currentFiles.Values)
40+
streams.Dispose();
41+
_currentFiles.Clear();
3242

3343
_rangesSortedByIp.Clear();
44+
_legacyRanges.Clear();
3445
}
3546
public static bool ReadPmipFile(string filePath)
3647
{
37-
//_debugPane?.OutputString("MIXEDCALLSTACK :: Reading pmip file: " + filePath + "\n");
38-
DisposeStreams();
39-
try
48+
var _debugPane = UnityMixedCallstackFilter._debugPane;
49+
#if DEBUG
50+
_debugPane?.OutputString("MIXEDCALLSTACK :: Reading pmip file: " + filePath + "\n");
51+
#endif
52+
//DisposeStreams();
53+
54+
if (!_currentFiles.TryGetValue(filePath, out PmipStreams pmipStreams))
4055
{
41-
_fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
42-
_fileStreamReader = new StreamReader(_fileStream);
43-
var versionStr = _fileStreamReader.ReadLine();
44-
const char delimiter = ':';
45-
var tokens = versionStr.Split(delimiter);
56+
pmipStreams = new PmipStreams();
57+
try
58+
{
59+
pmipStreams.fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
60+
pmipStreams.fileStreamReader = new StreamReader(pmipStreams.fileStream);
61+
var versionStr = pmipStreams.fileStreamReader.ReadLine();
62+
const char delimiter = ':';
63+
var tokens = versionStr.Split(delimiter);
4664

47-
if (tokens.Length != 2)
48-
throw new Exception("Failed reading input file " + filePath + ": Incorrect format");
65+
if (tokens.Length != 2)
66+
throw new Exception("Failed reading input file " + filePath + ": Incorrect format");
4967

50-
if (!double.TryParse(tokens[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var version))
51-
throw new Exception("Failed reading input file " + filePath + ": Incorrect version format");
68+
if (!double.TryParse(tokens[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var version))
69+
throw new Exception("Failed reading input file " + filePath + ": Incorrect version format");
5270

53-
if (version > 2.0)
54-
throw new Exception("Failed reading input file " + filePath + ": A newer version of UnityMixedCallstacks plugin is required to read this file");
55-
}
56-
catch (Exception ex)
57-
{
58-
//_debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
59-
DisposeStreams();
60-
return false;
71+
if (version > 2.0)
72+
throw new Exception("Failed reading input file " + filePath + ": A newer version of UnityMixedCallstacks plugin is required to read this file");
73+
}
74+
catch (Exception ex)
75+
{
76+
_debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
77+
DisposeStreams();
78+
return false;
79+
}
80+
_currentFiles.Add(filePath, pmipStreams);
6181
}
6282

6383
try
6484
{
6585
string line;
66-
while ((line = _fileStreamReader.ReadLine()) != null)
86+
int count = 0;
87+
int legacyCount = 0;
88+
while ((line = pmipStreams.fileStreamReader.ReadLine()) != null)
6789
{
6890
const char delemiter = ';';
6991
var tokens = line.Split(delemiter);
@@ -89,16 +111,27 @@ public static bool ReadPmipFile(string filePath)
89111
{
90112
// legacy stored in new pmip file
91113
_legacyRanges.Add(new Range() { Name = description, File = file, Start = startiplong, End = endipint });
114+
legacyCount++;
92115
}
93116
else
94-
_rangesSortedByIp.Add(new Range() { Name = description, File = file, Start = startiplong, End = endipint });
117+
{
118+
Range range = new Range() { Name = description, File = file, Start = startiplong, End = endipint };
119+
#if DEBUG
120+
_debugPane?.OutputString($"MIXEDCALLSTACK :: adding range: {range}\n");
121+
#endif
122+
_rangesSortedByIp.Add(range);
123+
count++;
124+
}
95125
}
96126
}
97-
//_debugPane?.OutputString("MIXEDCALLSTACK :: map now has " + _rangesSortedByIp.Count + " entries! legacy map has: " + _legacyRanges.Count + "\n");
127+
#if DEBUG
128+
if (count > 0 || legacyCount > 0)
129+
_debugPane?.OutputString($"MIXEDCALLSTACK :: added {count} to map for a total of {_rangesSortedByIp.Count} entries! Added {legacyCount} to legacy map for a total of {_legacyRanges.Count} \n");
130+
#endif
98131
}
99132
catch (Exception ex)
100133
{
101-
//_debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
134+
_debugPane?.OutputString("MIXEDCALLSTACK :: Unable to read dumped pmip file: " + ex.Message + "\n");
102135
DisposeStreams();
103136
return false;
104137
}

UnityMixedCallstackFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace UnityMixedCallstack
1515
public class UnityMixedCallstackFilter : IDkmCallStackFilter, IDkmLoadCompleteNotification, IDkmModuleInstanceLoadNotification
1616
{
1717
private static bool _enabled;
18-
private static IVsOutputWindowPane _debugPane;
18+
public static IVsOutputWindowPane _debugPane;
1919
private static Dictionary<int, PmipFile> _currentFiles = new Dictionary<int, PmipFile>();
2020

2121
struct PmipFile
@@ -153,8 +153,8 @@ private static void RefreshStackData(int pid)
153153
if (taskFiles.Length < 1)
154154
return;
155155

156-
if (!CheckForUpdatedFiles(taskFiles))
157-
return;
156+
if (CheckForUpdatedFiles(taskFiles))
157+
PmipReader.DisposeStreams();
158158

159159
foreach (PmipFile pmipFile in _currentFiles.Values)
160160
{

0 commit comments

Comments
 (0)