-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangliangyu3
committed
Sep 12, 2024
1 parent
6631dfc
commit 6a4f53f
Showing
1 changed file
with
46 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,84 @@ | ||
# Dynamic AOT Module Debugging | ||
|
||
### How to use | ||
This guide outlines the process for debugging WAMR AOT module compiled modules using dynamic AOT debugging features. Follow the steps below to set up and run your debugging environment. | ||
|
||
#### 1. Enable config | ||
## How to use | ||
|
||
### 1. Enable Debug Configuration | ||
|
||
To enable dynamic AOT debugging, set the following | ||
compile macro switch: | ||
|
||
``` | ||
WASM_ENABLE_AOT=1 | ||
WASM_ENABLE_DYNAMIC_AOT_DEBUG=1 | ||
``` | ||
|
||
#### 2. Build aot and obj file | ||
### 2. Build AOT and Object Files | ||
|
||
#### 2.1 Build wamrc Compiler | ||
|
||
- build [wamrc](https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/wamr-compiler) (enable WAMR_BUILD_DEBUG_AOT) | ||
- build test.c to test.wasm | ||
Ensure that wamrc is built with the WAMR_BUILD_DEBUG_AOT flag enabled. You can find the wamrc compiler [here](https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/wamr-compiler) | ||
|
||
#### 2.2 Compile Source Code to WebAssembly (WASM) | ||
|
||
Compile test.c to test.wasm using the following command: | ||
|
||
``` | ||
/opt/wasi-sdk/bin/clang -O0 -nostdlib -z stack-size=8192 -Wl,--initial-memory=65536 -g -gdwarf-2 -o test.wasm test.c -Wl,--export=main -Wl,--export=__main_argc_argv -Wl,--export=__heap_base -Wl,--export=__data_end -Wl,--no-entry -Wl,--allow-undefined | ||
/opt/wasi-sdk/bin/clang -O0 -nostdlib -z stack-size=8192 -Wl,--initial-memory=65536 | ||
-g -gdwarf-2 -o test.wasm test.c -Wl,--export=main -Wl,--export=__main_argc_argv | ||
-Wl,--export=__heap_base -Wl,--export=__data_end -Wl,--no-entry -Wl,--allow-undefined | ||
``` | ||
You can specify other architectures and instruction sets to compile, here we take armv7 as an example: | ||
|
||
- build test.wasm to test.aot | ||
Adjust the compiler options for different architectures and instruction sets. For example, to target ARMv7: | ||
|
||
#### 2.3 Compile WebAssembly to AOT File | ||
|
||
Compile and generate the test.aot file using wamrc without WAMR_BUILD_DEBUG_AOT. | ||
Generate the test.aot file using wamrc with the following command. Ensure WAMR_BUILD_DEBUG_AOT is not enabled here: | ||
|
||
``` | ||
./wamrc --opt-level=0 --target=thumbv7 --target-abi=gnueabihf --cpu=cortex-a7 --cpu-features=-neon -o test.aot test.wasm | ||
./wamrc --opt-level=0 --target=thumbv7 --target-abi=gnueabihf --cpu=cortex-a7 | ||
--cpu-features=-neon -o test.aot test.wasm | ||
``` | ||
|
||
- build test.wasm to test obj file | ||
#### 2.4 Compile WebAssembly to Object File | ||
|
||
Use wamrc that needs to turn on WAMR_BUILD_DEBUG_AOT to compile and generate the test obj file. | ||
Generate the test object file using wamrc with WAMR_BUILD_DEBUG_AOT enabled: | ||
|
||
``` | ||
./wamrc --opt-level=0 --format=object --target=thumbv7 --target-abi=gnueabihf --cpu=cortex-a7 --cpu-features=-neon -o test test.wasm | ||
./wamrc --opt-level=0 --format=object --target=thumbv7 --target-abi=gnueabihf | ||
--cpu=cortex-a7 --cpu-features=-neon -o test test.wasm | ||
``` | ||
|
||
#### 3. Start emulator and nuttx | ||
### 3. Start Emulator and NuttX | ||
|
||
- Start emulator in terminal 1 | ||
#### 3.1 Start Emulator | ||
|
||
In Terminal 1, start the emulator in debug mode and launch the GDB server: | ||
|
||
``` | ||
/* start emulator on debug mode, and will start gdb server, set port as 1234 */ | ||
./emulator.sh vela -qemu -S -s | ||
$ iwasm test.aot | ||
# start emulator on debug mode, and will start gdb server, set port as 1234 | ||
$ ./emulator.sh vela -qemu -S -s | ||
ap> iwasm test.aot | ||
``` | ||
|
||
- Start nuttx by GDB in terminal 2 | ||
#### 3.2 Start NuttX Using GDB | ||
|
||
In Terminal 2, set the path to your object file and start NuttX with GDB: | ||
|
||
``` | ||
/* You can save test obj file in this path */ | ||
# You can save test obj file in this path | ||
export OBJ_PATH=~/work/data/ | ||
gdb-multiarch ./nuttx/nuttx -ex "tar remote:1234" -ex "source dynamic_aot_debug.py" | ||
``` | ||
|
||
In the GDB prompt: | ||
|
||
``` | ||
$(gdb) c | ||
$(gdb) b main | ||
``` | ||
|
||
#### 4. Workflow | ||
### 4. Workflow | ||
|
||
image:: dynamic_aot_debug_workflow.png | ||
Refer to the workflow diagram (wasm-micro-runtime/test-tools/dynamic-aot-debug) for an overview of the debugging process. |