Skip to content

Commit 2250723

Browse files
author
Christophe Nasarre
committed
- Support ClrMD 2
- Remove message box error when invalid dumpheap output
1 parent 69d0aae commit 2250723

File tree

9 files changed

+80
-16
lines changed

9 files changed

+80
-16
lines changed

src/LeakShell/MainFrame.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,14 @@ private HeapSnapshot GetSnapshotFromClipboard()
364364
}
365365
private HeapSnapshot GetSnapshotFromDumpHeap_Stat(string heapdump)
366366
{
367-
// protect against ill-formatted "!dumpheap -stat" output
367+
// protect against ill-formatted "!dumpheap -stat" output or unrelated text
368368
HeapSnapshot snapshot;
369369
try
370370
{
371371
snapshot = HeapSnapshotFactory.CreateFromHeapStat(heapdump);
372372
}
373373
catch (InvalidOperationException x)
374374
{
375-
MessageBox.Show(this, x.Message, "Error while parsing '!dumpheap -stat' output");
376375
snapshot = null;
377376
}
378377

src/ParallelStacks.Runtime/ParallelStack.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ public static ParallelStack Build(ClrRuntime runtime)
1515
foreach (var thread in runtime.Threads)
1616
{
1717
stackFrames.Clear();
18-
18+
#if ClrMD1
1919
foreach (var stackFrame in thread.StackTrace.Reverse())
20+
#else
21+
foreach (var stackFrame in thread.EnumerateStackTrace().Reverse())
22+
#endif
2023
{
24+
#if ClrMD1
2125
if (stackFrame.Kind != ClrStackFrameType.ManagedMethod)
26+
#else
27+
if ((stackFrame.Kind != ClrStackFrameKind.ManagedMethod) || (stackFrame.Method == null))
28+
#endif
2229
continue;
2330

2431
stackFrames.Add(stackFrame);
@@ -39,6 +46,7 @@ public static ParallelStack Build(string dumpFile, string dacFilePath)
3946
ParallelStack ps = null;
4047
try
4148
{
49+
#if ClrMD1
4250
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
4351
{
4452
dataTarget = DataTarget.LoadCrashDump(dumpFile);
@@ -47,6 +55,15 @@ public static ParallelStack Build(string dumpFile, string dacFilePath)
4755
{
4856
dataTarget = DataTarget.LoadCoreDump(dumpFile);
4957
}
58+
#else
59+
if (
60+
(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ||
61+
(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
62+
)
63+
{
64+
dataTarget = DataTarget.LoadDump(dumpFile);
65+
}
66+
#endif
5067
else
5168
{
5269
throw new InvalidOperationException("Unsupported platform...");
@@ -74,6 +91,7 @@ public static ParallelStack Build(int pid, string dacFilePath)
7491
ParallelStack ps = null;
7592
try
7693
{
94+
#if ClrMD1
7795
const uint msecTimeout = 2000;
7896

7997
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -86,6 +104,18 @@ public static ParallelStack Build(int pid, string dacFilePath)
86104
// ClrMD implementation for Linux is available only for Passive
87105
dataTarget = DataTarget.AttachToProcess(pid, msecTimeout, AttachFlag.Passive);
88106
}
107+
#else
108+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
109+
{
110+
dataTarget = DataTarget.AttachToProcess(pid, true);
111+
}
112+
else
113+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
114+
{
115+
// ClrMD implementation for Linux is available only for Passive
116+
dataTarget = DataTarget.AttachToProcess(pid, true);
117+
}
118+
#endif
89119
else
90120
{
91121
throw new InvalidOperationException("Unsupported platform...");
@@ -110,7 +140,11 @@ public static ParallelStack Build(int pid, string dacFilePath)
110140
private static ClrRuntime CreateRuntime(DataTarget dataTarget, string dacFilePath)
111141
{
112142
// check bitness first
143+
#if ClrMD1
113144
bool isTarget64Bit = (dataTarget.PointerSize == 8);
145+
#else
146+
bool isTarget64Bit = (dataTarget.DataReader.PointerSize == 8);
147+
#endif
114148
if (Environment.Is64BitProcess != isTarget64Bit)
115149
{
116150
throw new InvalidOperationException(
@@ -138,7 +172,11 @@ private ParallelStack(ClrStackFrame frame = null)
138172
private void AddStack(uint threadId, ClrStackFrame[] frames, int index = 0)
139173
{
140174
ThreadIds.Add(threadId);
175+
#if ClrMD1
141176
var firstFrame = frames[index].DisplayString;
177+
#else
178+
var firstFrame = frames[index].Method?.Signature;
179+
#endif
142180
var callstack = Stacks.FirstOrDefault(s => s.Frame.Text == firstFrame);
143181
if (callstack == null)
144182
{

src/ParallelStacks.Runtime/ParallelStacks.Runtime.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010

1111
<PropertyGroup>
1212
<PackageId>ParallelStacks.Runtime</PackageId>
13-
<PackageVersion>1.3</PackageVersion>
13+
<PackageVersion>2.0.1</PackageVersion>
1414
<Title>ParallelStacks.Runtime</Title>
1515
<Authors>Christophe Nasarre</Authors>
1616
<Owners>chrisnas</Owners>
1717
<PackageProjectUrl>https://github.com/chrisnas/DebuggingExtensions</PackageProjectUrl>
1818
<PackageLicenseUrl>https://github.com/chrisnas/DebuggingExtensions/blob/master/LICENSE</PackageLicenseUrl>
1919
<Description>Helper objects to compute and render thread stacks</Description>
20-
<PackageReleaseNotes>- refactor rendering outside of the ParallelStack class
21-
- add HTML rendering</PackageReleaseNotes>
20+
<PackageReleaseNotes>- based on ClrMD 2.0
21+
- signed with a strong name to be useable by dotnet-dump</PackageReleaseNotes>
2222
<Copyright>Copyright 2019-$([System.DateTime]::UtcNow.ToString(yyyy))</Copyright>
2323
<PackageTags>ClrMD Thread Stack</PackageTags>
24+
<SignAssembly>true</SignAssembly>
25+
<DelaySign>false</DelaySign>
26+
<AssemblyOriginatorKeyFile>StrongNameForParallelStacks.Runtime.snk</AssemblyOriginatorKeyFile>
2427
</PropertyGroup>
2528

2629
<ItemGroup>
27-
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="1.1.37504" />
30+
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.0.145301" />
2831
</ItemGroup>
2932
</Project>

src/ParallelStacks.Runtime/Properties/AssemblyInfo.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("ParallelStacks.Runtime")]
12-
[assembly: AssemblyCopyright("Copyright © Christophe Nasarre 2019")]
12+
[assembly: AssemblyCopyright("Copyright © Christophe Nasarre 2019-2020")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -28,8 +28,19 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("1.3.0.0")]
32-
[assembly: AssemblyFileVersion("1.3.0.0")]
31+
[assembly: AssemblyVersion("2.0.1.0")]
32+
[assembly: AssemblyFileVersion("2.0.1.0")]
33+
//
34+
// version 2.0.1
35+
// -----------------------------------------
36+
// - add a strong name to be useable by dotnet-dump
37+
//
38+
//
39+
// version 2.0
40+
// -----------------------------------------
41+
// - use ClrMD 2.0
42+
// - update copyright year to 2020
43+
//
3344
//
3445
// version 1.3
3546
// -----------------------------------------

src/ParallelStacks.Runtime/StackFrame.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public class StackFrame
1515

1616
public StackFrame(ClrStackFrame frame)
1717
{
18+
#if ClrMD1
1819
Text = string.Intern(frame.DisplayString);
20+
#else
21+
var signature = frame.Method?.Signature;
22+
Text = string.IsNullOrEmpty(signature) ? "?" : string.Intern(signature);
23+
#endif
1924
Signature = new List<string>();
2025
ComputeNames(frame);
2126
}
@@ -36,7 +41,11 @@ private void ComputeNames(ClrStackFrame frame)
3641

3742
// generic methods are not well formatted by ClrMD
3843
// foo<...>() => foo[[...]]()
39-
var fullName = frame.Method.GetFullSignature();
44+
#if ClrMD1
45+
var fullName = frame.Method?.GetFullSignature();
46+
#else
47+
var fullName = frame.Method?.Signature;
48+
#endif
4049
MethodName = frame.Method.Name;
4150
if (MethodName.EndsWith("]]"))
4251
{
596 Bytes
Binary file not shown.

src/ParallelStacks/ParallelStacks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="1.1.37504" />
12+
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.0.145301" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/dotnet-pstacks/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("1.3.2.0")]
32-
[assembly: AssemblyFileVersion("1.3.2.0")]
31+
[assembly: AssemblyVersion("2.0.0.0")]
32+
[assembly: AssemblyFileVersion("2.0.0.0")]
33+
//
34+
// version 2.0.0
35+
// -----------------------------------------
36+
// - use ClrMD 2.0
3337
//
3438
// version 1.3.2
3539
// -----------------------------------------

src/gsose/gsose.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
3737
<DebugSymbols>true</DebugSymbols>
3838
<OutputPath>bin\x64\Debug\</OutputPath>
39-
<DefineConstants>DEBUG;TRACE</DefineConstants>
39+
<DefineConstants>TRACE;DEBUG;ClrMD1</DefineConstants>
4040
<DebugType>full</DebugType>
4141
<PlatformTarget>x64</PlatformTarget>
4242
<ErrorReport>prompt</ErrorReport>
4343
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
4444
</PropertyGroup>
4545
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
4646
<OutputPath>bin\x64\Release\</OutputPath>
47-
<DefineConstants>TRACE</DefineConstants>
47+
<DefineConstants>TRACE;ClrMD1</DefineConstants>
4848
<Optimize>true</Optimize>
4949
<DebugType>pdbonly</DebugType>
5050
<PlatformTarget>x64</PlatformTarget>

0 commit comments

Comments
 (0)