-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Native AOT StackFrame
method info
#92869
Comments
By default NativeAOT apps carry enough information about each method to be able to print out the The real reason this is not implemented currently is that the What is the scenario where you want the detailed breakdown of the method information from a stack trace? |
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsWhen published as a native AOT binary, _options.LogDebug("### ToString = {0}", stackFrame.ToString());
_options.LogDebug("### Has Native Image = {0}", stackFrame.HasNativeImage());
_options.LogDebug("### Native Image Base = 0x{0:x}", stackFrame.GetNativeImageBase());
_options.LogDebug("### Native Interface pointer = 0x{0:x}", stackFrame.GetNativeIP());
_options.LogDebug("### Offset = {0}", stackFrame.GetNativeOffset());
_options.LogDebug("### FileName = {0}", stackFrame.GetFileName());
_options.LogDebug("### Line no = {0}", stackFrame.GetFileLineNumber());
_options.LogDebug("### HasMethod = {0}", stackFrame.HasMethod());
_options.LogDebug("### Method = {0}", stackFrame.GetMethod());
_options.LogDebug("### ILOffset = {0}", stackFrame.GetILOffset());
As a side note, how does runtime resolve the method name in ToString() to such a nicely-looking string? If I try to symbolicate via the native debug info in the generated .PDB, the symbol name I get is
|
Thanks for the quick response @vitek-karas
To show stack trace for error-reporting SDKs, namely Sentry. It's possible to do ("offline") symbolication on the server using the generated PDB but, as I've mentioned in the original post, the symbol name doesn't look as good as the C# method info returned by AFAIK the only way to get the "nice" method name at this time is to try and parse ToString() output on the client. Or is there another way to get access to the "information about each method to be able to print out the ToString you see"? Alternatively, is it possible to get the correct c# module, class and method names from PDB(or DWARF for linux and macOS)? |
Is offline symbolication the approach that Sentry uses for IL2CPP? If so, similar approach could be used to generate stacks for Native AOT. I assume the problem right now is that the debug information generated by native AOT still doesn't look enough like C++. The name mangling scheme native AOT uses is not reversible. |
For IL2CPP (in Unity) we go through a couple more hoops that are not necessary with .NET Native AOT - I've already successfully symbolicated stack traces based on the list of loaded native images (from native APIs) and the image & symbol addresses as provided by the .net stacktrace runtime API. So that all works as expected.
Exactly, that's why I'm looking at improving the information from PDB with whatever is available at runtime. This info (before mangling) is available at runtime but as I've mentioned in the original post, it's only part of the ToString() result. |
Parsing For .NET 9, we could consider these, in order of preference:
3 is my least preferred option because we'd need to very carefully document the small subset of things that work reliably. one can absolutely get a 100% usable |
Thanks @MichalStrehovsky I completely agree with your reasoning and would be looking forward to get this info in the future. In the meantime, I'll resort to parsing |
When looking at Lines 35 to 59 in 2542302
It would be useful to have the package name (not just the namespace & class) whenever available. What's the chance of this changing? |
When you say "package information", do you mean the native module name and native address? If so, you can force stack traces to only report things in that format by setting this AppContext switch: Line 31 in 2542302
(Either call AppContext.SetSwitch programmatically at startup or places this value as a RuntimeHostConfigurationOption into the MSBuild project file) I just realized we don't have any testing for this switch. If you do take a dependency on it, please submit a test to https://github.com/dotnet/runtime/tree/main/src/tests/nativeaot/SmokeTests/StackTraceMetadata to test this so that we don't regress it (the test can simply set the appcontext switch and inspect a stack trace afterwards). |
I meant the module name. As for the switch - that would disable the class+namespace+method name resolution right? That's not what I'm looking for. Instead, I'd like to be able to get the class+namespace+method name and the module name at the same time. As you can see in the |
The module name we print is not the module name you think it is. It is the name of the native module, not the original source assembly. The original source assembly name gets dropped during native compilation because we don't have any use for it (it's not part of the "official" stack trace format string). We could potentially include it if we go with option 2 in the above comment. (It might be a good exercise if you could propose a shape for this API that you would need). |
Ah, that clears things up then, thanks. I'll ignore it then. |
I wrote up a proposal for trim-safe/aot-safe version of this API: #96528. I'm going to close this since it basically supersedes this. |
When published as a native AOT binary,
System.Diagnostics.StackFrame
doesn't have method information (as returned byGetMethod
). Interestingly, some info is available at runtime because it is printed byToString()
. It would be preferrable to expose the module & method name via appropriate methods so that we don't have to rely on parsingToString()
output. See an example output below:As a side note, how does runtime resolve the method name in ToString() to such a nicely-looking string? If I try to symbolicate via the native debug info in the generated .PDB, the symbol name I get is
S_P_CoreLib_System_Runtime_CompilerServices_TaskAwaiter__HandleNonSuccessAndDebuggerNotification
The text was updated successfully, but these errors were encountered: