Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Diagnostics.Debugger.Break() causes System.Runtime.InteropServices.COMException #97261

Closed
tommcdon opened this issue Jan 21, 2024 · 6 comments · Fixed by #97264
Closed
Assignees
Milestone

Comments

@tommcdon
Copy link
Member

tommcdon commented Jan 21, 2024

Description

Calling System.Diagnostics.Debugger.Break() should cause the debugger to stop by triggering a user breakpoint at the location where the function was called.

Reproduction Steps

Call Debugger.Break() in small C# console app

Expected behavior

Debugger should stop as if it hit a breakpoint when Debugger.Break() is called

Actual behavior

A System.Runtime.InteropServices.COMException is triggered

Regression?

This is a regression in .NET 9 main builds

Known Workarounds

N/A

Configuration

All OS's and Architectures

Other information

DebuggerUserBreakpoint::IsFrameInDebuggerNamespace is checking the Namespace and the Class by converting a UTF8 string into a Unicode string:

MAKE_WIDEPTR_FROMUTF8(wszNamespace, szNamespace); // throw
MAKE_WIDEPTR_FROMUTF8(wszClassName, szClassName);

The MAKE_WIDEPTR_FROMUTF8 macro uses ConvertUtf8_Unicode which was re-written in #96099. The original implementation seemed to accept zero-length strings, but the new one will now throw an exception. I am not sure if ConvertUtf8_Unicode intends to support zero length strings (if yes we should consider updating the function). We can work around this particular issue by avoiding converting zero-length strings in DebuggerUserBreakpoint::IsFrameInDebuggerNamespace.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 21, 2024
@ghost
Copy link

ghost commented Jan 21, 2024

Tagging subscribers to this area: @thaystg
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Calling System.Diagnostics.Debugger.Break() should cause the debugger to stop by triggering a user breakpoint at the location where the function was called.

Reproduction Steps

Call Debugger.Break() in small C# console app

Expected behavior

Debugger should stop as if it hit a breakpoint when Debugger.Break() is called

Actual behavior

A System.Runtime.InteropServices.COMException is triggered

Regression?

This is a regression in .NET 9 main builds

Known Workarounds

N/A

Configuration

All OS's and Architectures

Other information

DebuggerUserBreakpoint::IsFrameInDebuggerNamespace is checking the Namespace and the Class by converting a UTF8 string into a Unicode string:

MAKE_WIDEPTR_FROMUTF8(wszNamespace, szNamespace); // throw
MAKE_WIDEPTR_FROMUTF8(wszClassName, szClassName);

The MAKE_WIDEPTR_FROMUTF8 macro uses ConvertUtf8_Unicode which was re-written in #9609. The original implementation seemed to accept zero-length strings, but the new one will now throw an exception. I am not sure if ConvertUtf8_Unicode intends to support zero length strings (if yes we should consider updating the function). We can work around this particular issue by avoiding converting zero-length strings in DebuggerUserBreakpoint::IsFrameInDebuggerNamespace.

Author: tommcdon
Assignees: -
Labels:

untriaged, area-Debugger-mono

Milestone: -

@ghost
Copy link

ghost commented Jan 21, 2024

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Calling System.Diagnostics.Debugger.Break() should cause the debugger to stop by triggering a user breakpoint at the location where the function was called.

Reproduction Steps

Call Debugger.Break() in small C# console app

Expected behavior

Debugger should stop as if it hit a breakpoint when Debugger.Break() is called

Actual behavior

A System.Runtime.InteropServices.COMException is triggered

Regression?

This is a regression in .NET 9 main builds

Known Workarounds

N/A

Configuration

All OS's and Architectures

Other information

DebuggerUserBreakpoint::IsFrameInDebuggerNamespace is checking the Namespace and the Class by converting a UTF8 string into a Unicode string:

MAKE_WIDEPTR_FROMUTF8(wszNamespace, szNamespace); // throw
MAKE_WIDEPTR_FROMUTF8(wszClassName, szClassName);

The MAKE_WIDEPTR_FROMUTF8 macro uses ConvertUtf8_Unicode which was re-written in #9609. The original implementation seemed to accept zero-length strings, but the new one will now throw an exception. I am not sure if ConvertUtf8_Unicode intends to support zero length strings (if yes we should consider updating the function). We can work around this particular issue by avoiding converting zero-length strings in DebuggerUserBreakpoint::IsFrameInDebuggerNamespace.

Author: tommcdon
Assignees: -
Labels:

area-Diagnostics-coreclr, untriaged, area-Debugger-mono

Milestone: -

@tommcdon tommcdon added this to the 9.0.0 milestone Jan 21, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 21, 2024
@tommcdon tommcdon self-assigned this Jan 21, 2024
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 21, 2024
@tommcdon
Copy link
Member Author

I am not sure if ConvertUtf8_Unicode intends to support zero length strings

@AaronRobinsonMSFT @jkotas Do you know if ConvertUtf8_Unicode (and related functions) should accept zero length strings?
For now I have worked around this particular issue by avoiding converting zero-length strings in DebuggerUserBreakpoint::IsFrameInDebuggerNamespace however I am concerned there are other places in the runtime that make the same assumption.

@AaronRobinsonMSFT
Copy link
Member

I think we might want to revert #96099 for now.

/cc @huoyaoyuan

@huoyaoyuan
Copy link
Member

Can we add some test to exercise patterns used by debugger?

@AaronRobinsonMSFT
Copy link
Member

Can we add some test to exercise patterns used by debugger?

Yep. We'll do that in the updated PR.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 21, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.