Skip to content

Commit 196d7a0

Browse files
Make the NativeAOT debugger script more flexible (#10016)
* Make the NativeAOT debugger script more flexible Make it able to detect the OS-specific path to the NDK toolchain binaries, as well as the path to the NDK root directory using a number of environment variables used at one time or another for this purpose. Instead of hard-coding path to the `lldb-server` binary, which is located in a versioned directory, use `clang` itself to print full path to the binary, thus making the script LLVM version agnostic. * Maybe it works here too? * Use prefixed clang binary * Fixlets * Add quotes to CLANG_PREFIX values --------- Co-authored-by: Dean Ellis <[email protected]>
1 parent 8c74126 commit 196d7a0

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

samples/NativeAOT/runwithdebugger.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,32 @@ $env:ANDROID_NDK_HOME = $_DEF_NDK_HOME
3737
# Kill any existing lldb-server processes
3838
$null = & $ADB shell "run-as net.dot.hellonativeaot killall -q -9 lldb-server"
3939

40+
$DEVICE_ARCH = & $ADB shell uname -m
41+
if ( $DEVICE_ARCH -match "aarch64" ) {
42+
$CLANG_PREFIX = "aarch64-linux-android21"
43+
} elseif ( $DEVICE_ARCH -match "x86_64" ) {
44+
$CLANG_PREFIX = "x86_64-linux-android21"
45+
} else {
46+
Write-Error "Error: unsupported device architecture $DEVICE_ARCH"
47+
exit 1
48+
}
49+
4050
# Get the appropriate path for Windows NDK
41-
$NDK_LLDB_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\19\lib\linux\aarch64\lldb-server"
42-
if (-not (Test-Path $NDK_LLDB_PATH)) {
43-
$NDK_LLDB_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\linux-x86_64\lib\clang\19\lib\linux\aarch64\lldb-server"
44-
if (-not (Test-Path $NDK_LLDB_PATH)) {
45-
$NDK_LLDB_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\darwin-x86_64\lib\clang\19\lib\linux\aarch64\lldb-server"
46-
if (-not (Test-Path $NDK_LLDB_PATH)) {
47-
Write-Error "Could not find lldb-server in any of the expected NDK locations"
51+
$NDK_CLANG_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\windows-x86_64\bin\$CLANG_PREFIX-clang"
52+
if (-not (Test-Path $NDK_CLANG_PATH)) {
53+
$NDK_CLANG_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\linux-x86_64\bin\$CLANG_PREFIX-clang"
54+
if (-not (Test-Path $NDK_CLANG_PATH)) {
55+
$NDK_CLANG_PATH = "$env:ANDROID_NDK_HOME\toolchains\llvm\prebuilt\darwin-x86_64\bin\$CLANG_PREFIX-clang"
56+
if (-not (Test-Path $NDK_CLANG_PATH)) {
57+
Write-Error "Could not find clang in any of the expected NDK locations"
4858
exit 1
4959
}
5060
}
5161
}
5262

63+
$NDK_LLDB_PATH= & $NDK_CLANG_PATH -print-file-name=lldb-server
5364
# Push lldb-server to device
54-
& $ADB push $NDK_LLDB_PATH /data/local/tmp/lldb-server
65+
& $ADB push "$NDK_LLDB_PATH" /data/local/tmp/lldb-server
5566
& $ADB shell run-as net.dot.hellonativeaot cp /data/local/tmp/lldb-server .
5667
& $ADB forward tcp:5039 tcp:5039
5768

samples/NativeAOT/runwithdebugger.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,29 @@ export ANDROID_NDK_HOME
2525
# This script is used to run the NativeAOT sample with the debugger attached.
2626
# It is used by the CI system to verify that the debugger works with NativeAOT.
2727
adb shell run-as net.dot.hellonativeaot killall -9 lldb-server > /dev/null 2>&1 || true
28-
adb push $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/19/lib/linux/aarch64/lldb-server /data/local/tmp/lldb-server
28+
29+
case $(uname) in
30+
Linux) TOOLCHAIN_OS=linux-x86_64 ;;
31+
Darwin) TOOLCHAIN_OS=darwine-x86_64 ;;
32+
*) echo "Unsupported OS: $(uname)"; exit 1 ;;
33+
esac
34+
35+
if [ -n "${ANDROID_NDK_HOME}" ]; then
36+
ANDROID_NDK_DIR="${ANDROID_NDK_HOME}"
37+
elif [ -n "${ANDROID_NDK_ROOT}" ]; then
38+
ANDROID_NDK_DIR="${ANDROID_NDK_ROOT}"
39+
elif [ -n "${ANDROID_NDK_PATH}" ]; then
40+
ANDROID_NDK_DIR="${ANDROID_NDK_PATH}"
41+
fi
42+
43+
DEVICE_ARCH="$(adb shell uname -m)"
44+
case ${DEVICE_ARCH} in
45+
aarch64) CLANG_PREFIX=aarch64-linux-android21 ;;
46+
x86_64) CLANG_PREFIX=x86_64-linux-android21 ;;
47+
*) echo "Unsupported device architecture ${DEVICE_ARCH}"; exit 1 ;;
48+
esac
49+
50+
adb push "$("${ANDROID_NDK_DIR}/toolchains/llvm/prebuilt/${TOOLCHAIN_OS}/bin/${CLANG_PREFIX}-clang" -print-file-name=lldb-server)" /data/local/tmp/lldb-server
2951
adb shell run-as net.dot.hellonativeaot cp /data/local/tmp/lldb-server .
3052
adb forward tcp:5039 tcp:5039
3153

0 commit comments

Comments
 (0)