Skip to content
Open
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
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;
Comment on lines +5542 to +5545
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DmlEscape function has a performance concern. On each iteration, it creates a temporary 2-character array and concatenates it to the result string, which can be inefficient for longer strings due to repeated memory allocations. Consider using result.Reserve() to pre-allocate space, or accumulate characters in a buffer before appending them to the result string.

Copilot uses AI. Check for mistakes.
}
Comment on lines +5527 to +5546
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of character escaping is incorrect. The ampersand (&) character must be escaped FIRST, before escaping < and >, otherwise any pre-existing & characters in the input will be double-escaped. For example, if the input contains "<", it would first escape "&" to "&", then escape "<" to result in "&lt;" instead of preserving "<".

The correct order should be:

  1. Escape & to &
  2. Escape < to <
  3. Escape > to >

Copilot uses AI. Check for mistakes.
}

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
32 changes: 32 additions & 0 deletions src/tests/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; }
}
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/tests/SOS.UnitTests/SOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,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/tests/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 when DML is enabled
#

CONTINUE

LOADSOS

# Verify that ClrStack with /d (DML enabled) properly displays async method name with angle brackets
SOSCOMMAND:ClrStack /d
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>\(.*\).*
Comment on lines +13 to +14
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verification is checking for literal angle brackets <Main> but when DML is enabled and the escaping is applied, the output will contain the DML escape sequences &lt;Main&gt; instead. The VERIFY regex should be checking for the escaped version to properly validate that the DML escaping is working correctly.

Suggested change
# Verify that the method name contains <Main> and is not trimmed to Main>
VERIFY:.*AsyncMainTest\.<Main>\(.*\).*
# Verify that the method name contains <Main> (escaped as &lt;Main&gt; with DML) and is not trimmed to Main>
VERIFY:.*AsyncMainTest\.&lt;Main&gt;\(.*\).*

Copilot uses AI. Check for mistakes.