Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliangyu3 committed Sep 18, 2024
1 parent 50a58e0 commit 3539b26
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 37 deletions.
130 changes: 93 additions & 37 deletions test-tools/dynamic-aot-debug/README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,139 @@
# Dynamic AOT Module Debugging

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.
> Note: Dynamic AOT debugging is experimental and only a few debugging capabilities are supported.
## How to use
This guide explains how to debug WAMR AOT modules with dynamic AOT features. Follow these steps to set up and run your debugging environment.

### 1. Enable Debug Configuration
## 1. Test source code

To enable dynamic AOT debugging, set the following
compile macro switch:
The following c program file is used as a debugging test file.

```bash
#include <stdio.h>

int main() {
printf("hello, world!\n");
int a = 1024;
printf("a is %d\n",a);
int b = 42;
printf("b is %d\n",b);
return 0;
}
```
cmake -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1

## 2. Build iwasm with dynamic aot debugging feature

To enable dynamic AOT debugging, ensure the following
compile options are enabled when you [build iwasm](../../product-mini/README.md):

```bash
cmake -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1 -DCMAKE_BUILD_TYPE=Debug
```

### 2. Build AOT and Object Files
## 3. Build wamrc

#### 2.1 Build wamrc Compiler
Developer may need to build out two versions of wamrc, one is to compile the wasm binary into the AOT file, the other is to compile the wasm binary into an object file. To build out the former, just build wamrc as normal, see [wamrc-compiler/README.md](../../wamr-compiler/README.md). To build out the latter, the `WAMR_BUILD_DEBUG_AOT` flag must be added to cmake, please refer to the first two steps in [doc/source_debugging_aot.md](../../doc/source_debugging_aot.md) and if you encounter the error “‘eLanguageTypeC17’ not declared in this scope”, you can bypass it by commenting out the case judgments. This will not affect the debugging results.

Ensure that wamrc is built with the WAMR_BUILD_DEBUG_AOT flag enabled. Please refer to the first two steps in [doc/source_debugging_aot.md](../../doc/source_debugging_aot.md).
## 4. Dynamic aot debugging and verification across various platforms

#### 2.2 Compile Source Code to WebAssembly (WASM)
You can adjust the compiler options for different architectures and instruction sets.

Compile test.c to test.wasm using the following command:
### 4.1 Linux

#### Compile test.c to test.wasm

```bash
/opt/wasi-sdk/bin/clang -O0 -g -gdwarf-2 -o test.wasm test.c
```
/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

#### Compile test.wasm to test.aot

```bash
./wamrc --opt-level=0 -o test.aot test.wasm
```

Adjust the compiler options for different architectures and instruction sets. For example, to target ARMv7:
#### Compile test.wasm to test object file

#### 2.3 Compile WebAssembly to AOT File
> Note: please use the version wamrc which was built with `cmake -DWAMR_BUILD_DEBUG_AOT` flag.
Generate the test.aot file using wamrc with the following command. Ensure WAMR_BUILD_DEBUG_AOT is not enabled here:
```bash
./wamrc --opt-level=0 --format=object -o test.obj test.wasm
```

#### Launch the program using gdbserver on the remote linux host

```bash
cd ~/aot_debug # This directory contains iwasm and test.aot
gdbserver hostip:port ./iwasm test.aot
```
./wamrc --opt-level=0 --target=thumbv7 --target-abi=gnueabihf --cpu=cortex-a7
--cpu-features=-neon -o test.aot test.wasm

#### Local remote debugging

```bash
expport OBJ_PATH=~/aot_debug
cd ~/aot_debug # This directory contains iwasm, test.c, test obj file and dynamic_aot_debug.py
gdb ./iwasm
(gdb) target remote hostip:port
(gdb) source dynamic_aot_debug.py
(gdb) c
(gdb) b test.c:main
(gdb) n
```

#### 2.4 Compile WebAssembly to Object File
### 4.2 ARMv7

Generate the test object file using wamrc with WAMR_BUILD_DEBUG_AOT enabled:
#### Compile test.c to test.wasm

```bash
/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
```
./wamrc --opt-level=0 --format=object --target=thumbv7 --target-abi=gnueabihf
--cpu=cortex-a7 --cpu-features=-neon -o test test.wasm

#### Compile test.wasm to test.aot

```bash
./wamrc --opt-level=0 --target=thumbv7 --target-abi=gnueabihf --cpu=cortex-a7
--cpu-features=-neon -o test.aot test.wasm
```

### 3. Start Emulator and NuttX
#### Compile test.wasm to test object file

#### 3.1 Start Emulator
> Note: please use the version wamrc which was built with `cmake -DWAMR_BUILD_DEBUG_AOT` flag.
```bash
./wamrc --opt-level=0 --format=object --target=thumbv7 --target-abi=gnueabihf
--cpu=cortex-a7 --cpu-features=-neon -o test.obj test.wasm
```

#### Start Emulator

In Terminal 1, start the emulator in debug mode and launch the GDB server:

```
```bash
# start emulator on debug mode, and will start gdb server, set port as 1234
$ ./emulator.sh vela -qemu -S -s
./emulator.sh vela -qemu -S -s
ap> iwasm test.aot
```

#### 3.2 Start NuttX Using GDB
#### 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
export OBJ_PATH=~/work/data/
gdb-multiarch ./nuttx/nuttx -ex "tar remote:1234" -ex "source dynamic_aot_debug.py"
```bash
# You can save test.obj file in this path
export OBJ_PATH=~/work/data/aot_debug
gdb-multiarch nuttx -ex "tar remote:1234" -ex "source dynamic_aot_debug.py"
```

In the GDB prompt:

```
$(gdb) c
$(gdb) b main
```bash
(gdb) c
(gdb) b test.c:main
(gdb) n
```

### 4. Workflow
## 5. Workflow

Refer to the workflow diagram (wasm-micro-runtime/test-tools/dynamic-aot-debug) for an overview of the debugging process.
Refer to the workflow diagram (wasm-micro-runtime/test-tools/dynamic-aot-debug) for an overview of the debugging process. In addition, the implementation of this dynamic aot debugging solution is not complete yet. It only supports breakpoints and single-step execution, and it is not yet known to view detailed information such as variables.
3 changes: 3 additions & 0 deletions test-tools/dynamic-aot-debug/dynamic_aot_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def add_symbol_with_aot_info(aot_module_info):
# Remove directory part if present
file_name = os.path.basename(file_name_without_extension)

# Add .obj extension to the file name
file_name = file_name + ".obj"

# Construct the path for the symbol file
path_symfile = os.path.join(path_objs, file_name)

Expand Down

0 comments on commit 3539b26

Please sign in to comment.