-
Notifications
You must be signed in to change notification settings - Fork 561
Add Support for Debugging NativeAOT #9855
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6c543ac to
0bcd739
Compare
jkotas
reviewed
Mar 11, 2025
56117a8 to
cd53116
Compare
jkotas
reviewed
Mar 12, 2025
jonpryor
reviewed
Mar 18, 2025
jonpryor
reviewed
Mar 18, 2025
|
@dellis1972: please update the PR description for how people should use the feature, which presumably will involve running the |
4e7a9a2 to
b4f23f5
Compare
|
@jonpryor I updated this. Also added a lldb formatter for strings so we can view the value of the string in VSCode. Sorry I think I blatted your formatting changes when I force pushed. |
Make the instructions more readable to @jonpryor.
d81cde9 to
3735394
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you are using VSCode from the android repo, you can go to the "Run and Debug" Badge, and select "Debug NativeAOT" from the drop down. This will let you debug the NativeAOT sample. Fire up your emulator or connect your device, then click the play button next to "Debug NativeAOT" and it will launch the app. If the Java debugger dialog is not cleared automatically, goto the "Debug Console" which should be showing the lldb REPL, and type
clearjdb. Your app should then continue.Note it will take some time to build and install the NativeAOT sample. VSCode will probably
give you an option to cancel or wait, you can just ignore this dialog.
If you want to to use
lldbdirectly then you can use therunwithdebugger.sh/runwithdebugger.ps1scripts to run all the steps you need to setup the debugger manually.What follows is an explanation of what that script does.
How
runwithdebugger.*scripts workThe first this the script does is to install the application. It does this using the
InstallMSBuild target.Next it needs to install
lldb-serveron the device.The following steps, install the
lldb-server, stop any existing lldb-server process and then launches it. It also sets up the requiredadbport forwarding so we can connect to the server from the local machine.Note: We have to run the
lldb-serverin the context of the app so it has the correct networking permissions. This is why we use therun-ascommand.Note: the path
clang/*/lib/might change depending on your version of the NDK.Once
lldb-serveris up and running, the script with run up the app using the followingThe
-Dis important as it stops the app from running until the java debugger is attached. This can be useful if your app is crashing on startup.If you do not want to the app to pause on startup, you can omit the
-Dargument.Now that the app is running we need to get the process id. We do that using
adb shell ps.The
grepis used to filter the results to only our app.adb shell ps | grep net.dot.hellonativeaotThe script then uses
awkor andregexto extract the process id.It then adds an
adbport forward for port8700to this process id. This is so we can easilyattach the java debugger (
jdb) to the app to clear the debugger dialog box.What does the launch.json do?
In addition to the script above, there are a number of commands in
launch.jsonwhich arerun when launching via VSCode. If you want to run these manually rather than using VSCode
you will need to use
lldbfrom the command line it execute the following commands.These setup
lldband loads the symbols, then attaches to the process. It also sets upa
clearjdbcommand which you can use from within thelldbREPL to clear the JavaDebugger dialog you get when you launch your app.
If your symbols are in a separate
.dbgfile, you can use the following.> target symbols add samples/NativeAOT/bin/Debug/net10.0-android/android-arm64/native/NativeAOT.so.dbgNext you need to attach the java debugger to clear the dialog which is currently blocking the application execution. You can skip this step if you omitted the
-Dwhenlaunching the activity.
you can do this via the
lldbterminal by using theclearjdbfunction which is anextension function we have.
or use the following from the command line.
python3 samples/NativeAOT/lldb_commands.pyalternatively, you can also clear it manually via
You will want to type
quitto exit thejdbterminal once it has connected.If you used the script you will not need to setup the
adbport forward.Breakpoints
Setting breakpoints just need to use the filename and line number, these are just standard
lldbcommands.breakpoint set -f MainActivity.cs -l 34This will place a breakpoint at line 34 of MainActivity.cs.