Skip to content

Windbg breakpoints on AOT binary induce crash #94650

Closed

Description

@fbrosseau

Hello,

Description

In dotnet 8 RC2 AOT, Windbg bm command inserts breakpoints in data sections, causing crash because the breakpoint instructions corrupt AOT runtime data structures.

Reproduction Steps

Program:

Activator.CreateInstance(typeof(GreatTest));

class GreatTest
{
    public GreatTest()
    {
    }
}

Csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <PublishAot>true</PublishAot>
  </PropertyGroup>
</Project>

Build: dotnet publish

Upon LdrpDoDebuggerBreak, do bm AotDbgCrash!*GreatTest*. This will resolve the ctor, but also runtime data structures for NativeAOT. The expected behavior is that bm wildcards should resolve only functions, not data:

0:000> bm AotDbgCrash!*GreatTest*
  0: 00007ff7`933e82c8 @!"AotDbgCrash!__writableDataAotDbgCrash_GreatTest"
  1: 00007ff7`932acb00 @!"AotDbgCrash!AotDbgCrash_GreatTest___ctor"

The insertion of a breakpoint at #0 bricks the runtime.

(81d8.3944): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
AotDbgCrash!S_P_CoreLib_System_Type__GetTypeFromHandle+0x1e:
00007ff6`a4b57dee 488b01          mov     rax,qword ptr [rcx] ds:00000000`000000cc=????????????????
0:000> k
 # Child-SP          RetAddr               Call Site
00 000000f6`494ff860 00007ff7`932acadc     AotDbgCrash!S_P_CoreLib_Internal_Runtime_CompilerHelpers_LdTokenHelpers__GetRuntimeType+0x1c [/_/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/LdTokenHelpers.cs @ 36] 
01 000000f6`494ff890 00007ff7`932cb860     AotDbgCrash!AotDbgCrash_Program___Main__+0x1c [C:\Users\bfrancis\source\repos\AotDbgCrash\AotDbgCrash\Program.cs @ 1] 
02 000000f6`494ff8c0 00007ff7`931c22d2     AotDbgCrash!AotDbgCrash__Module___StartupCodeMain+0xe0

Activity

  1. ghost added
    untriaged
    on Nov 13, 2023
  2. jkotas commented on Nov 13, 2023

    @jkotas
    Member

    bm command finds a match for the ctor, but also for writeableData runtime data structure:

    0:000> bm AotDbgCrash!*GreatTest*
      0: 00007ff6`3fdad920 @!"AotDbgCrash!AotDbgCrash_GreatTest___ctor"
      1: 00007ff6`3ff055b0 @!"AotDbgCrash!__writableDataAotDbgCrash_GreatTest"
    

    Setting the breaking on writeableData corrupts the data structure that leads to the crash.

    Can we do something to prevent bm from matching the writeableData?

  3. MichalStrehovsky commented on Nov 13, 2023

    @MichalStrehovsky
    Member

    Per WinDbg docs, bm is supposed to match only code unless /a was specified.

    (For bm only) Sets breakpoints on all of the specified locations, whether they are in data space or code space. Because breakpoints on data can cause program failures, use this option only on locations that are known to be safe.

    The writableData blocks are in a data section of the executable so if WinDbg was following what the docs are saying, it shouldn't write in that location. Unless there's some other mechanism to decide if something is code or data.

  4. added this to the Future milestone on Nov 13, 2023
  5. ghost removed
    untriaged
    on Nov 13, 2023
  6. jkotas commented on Nov 13, 2023

    @jkotas
    Member

    @mikem8361 Do you have any insights into why windbg bm command sets breaking in data section in this case?

  7. mikem8361 commented on Nov 13, 2023

    @mikem8361
    Contributor

    Sorry I don't. I'll send the windows debugger team this issue.

  8. fbrosseau commented on Nov 14, 2023

    @fbrosseau
    Author

    Thank you folks I updated the opening post for a better description

  9. ghost added
    in-pr
    on Nov 14, 2023
  10. ghost removed
    in-pr
    on Nov 15, 2023
  11. locked and limited conversation to collaborators on Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions