-
Notifications
You must be signed in to change notification settings - Fork 540
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
Add Support for Debugging NativeAOT #9855
Open
dellis1972
wants to merge
30
commits into
main
Choose a base branch
from
dev/dellis1972/debugnativeaot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
lldb
directly then you can use therunwithdebugger.sh
/runwithdebugger.ps1
scripts 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
Install
MSBuild target.Next it needs to install
lldb-server
on the device.The following steps, install the
lldb-server
, stop any existing lldb-server process and then launches it. It also sets up the requiredadb
port forwarding so we can connect to the server from the local machine.Note: We have to run the
lldb-server
in the context of the app so it has the correct networking permissions. This is why we use therun-as
command.Note: the path
clang/*/lib/
might change depending on your version of the NDK.Once
lldb-server
is up and running, the script with run up the app using the followingThe
-D
is 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
-D
argument.Now that the app is running we need to get the process id. We do that using
adb shell ps
.The
grep
is used to filter the results to only our app.adb shell ps | grep net.dot.hellonativeaot
The script then uses
awk
or andregex
to extract the process id.It then adds an
adb
port forward for port8700
to 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.json
which arerun when launching via VSCode. If you want to run these manually rather than using VSCode
you will need to use
lldb
from the command line it execute the following commands.These setup
lldb
and loads the symbols, then attaches to the process. It also sets upa
clearjdb
command which you can use from within thelldb
REPL to clear the JavaDebugger dialog you get when you launch your app.
If your symbols are in a separate
.dbg
file, you can use the following.> target symbols add samples/NativeAOT/bin/Debug/net10.0-android/android-arm64/native/NativeAOT.so.dbg
Next 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
-D
whenlaunching the activity.
you can do this via the
lldb
terminal by using theclearjdb
function which is anextension function we have.
or use the following from the command line.
python3 samples/NativeAOT/lldb_commands.py
alternatively, you can also clear it manually via
You will want to type
quit
to exit thejdb
terminal once it has connected.If you used the script you will not need to setup the
adb
port forward.Breakpoints
Setting breakpoints just need to use the filename and line number, these are just standard
lldb
commands.breakpoint set -f MainActivity.cs -l 34
This will place a breakpoint at line 34 of MainActivity.cs.