Skip to content

Commit 5641595

Browse files
committed
Add Native AOT diagnostics support documentation for iOS-like platforms
1 parent e20eb39 commit 5641595

File tree

7 files changed

+139
-27
lines changed

7 files changed

+139
-27
lines changed

.openpublishing.redirection.core.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@
352352
"redirect_url": "/dotnet/core/deploying/native-aot/index",
353353
"redirect_document_id": true
354354
},
355+
{
356+
"source_path_from_root": "/docs/core/deploying/native-aot/diagnostics.md",
357+
"redirect_url": "/dotnet/core/deploying/native-aot/diagnostics/index",
358+
"redirect_document_id": true
359+
},
355360
{
356361
"source_path_from_root": "/docs/core/deploying/prepare-libraries-for-trimming.md",
357362
"redirect_url": "/dotnet/core/deploying/trimming/prepare-libraries-for-trimming",
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
11
---
2-
title: Diagnostics and instrumentation
3-
description: Learn about diagnostics in Native AOT applications
2+
title: Diagnostics and instrumentation on desktop platforms
3+
description: Learn about diagnostics in Native AOT applications on desktop platforms
44
author: lakshanf
55
ms.author: lakshanf
66
ms.date: 08/07/2023
77
---
88

9-
# Diagnostics and instrumentation
10-
11-
Native AOT shares some, but not all, diagnostics and instrumentation capabilities with CoreCLR. Because of CoreCLR's rich selection of diagnostic utilities, it's sometimes appropriate to diagnose and debug problems in CoreCLR. Apps that are [trim-compatible](../trimming/prepare-libraries-for-trimming.md) shouldn't have behavioral differences, so investigations often apply to both runtimes. Nonetheless, some information can only be gathered after publishing, so Native AOT also provides post-publish diagnostic tooling.
12-
13-
## .NET 8 Native AOT diagnostic support
14-
15-
The following table summarizes diagnostic features supported for Native AOT deployments:
16-
17-
| Feature | Fully supported | Partially supported | Not supported |
18-
| - | - | - | - |
19-
| [Observability and telemetry](#observability-and-telemetry) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
20-
| [Development-time diagnostics](#development-time-diagnostics) | <span aria-hidden="true">✔️</span><span class="visually-hidden">Fully supported</span> | | |
21-
| [Native debugging](#native-debugging) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
22-
| [CPU Profiling](#cpu-profiling) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
23-
| [Heap analysis](#heap-analysis) | | | <span aria-hidden="true">❌</span><span class="visually-hidden">Not supported</span> |
9+
# Native AOT diagnostic support on desktop platforms
2410

2511
## Observability and telemetry
2612

27-
As of .NET 8, the Native AOT runtime supports [EventPipe](../../diagnostics/eventpipe.md), which is the base layer used by many logging and tracing libraries. You can interface with EventPipe directly through APIs like `EventSource.WriteEvent` or you can use libraries built on top, like [OpenTelemetry](../../diagnostics/observability-with-otel.md). EventPipe support also allows .NET diagnostic tools like [dotnet-trace](../../diagnostics/dotnet-trace.md), [dotnet-counters](../../diagnostics/dotnet-counters.md), and [dotnet-monitor](../../diagnostics/dotnet-monitor.md) to work seamlessly with Native AOT or CoreCLR applications. EventPipe is an optional component in Native AOT. To include EventPipe support, set the `EventSourceSupport` MSBuild property to `true`.
13+
As of .NET 8, the Native AOT runtime supports [EventPipe](../../../diagnostics/eventpipe.md), which is the base layer used by many logging and tracing libraries. You can interface with EventPipe directly through APIs like `EventSource.WriteEvent` or you can use libraries built on top, like [OpenTelemetry](../../../diagnostics/observability-with-otel.md). EventPipe support also allows .NET diagnostic tools like [dotnet-trace](../../../diagnostics/dotnet-trace.md), [dotnet-counters](../../../diagnostics/dotnet-counters.md), and [dotnet-monitor](../../../diagnostics/dotnet-monitor.md) to work seamlessly with Native AOT or CoreCLR applications. EventPipe is an optional component in Native AOT. To include EventPipe support, set the `EventSourceSupport` MSBuild property to `true`.
2814

2915
```xml
3016
<PropertyGroup>
3117
<EventSourceSupport>true</EventSourceSupport>
3218
</PropertyGroup>
3319
```
3420

35-
Native AOT provides partial support for some [well-known event providers](../../diagnostics/well-known-event-providers.md). Not all [runtime events](../../../fundamentals/diagnostics/runtime-events.md) are supported in Native AOT.
21+
Native AOT provides partial support for some [well-known event providers](../../../diagnostics/well-known-event-providers.md). Not all [runtime events](../../../../fundamentals/diagnostics/runtime-events.md) are supported in Native AOT.
3622

3723
## Development-time diagnostics
3824

@@ -55,7 +41,7 @@ The Native AOT compiler generates information about line numbers, types, locals,
5541
To debug managed exceptions, set a breakpoint on the `RhThrowEx` method, which is called whenever a managed exception is thrown. The exception is stored in the `rcx` or `x0` register. If your debugger supports viewing C++ objects, you can cast
5642
the register to `S_P_CoreLib_System_Exception*` to see more information about the exception.
5743

58-
Collecting a [dump](../../diagnostics/dumps.md) file for a Native AOT application involves some manual steps in .NET 8.
44+
Collecting a [dump](../../../diagnostics/dumps.md) file for a Native AOT application involves some manual steps in .NET 8.
5945

6046
### Visual Studio-specific notes
6147

@@ -69,12 +55,12 @@ To see what exception was thrown, start debugging (**Debug > Start Debugging** o
6955

7056
When publishing, the Native AOT compiler produces both an executable and a symbol file. Native debugging, and related activities like profiling, require access to the native symbol file. If this file isn't present, you might have degraded or broken results.
7157

72-
For information about the name and location of the symbol file, see [Native debug information](index.md#native-aot-deployment).
58+
For information about the name and location of the symbol file, see [Native debug information](../index.md#native-aot-deployment).
7359

7460
## CPU profiling
7561

7662
Platform-specific tools like [PerfView](https://github.com/microsoft/perfview) and [Perf](https://perf.wiki.kernel.org/index.php/Main_Page) can be used to collect CPU samples of a Native AOT application.
7763

7864
## Heap analysis
7965

80-
Managed heap analysis isn't currently supported in Native AOT. Heap analysis tools like [dotnet-gcdump](../../diagnostics/dotnet-gcdump.md), [PerfView](https://github.com/microsoft/perfview), and Visual Studio heap analysis tools don't work in Native AOT in .NET 8.
66+
Managed heap analysis isn't currently supported in Native AOT. Heap analysis tools like [dotnet-gcdump](../../../diagnostics/dotnet-gcdump.md), [PerfView](https://github.com/microsoft/perfview), and Visual Studio heap analysis tools don't work in Native AOT in .NET 8.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Diagnostics and instrumentation
3+
description: Learn about diagnostics in Native AOT applications
4+
author: lakshanf
5+
ms.author: lakshanf
6+
ms.date: 08/07/2023
7+
---
8+
9+
# Diagnostics and instrumentation
10+
11+
Native AOT shares some, but not all, diagnostics and instrumentation capabilities with CoreCLR on desktop platforms and Mono on mobile platforms. Because of CoreCLR's and Mono's rich selection of diagnostic utilities, it's sometimes appropriate to diagnose and debug problems in CoreCLR or Mono, rather than with Native AOT. Apps that are [trim-compatible](../../trimming/prepare-libraries-for-trimming.md) shouldn't have behavioral differences, so investigations often apply between runtimes. Nonetheless, some information can only be gathered after publishing, so Native AOT also provides post-publish diagnostic tooling.
12+
13+
## Native AOT diagnostic support
14+
15+
The following table summarizes diagnostic features supported for Native AOT deployments and a more detailed description of diagnostics support on different platforms can be found on dedicated pages:
16+
17+
- [Desktop platforms](./desktop-platforms.md)
18+
- [iOS-like platforms](./ios-like-platforms.md)
19+
20+
### [Desktop platforms](#tab/desktop-plat)
21+
22+
| Feature | Fully supported | Partially supported | Not supported |
23+
| - | - | - | - |
24+
| [Observability and telemetry](./desktop-platforms.md#observability-and-telemetry) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
25+
| [Development-time diagnostics](./desktop-platforms.md#development-time-diagnostics) | <span aria-hidden="true">✔️</span><span class="visually-hidden">Fully supported</span> | | |
26+
| [Native debugging](./desktop-platforms.md#native-debugging) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
27+
| [CPU Profiling](./desktop-platforms.md#cpu-profiling) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
28+
| [Heap analysis](./desktop-platforms.md#heap-analysis) | | | <span aria-hidden="true">❌</span><span class="visually-hidden">Not supported</span> |
29+
30+
### [iOS-like platforms](#tab/ios-like-plat)
31+
32+
| Feature | Fully supported | Partially supported | Not supported |
33+
| - | - | - | - |
34+
| [Observability and telemetry](./ios-like-platforms.md#observability-and-telemetry) | | | <span aria-hidden="true">❌</span><span class="visually-hidden">Not supported</span> |
35+
| [Development-time diagnostics](./ios-like-platforms.md#development-time-diagnostics) | <span aria-hidden="true">✔️</span><span class="visually-hidden">Fully supported</span> | | |
36+
| [Native debugging](./ios-like-platforms.md#native-debugging) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
37+
| [CPU Profiling](./ios-like-platforms.md#cpu-profiling) | | <span aria-hidden="true">✔️</span><span class="visually-hidden">Partially supported</span> | |
38+
| [Heap analysis](./ios-like-platforms.md#heap-analysis) | | | <span aria-hidden="true">❌</span><span class="visually-hidden">Not supported</span> |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Diagnostics and instrumentation on iOS-like platforms
3+
description: Learn about diagnostics in Native AOT applications on iOS-like platforms
4+
author: ivanpovazan
5+
ms.author: ivanpovazan
6+
ms.date: 11/11/2024
7+
---
8+
9+
# Native AOT diagnostic support on iOS-like platforms
10+
11+
## Observability and telemetry
12+
13+
Tracing of .NET applications on mobile platforms is enabled through [dotnet-dsrouter](../../../diagnostics/dotnet-dsrouter.md) which connects diagnostic tooling with .NET mobile applications running on iOS-like platforms over TCP/IP. However, Native AOT is currently not compatible with this scenario as it does not support EventPipe/DiagnosticServer components built with TCP/IP stack.
14+
15+
## Development-time diagnostics
16+
17+
The .NET CLI tooling (`dotnet` SDK) offers separate commands for `build` and `publish`. `dotnet build` (or `Start Debugging (F5)` in VS Code), uses Mono by default when building or launching .NET MAUI iOS (or MacCatalyst) applications. Only `dotnet publish` creates a Native AOT application, if this deployment model is enabled in the project file. Publishing your app as Native AOT, produces an app that has been ahead-of-time (AOT) compiled to native code. As described in this document, not all diagnostic tools will work seamlessly with published Native AOT applications.
18+
However, all applications that are trim and AOT-compatible, i.e., that do not produce any trim and AOT warnings during build time, shouldn't have behavioral differences between Mono and Native AOT.
19+
Therefore, all .NET development-time diagnostic tools (like Hot Reload) are still available for developers during mobile app development cycle.
20+
We recommend developing, debugging, and testing the applications as usual and publishing the working app with Native AOT as one of the last steps.
21+
22+
## Native debugging
23+
24+
When you run your .NET MAUI iOS (or MacCatalyst) app during development, like inside VS Code, or with `dotnet build -t:Run`, it runs on Mono by default. However, if `PublishAot` is present in the project file, the behavior is expected to be the same between Mono and Native AOT when the application is not producing any trim and AOT warnings upon build. This characteristic allows you to use the standard VS Code managed debugging engine for development and testing, if your application fulfils the mentioned requirement.
25+
26+
After publishing, Native AOT applications are true native binaries. The managed debugger won't work on them. However, the Native AOT compiler generates fully native executable files that you can debug with `lldb`. Debugging a MacCatalyst app with `lldb` is straight-forward, as it is executed on the same system. However, debugging NativeAOT iOS applications requires a few extra steps which are covered in the following subsection.
27+
28+
### Debugging .NET MAUI iOS applications with NativeAOT
29+
30+
.NET MAUI applications which are compatible with NativeAOT and are properly configured and published with this deployment model (for more information see: [Publish using Native AOT](https://learn.microsoft.com/en-us/dotnet/maui/deployment/nativeaot?view=net-maui-9.0#publish-using-native-aot), can be debugged in the following ways.
31+
32+
#### iOS
33+
34+
1. Publish your app with Native AOT targeting `ios-arm64` and store the following information:
35+
36+
- Application name - referenced bellow as `<app-name>`
37+
- Bundle identifier - referenced bellow as `<bundle-identifier>`
38+
- Path to the published application's archive *.ipa* file - referenced bellow as `<path-to-ipa>`
39+
40+
2. Discover physical device ID - referenced bellow as: `<device-identifier>`
41+
42+
```bash
43+
xcrun devicectl list devices
44+
```
45+
46+
3. Install the app on your physical device
47+
48+
```bash
49+
xcrun devicectl device install app --device <device-identifier> <path-to-ipa>
50+
```
51+
52+
4. Launch the app stopped on your physical device
53+
54+
```bash
55+
xcrun devicectl device process launch --device <device-identifier> --start-stopped <bundle-identifier>
56+
```
57+
58+
5. Open `lldb` and connect to your physical device
59+
60+
```bash
61+
(lldb) device select <device-identifier>
62+
(lldb) device process attach -n <app-name>
63+
```
64+
65+
After successfully completing previous steps, you are all set to start debugging your Native AOT .NET MAUI iOS application with `lldb`.
66+
67+
### Importance of the symbol file
68+
69+
By default, debug symbols are stripped from the application's binary file into *.dSYM* files. This file is used by debuggers and post mortem analysis tools to show information about local variables, source line numbers, to recreate stack traces of crash dumps etc. Therefore, it is essential to preserve it before submitting your application to App Store.
70+
71+
## CPU profiling
72+
73+
[Xcode Instruments](https://developer.apple.com/download/) can be used to collect CPU samples of a Native AOT application.
74+
75+
## Heap analysis
76+
77+
Currently not supported with Native AOT.

docs/core/deploying/native-aot/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ By default, Native AOT publishing produces debug information in a separate file:
113113

114114
- Linux: *.dbg*
115115
- Windows: *.pdb*
116-
- macOS: *.dSYM* folder
116+
- MacOS/MacCatalyst/iOS/tvOS: *.dSYM* folder
117117

118-
The debug file is necessary for running the app under the [debugger or inspecting crash dumps](./diagnostics.md#importance-of-the-symbol-file). On Unix-like platforms, set the `StripSymbols` property to `false` to include the debug information in the native binary. Including debug information makes the native binary larger.
118+
The debug file is necessary for running the app under the debugger or inspecting crash dumps on both: [desktop](./diagnostics/desktop-platforms.md#importance-of-the-symbol-file) and [mobile](./diagnostics/ios-like-platforms.md#importance-of-the-symbol-file) platforms. On Unix-like platforms, set the `StripSymbols` property to `false` to include the debug information in the native binary. Including debug information makes the native binary larger.
119119

120120
```xml
121121
<PropertyGroup>
@@ -136,7 +136,7 @@ Native AOT apps have the following limitations:
136136
- Apps include required runtime libraries (just like [self-contained apps](../index.md#publish-self-contained), increasing their size as compared to framework-dependent apps).
137137
- <xref:System.Linq.Expressions> always use their interpreted form, which is slower than run-time generated compiled code.
138138
- Not all the runtime libraries are fully annotated to be Native AOT compatible. That is, some warnings in the runtime libraries aren't actionable by end developers.
139-
- [Diagnostic support for debugging and profiling](./diagnostics.md) with some limitations.
139+
- [Diagnostic support for debugging and profiling](./diagnostics/index.md) with some limitations.
140140
- Support for some ASP.NET Core features. For more information, see [ASP.NET Core support for Native AOT](/aspnet/core/fundamentals/native-aot/).
141141

142142
The publish process analyzes the entire project and its dependencies for possible limitations. Warnings are issued for each limitation the published app might encounter at run time.

docs/core/diagnostics/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.topic: overview
99

1010
Software doesn't always behave as you would expect, but .NET Core has tools and APIs that will help you diagnose these issues quickly and effectively.
1111

12-
[Native AOT deployment](../../core/deploying/native-aot/index.md) is an application model that's been available since .NET 7. For information about .NET 8 diagnostic support for Native AOT apps, see [Native AOT diagnostics](../../core/deploying/native-aot/diagnostics.md).
12+
[Native AOT deployment](../../core/deploying/native-aot/index.md) is an application model that's been available since .NET 7. For information about .NET 8 diagnostic support for Native AOT apps, see [Native AOT diagnostics](../../core/deploying/native-aot/diagnostics/index.md).
1313

1414
This article helps you find the various tools you need.
1515

docs/navigate/devops-testing/toc.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,13 @@ items:
498498
- name: Optimize AOT deployments
499499
href: ../../core/deploying/native-aot/optimizing.md
500500
- name: AOT diagnostics
501-
href: ../../core/deploying/native-aot/diagnostics.md
501+
items:
502+
- name: Overview
503+
href: ../../core/deploying/native-aot/diagnostics/index.md
504+
- name: Desktop platforms
505+
href: ../../core/deploying/native-aot/diagnostics/desktop-platforms.md
506+
- name: iOS-like platforms
507+
href: ../../core/deploying/native-aot/diagnostics/ios-like-platforms.md
502508
- name: Native code interop
503509
href: ../../core/deploying/native-aot/interop.md
504510
- name: Build native libraries

0 commit comments

Comments
 (0)