Skip to content
Draft
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
32 changes: 32 additions & 0 deletions src/SOS/SOS.UnitTests/Debuggees/AsyncMain/AsyncMain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Threading.Tasks;

public class AsyncMainTest
{
public static async Task<int> Main(string[] args)
{
DivideData data = new()
{
Numerator = 16,
Denominator = 0,
};

Console.WriteLine($"{data.Numerator}/{data.Denominator} = {await DivideAsync(data)}");
return 0;
}

static async Task<int> DivideAsync(DivideData data)
{
await Task.Delay(10);
return data.Numerator / data.Denominator;
}
}

public class DivideData
{
public int Numerator { get; set; }
public int Denominator { get; set; }
}
7 changes: 7 additions & 0 deletions src/SOS/SOS.UnitTests/Debuggees/AsyncMain/AsyncMain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition="'$(BuildProjectFramework)' != ''">$(BuildProjectFramework)</TargetFramework>
<TargetFrameworks Condition="'$(BuildProjectFramework)' == ''">$(SupportedSubProcessTargetFrameworks)</TargetFrameworks>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions src/SOS/SOS.UnitTests/SOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ public async Task SimpleThrow(TestConfiguration config)
await SOSTestHelpers.RunTest(config, debuggeeName: "SimpleThrow", scriptName: "SimpleThrow.script", Output, testTriage: true);
}

[SkippableTheory, MemberData(nameof(Configurations))]
public async Task AsyncMain(TestConfiguration config)
{
await SOSTestHelpers.RunTest(config, debuggeeName: "AsyncMain", scriptName: "AsyncMain.script", Output, testTriage: true);
}

[SkippableTheory, MemberData(nameof(Configurations))]
public async Task LineNums(TestConfiguration config)
{
Expand Down
14 changes: 14 additions & 0 deletions src/SOS/SOS.UnitTests/Scripts/AsyncMain.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Tests that ClrStack properly displays async Main method names with angle brackets
#

CONTINUE

LOADSOS

# Verify that ClrStack with no options works and displays async method name correctly
SOSCOMMAND:ClrStack
VERIFY:.*OS Thread Id:\s+0x<HEXVAL>\s+.*
VERIFY:\s+Child\s+SP\s+IP\s+Call Site\s+
# Verify that the method name contains <Main> and is not trimmed to Main>
VERIFY:.*AsyncMainTest\.<Main>\(.*\).*
10 changes: 8 additions & 2 deletions src/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10942,7 +10942,10 @@ class ClrStackImpl
out.WriteColumn(1, bFull ? String("") : NativePtr(ip));

// This is a clr!Frame.
out.WriteColumn(2, GetFrameFromAddress(TO_TADDR(FrameData.frameAddr), pStackWalk, bFull));
WString frameName = GetFrameFromAddress(TO_TADDR(FrameData.frameAddr), pStackWalk, bFull);
if (IsDMLEnabled())
frameName = DmlEscape(frameName);
out.WriteColumn(2, frameName);

// Print out gc references for the Frame.
for (unsigned int i = 0; i < refCount; ++i)
Expand Down Expand Up @@ -10976,7 +10979,10 @@ class ClrStackImpl
// The unmodified IP is displayed which points after the exception in most cases. This means that the
// printed IP and the printed line number often will not map to one another and this is intentional.
out.WriteColumn(1, InstructionPtr(ip));
out.WriteColumn(2, MethodNameFromIP(ip, bSuppressLines, bFull, bFull, bAdjustIPForLineNumber));
WString methodName = MethodNameFromIP(ip, bSuppressLines, bFull, bFull, bAdjustIPForLineNumber);
if (IsDMLEnabled())
methodName = DmlEscape(methodName);
out.WriteColumn(2, methodName);

// Print out gc references. refCount will be zero if bGC is false (or if we
// failed to fetch gc reference information).
Expand Down
31 changes: 31 additions & 0 deletions src/SOS/Strike/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5518,6 +5518,37 @@ WString MethodNameFromIP(CLRDATA_ADDRESS ip, BOOL bSuppressLines, BOOL bAssembly
return methodOutput;
}

WString DmlEscape(const WString &input)
{
const WCHAR *str = input.c_str();
size_t len = input.GetLength();
WString result;

for (size_t i = 0; i < len; i++)
{
if (str[i] == L'<')
{
result += W("&lt;");
}
else if (str[i] == L'>')
{
result += W("&gt;");
}
else if (str[i] == L'&')
{
result += W("&amp;");
}
else
{
// Append single character
WCHAR temp[2] = { str[i], L'\0' };
result += temp;
}
}

return result;
}

HRESULT GetGCRefs(ULONG osID, SOSStackRefData **ppRefs, unsigned int *pRefCnt, SOSStackRefError **ppErrors, unsigned int *pErrCount)
{
if (ppRefs == NULL || pRefCnt == NULL)
Expand Down
1 change: 1 addition & 0 deletions src/SOS/Strike/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ WString BuildRegisterOutput(const SOSStackRefData &ref, bool printObj = true);
WString MethodNameFromIP(CLRDATA_ADDRESS methodDesc, BOOL bSuppressLines = FALSE, BOOL bAssemblyName = FALSE, BOOL bDisplacement = FALSE, BOOL bAdjustIPForLineNumber = FALSE);
HRESULT GetGCRefs(ULONG osID, SOSStackRefData **ppRefs, unsigned int *pRefCnt, SOSStackRefError **ppErrors, unsigned int *pErrCount);
WString GetFrameFromAddress(TADDR frameAddr, IXCLRDataStackWalk *pStackwalk = NULL, BOOL bAssemblyName = FALSE);
WString DmlEscape(const WString &input);

HRESULT PreferCanonMTOverEEClass(CLRDATA_ADDRESS eeClassPtr, BOOL *preferCanonMT, CLRDATA_ADDRESS *outCanonMT = NULL);

Expand Down
Loading