Skip to content

Add NativeAOT.py for lldb visualization #115747

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

am11
Copy link
Member

@am11 am11 commented May 19, 2025

Adding @jbevain script from #115406 (comment).

Context:

(lldb) f 11
frame #11: 0x00000001005ff258 web04`_web04_Program___Main__(args=length=0) at Program.cs:11
   8   	  var testString = "Hello from NativeAOT!";
   9   	  var testArray = new int[] { 10, 20, 30 };
   10  	
-> 11  	  throw new InvalidOperationException($"{testString} {testArray.Length}");
   12  	}
   13  	
   14  	builder.Services.ConfigureHttpJsonOptions(options =>

Before:

(lldb) frame var testArray testString
(__Array<Int32> &) testArray = 0x00000004c0036550: {
  S_P_CoreLib_System_Array = {
    Object = {
      m_pEEType = 0x000000010126eef8
    }
    _numComponents = 3
  }
  m_NumComponents = 3
  m_Data = {}
}
(String &) testString = 0x0000000101025940: {
  Object = {
    m_pEEType = 0x00000001010e58b0
  }
  _stringLength = 21
  _firstChar = U+0048 u'H'
}

After:

(lldb) command script import /Users/adeel/projects/runtime/src/coreclr/nativeaot/BuildIntegration/NativeAOT.py
(lldb) frame var testArray testString
(__Array<Int32> &) testArray = 0x00000004c0036550 length=3: {
  [0] = 10
  [1] = 20
  [2] = 30
}
(String &) testString = 0x0000000101025940 "Hello from NativeAOT!": {
  Object = {}
  _stringLength = 21
  _firstChar = U+0048 u'H'
}

@am11 am11 requested a review from MichalStrehovsky as a code owner May 19, 2025 21:58
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 19, 2025
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@agocke
Copy link
Member

agocke commented May 19, 2025

Nice. It's too bad that lldb doesn't support just directly embedding this in the symbols, but I guess this is the next best thing.


Add to ~/.lldbinit:

command script import {path-to-ilcompiler-package}/build/NativeAOT.lldb.py
Copy link
Member

Choose a reason for hiding this comment

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

path-to-ilcompiler-package is not constant. It changes every month.

Would it be better to include this in our LLDB debugger extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

It has same release cadence as SDK. File is next to NativeAOT.natvis.

dotnet-debugger-extensions and dotnet-sos have different release cadence. Also, debugger extension is not open source and unavailable in VMR distro builds; the only option there is dotnet-sos, so we will need to add it to two packages that way.

Copy link
Member

Choose a reason for hiding this comment

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

NativeAOT.natvis is bundled into the .pdb file. People do not need to worry about explicitly setting a path to it. This python script is not like .natvis.

Yes, .NET debuggers are on a different shipping train and licensing plan than .NET itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

@hoyosjs, @mikem8361, should we emit it from https://github.com/dotnet/diagnostics/blob/ce653def0d1969dca0d518a95559b2acc3c6128c/src/SOS/SOS.InstallHelper/InstallHelper.cs#L65 at InstallLocation and include command script import line in ~/.lldbinit?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the Python script could be embedded into symbols and LLDB would pick it up but I only see it implemented for mach-O: https://github.com/llvm/llvm-project/blob/705e27c23474f3177670a791b5b54eefedee0cd8/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp#L202-L318

From what I see in the source code, the experience would be that LLDB will notify there's a debugging script and one then needs to make a gesture to allow it.

I like the approach from #115406 (comment) - the only unfortunate thing about that one is that the LLDB change to read the embedded formatters was only made 5 months ago so it'll take years until Linux distros pick that up.

Copy link
Member Author

Choose a reason for hiding this comment

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

It can be implemented as SOS sub-command in C++ which gives us full control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants