Uh oh!
There was an error while loading. Please reload this page.
forked from jbevain/PmipMyCallStack
- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathUnityMixedCallstackFilter.cs
More file actions
Latest commit
181 lines (157 loc) · 6.73 KB
/
Copy pathUnityMixedCallstackFilter.cs
File metadata and controls
181 lines (157 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Globalization;
usingSystem.IO;
usingMicrosoft.VisualStudio;
usingMicrosoft.VisualStudio.Debugger;
usingMicrosoft.VisualStudio.Debugger.CallStack;
usingMicrosoft.VisualStudio.Debugger.ComponentInterfaces;
usingMicrosoft.VisualStudio.Shell;
usingMicrosoft.VisualStudio.Shell.Interop;
usingUnityMixedCallStack;
namespaceUnityMixedCallstack
{
publicclassUnityMixedCallstackFilter:IDkmCallStackFilter,IDkmLoadCompleteNotification,IDkmModuleInstanceLoadNotification
{
privatestaticbool_enabled;
publicstaticIVsOutputWindowPane_debugPane;
privatestaticDictionary<int,PmipFile>_currentFiles=newDictionary<int,PmipFile>();
structPmipFile
{
publicintcount;
publicintpid;
publicstringpath;
}
publicvoidOnLoadComplete(DkmProcessprocess,DkmWorkListworkList,DkmEventDescriptoreventDescriptor)
{
PmipReader.DisposeStreams();
if(_debugPane==null)
{
IVsOutputWindowoutWindow=Package.GetGlobalService(typeof(SVsOutputWindow))asIVsOutputWindow;
GuiddebugPaneGuid=VSConstants.GUID_OutWindowDebugPane;
outWindow?.GetPane(refdebugPaneGuid,out_debugPane);
}
}
publicDkmStackWalkFrame[]FilterNextFrame(DkmStackContextstackContext,DkmStackWalkFrameinput)
{
if(input==null)// after last frame
returnnull;
if(input.InstructionAddress==null)// error case
returnnew[]{input};
if(input.InstructionAddress.ModuleInstance!=null&&input.InstructionAddress.ModuleInstance.Module!=null)// code in existing module
returnnew[]{input};
if(!_enabled)// environment variable not set
returnnew[]{input};
try
{
DkmStackWalkFrame[]retVal=new[]{UnityMixedStackFrame(stackContext,input)};
returnretVal;
}catch(Exceptionex)
{
_debugPane?.OutputString("UNITYMIXEDCALLSTACK :: ip : "+input.Process.LivePart.Id+" threw exception: "+ex.Message+"\n"+ex.StackTrace);
}
returnnew[]{input};
}
privatestaticDkmStackWalkFrameUnityMixedStackFrame(DkmStackContextstackContext,DkmStackWalkFrameframe)
{
RefreshStackData(frame.Process.LivePart.Id);
#if DEBUG
_debugPane?.OutputString($"UNITYMIXEDCALLSTACK :: done refreshing data for pid({frame.Process.LivePart.Id}) :: looking for address: {frame.InstructionAddress.CPUInstructionPart.InstructionPointer:X16}\n");
#endif
stringname=null;
if(PmipReader.TryGetDescriptionForIp(frame.InstructionAddress.CPUInstructionPart.InstructionPointer,outname))
{
#if DEBUG
_debugPane?.OutputString($"ip: {frame.InstructionAddress.CPUInstructionPart.InstructionPointer:X16} ### {name}\n");
#endif
returnDkmStackWalkFrame.Create(
stackContext.Thread,
frame.InstructionAddress,
frame.FrameBase,
frame.FrameSize,
frame.Flags,
name,
frame.Registers,
frame.Annotations);
}
#if DEBUG
else
_debugPane?.OutputString($"IP not found: {frame.InstructionAddress.CPUInstructionPart.InstructionPointer:X16}\n");
#endif
returnframe;
}
privatestaticintGetFileNameSequenceNum(stringpath)
{
varname=Path.GetFileNameWithoutExtension(path);
constchardelemiter='_';
vartokens=name.Split(delemiter);
if(tokens.Length!=3)
return-1;
returnint.Parse(tokens[2]);
}
privatestaticboolCheckForUpdatedFiles(FileInfo[]taskFiles)
{
boolretVal=false;
try
{
foreach(FileInfotaskFileintaskFiles)
{
stringfName=Path.GetFileNameWithoutExtension(taskFile.Name);
string[]tokens=fName.Split('_');
PmipFilepmipFile=newPmipFile()
{
count=int.Parse(tokens[2]),
pid=int.Parse(tokens[1]),
path=taskFile.FullName
};
// 3 is legacy and treat everything as root domain
if(tokens.Length==3&&
(!_currentFiles.TryGetValue(0,outPmipFilecurFile)||
curFile.count<pmipFile.count||curFile.pid!=pmipFile.pid))
{
_currentFiles[0]=pmipFile;
retVal=true;
}
elseif(tokens.Length==4)
{
intdomainID=int.Parse(tokens[3]);
if(!_currentFiles.TryGetValue(domainID,outPmipFilecFile)||cFile.count<pmipFile.count||
cFile.pid!=pmipFile.pid)
{
_currentFiles[domainID]=pmipFile;
retVal=true;
}
}
}
}catch(Exceptione)
{
_debugPane?.OutputString("MIXEDCALLSTACK :: Exception thrown during CheckForUpdatedFiles: "+e.Message+"\n");
_enabled=false;
}
returnretVal;
}
privatestaticvoidRefreshStackData(intpid)
{
DirectoryInfotaskDirectory=newDirectoryInfo(Path.GetTempPath());
FileInfo[]taskFiles=taskDirectory.GetFiles("pmip_"+pid+"_*.txt");
if(taskFiles.Length<1)
return;
if(CheckForUpdatedFiles(taskFiles))
PmipReader.DisposeStreams();
foreach(PmipFilepmipFilein_currentFiles.Values)
{
_enabled=PmipReader.ReadPmipFile(pmipFile.path);
if(!_enabled)
{
_debugPane?.OutputString($"Unable to read file: {pmipFile.path}\n");
}
}
PmipReader.Sort();
}
publicvoidOnModuleInstanceLoad(DkmModuleInstancemoduleInstance,DkmWorkListworkList,DkmEventDescriptorSeventDescriptor)
{
if(moduleInstance.Name.Contains("mono-2.0")&&moduleInstance.MinidumpInfoPart==null)
_enabled=true;
}
}
}