Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 54 additions & 43 deletions src/Microsoft.Diagnostics.ExtensionCommands/DumpAsyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ bool ShouldIncludeStack(AsyncObject obj)
// <summary>Outputs a line of information for each instance field on the object.</summary>
void RenderFields(IAddressableTypedEntity? obj, int depth)
{
if (obj is not null)
if (obj?.Type is not null)
{
string depthTab = new string(' ', depth * TabWidth);

Expand Down Expand Up @@ -489,33 +489,36 @@ void RenderFields(IAddressableTypedEntity? obj, int depth)
// <summary>Gets a printable description for the specified object.</summary>
string Describe(ClrObject obj)
{
// Default the description to the type name.
string description = obj.Type.Name;

if (IsStateMachineBox(obj.Type))
string description = string.Empty;
if (obj.Type?.Name is not null)
{
// Remove the boilerplate box type from the name.
int pos = description.IndexOf("StateMachineBox<", StringComparison.Ordinal);
if (pos >= 0)
// Default the description to the type name.
description = obj.Type.Name;

if (IsStateMachineBox(obj.Type))
{
ReadOnlySpan<char> slice = description.AsSpan(pos + "StateMachineBox<".Length);
slice = slice.Slice(0, slice.Length - 1); // remove trailing >
description = slice.ToString();
// Remove the boilerplate box type from the name.
int pos = description.IndexOf("StateMachineBox<", StringComparison.Ordinal);
if (pos >= 0)
{
ReadOnlySpan<char> slice = description.AsSpan(pos + "StateMachineBox<".Length);
slice = slice.Slice(0, slice.Length - 1); // remove trailing >
description = slice.ToString();
}
}
}
else if (TryGetValidObjectField(obj, "m_action", out ClrObject taskDelegate))
{
// If we can figure out what the task's delegate points to, append the method signature.
if (TryGetMethodFromDelegate(runtime, taskDelegate, out ClrMethod? method))
else if (TryGetValidObjectField(obj, "m_action", out ClrObject taskDelegate))
{
// If we can figure out what the task's delegate points to, append the method signature.
if (TryGetMethodFromDelegate(runtime, taskDelegate, out ClrMethod? method))
{
description = $"{description} {{{method!.Signature}}}";
}
}
else if (obj.Address != 0 && taskCompletionSentinel.Address == obj.Address)
{
description = $"{description} {{{method!.Signature}}}";
description = "TaskCompletionSentinel";
}
}
else if (obj.Address != 0 && taskCompletionSentinel.Address == obj.Address)
{
description = "TaskCompletionSentinel";
}

return description;
}

Expand All @@ -527,14 +530,17 @@ bool IncludeInOutput(ClrObject obj)
return false;
}

if (MethodTableAddress is ulong mt && obj.Type.MethodTable != mt)
if (obj.Type is not null)
{
return false;
}
if (MethodTableAddress is ulong mt && obj.Type.MethodTable != mt)
{
return false;
}

if (NameSubstring is not null && !obj.Type.Name.Contains(NameSubstring))
{
return false;
if (NameSubstring is not null && obj.Type.Name is not null && !obj.Type.Name.Contains(NameSubstring))
{
return false;
}
}

return true;
Expand Down Expand Up @@ -655,37 +661,42 @@ Dictionary<ClrObject, AsyncObject> CollectObjects()
// </remarks>
void AddContinuation(ClrObject continuation, List<ClrObject> continuations)
{
if (continuation.Type.Name.StartsWith("System.Collections.Generic.List<", StringComparison.Ordinal))
if (continuation.Type is not null)
{
if (continuation.Type.GetFieldByName("_items") is ClrInstanceField itemsField)
if (continuation.Type.Name is not null &&
continuation.Type.Name.StartsWith("System.Collections.Generic.List<", StringComparison.Ordinal))
{
ClrObject itemsObj = itemsField.ReadObject(continuation.Address, interior: false);
if (!itemsObj.IsNull)
if (continuation.Type.GetFieldByName("_items") is ClrInstanceField itemsField)
{
ClrArray items = itemsObj.AsArray();
if (items.Rank == 1)
ClrObject itemsObj = itemsField.ReadObject(continuation.Address, interior: false);
if (!itemsObj.IsNull)
{
for (int i = 0; i < items.Length; i++)
ClrArray items = itemsObj.AsArray();
if (items.Rank == 1)
{
if (items.GetObjectValue(i) is ClrObject { IsValid: true } c)
for (int i = 0; i < items.Length; i++)
{
continuations.Add(ResolveContinuation(c));
if (items.GetObjectValue(i) is ClrObject { IsValid: true } c)
{
continuations.Add(ResolveContinuation(c));
}
}
}
}
}
}
}
else
{
continuations.Add(continuation);
else
{
continuations.Add(continuation);
}
}
}

// <summary>Tries to get the object contents of a Task's continuations field</summary>
bool TryGetContinuation(ClrObject obj, out ClrObject continuation)
{
if (obj.Type.GetFieldByName("m_continuationObject") is ClrInstanceField continuationObjectField &&
if (obj.Type is not null &&
obj.Type.GetFieldByName("m_continuationObject") is ClrInstanceField continuationObjectField &&
continuationObjectField.ReadObject(obj.Address, interior: false) is ClrObject { IsValid: true } continuationObject)
{
continuation = ResolveContinuation(continuationObject);
Expand Down Expand Up @@ -888,7 +899,7 @@ private void WriteCodeLink(ulong address)
}

/// <summary>Gets whether the specified type is an AsyncStateMachineBox{T}.</summary>
private static bool IsStateMachineBox(ClrType type)
private static bool IsStateMachineBox(ClrType? type)
{
// Ideally we would compare the metadata token and module for the generic template for the type,
// but that information isn't fully available via ClrMd, nor can it currently find DebugFinalizableAsyncStateMachineBox
Expand Down
5 changes: 5 additions & 0 deletions src/SOS/SOS.UnitTests/SOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
using Xunit.Abstractions;
using Xunit.Extensions;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

[Collection("Windows Dump Generation")]
public class SOS
{
public SOS(ITestOutputHelper output)
Expand Down
4 changes: 4 additions & 0 deletions src/tests/DbgShim.UnitTests/DbgShimTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
using Xunit.Abstractions;
using Xunit.Extensions;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics
{
public class DbgShimTests : IDisposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
using Xunit.Abstractions;
using Xunit.Extensions;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.DebugServices.UnitTests
{
public class DebugServicesTests : IDisposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
{
public class EventCounterPipelineUnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
{
public class EventCounterTriggerTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
{
public class EventLogsPipelineUnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
{
public class EventTracePipelineUnitTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.NETCore.Client
{
public class EventPipeSessionTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.NETCore.Client
{
public class ProcessEnvironmentTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.NETCore.Client
{
public class GetProcessInfoTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
using Microsoft.Diagnostics.TestHelpers;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.NETCore.Client
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.NETCore.Client
{
public class ReversedServerTests
Expand Down
3 changes: 2 additions & 1 deletion src/tests/dotnet-counters/JSONExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

using System;
using System.IO;
using System.Collections.Generic;
using Xunit;
using Microsoft.Diagnostics.Tools.Counters.Exporters;
using Newtonsoft.Json;
using Microsoft.Diagnostics.Tools.Counters;

#pragma warning disable CA1507 // Use nameof to express symbol names

namespace DotnetCounters.UnitTests
{
/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion src/tests/dotnet-trace/ChildProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
using Xunit.Extensions;
using TestRunner = Microsoft.Diagnostics.CommonTestRunner.TestRunner;

// Newer SDKs flag MemberData(nameof(Configurations)) with this error
// Avoid unnecessary zero-length array allocations. Use Array.Empty<object>() instead.
#pragma warning disable CA1825

namespace Microsoft.Diagnostics.Tools.Trace
{

public class ChildProcessTests
{
public static IEnumerable<object[]> Configurations => TestRunner.Configurations;
Expand Down