Skip to content

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

Closed

Description

@tommcdon

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.

Activity

  1. ghost added
    untriaged
    on Jan 21, 2024
  2. added this to the 9.0.0 milestone on Jan 21, 2024
  3. ghost removed
    untriaged
    on Jan 21, 2024
  4. self-assigned this
    on Jan 21, 2024
  5. ghost added
    in-pr
    on Jan 21, 2024
  6. tommcdon commented on Jan 21, 2024

    @tommcdon
    MemberAuthor

    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.

  7. AaronRobinsonMSFT commented on Jan 21, 2024

    @AaronRobinsonMSFT
    Member

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

    /cc @huoyaoyuan

  8. huoyaoyuan commented on Jan 21, 2024

    @huoyaoyuan
    Member

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

  9. AaronRobinsonMSFT commented on Jan 21, 2024

    @AaronRobinsonMSFT
    Member

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

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

  10. ghost removed
    in-pr
    on Jan 21, 2024
  11. locked and limited conversation to collaborators on Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions