-
Notifications
You must be signed in to change notification settings - Fork 737
Improvements in some documentation #1546
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
Changes from all commits
75d8ae8
e346031
3f3e6ea
6823de9
f60c38d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,22 @@ WAMR supports source level debugging based on DWARF (normally used in C/C++/Rust | |
|
|
||
| **The lldb's ability to debug wasm application is based on the patch [Add class WasmProcess for WebAssembly debugging](https://reviews.llvm.org/D78801). Thanks very much to the author @paolosev for such a great work!** | ||
|
|
||
| ## Example app code | ||
|
|
||
| The following `test.c` file is used in this document as example: | ||
|
|
||
| ``` | ||
| #include <stdio.h> | ||
|
|
||
| int | ||
| main(void) | ||
| { | ||
| printf("hello\n"); | ||
|
|
||
| return 0; | ||
| } | ||
| ``` | ||
|
|
||
| ## Build wasm application with debug information | ||
| To debug your application, you need to compile them with debug information. You can use `-g` option when compiling the source code if you are using wasi-sdk (also work for emcc and rustc): | ||
| ``` bash | ||
|
|
@@ -57,6 +73,12 @@ Then you can use lldb commands to debug your applications. Please refer to [lldb | |
|
|
||
| > Note: AOT debugging is experimental and only a few debugging capabilities are supported. | ||
|
|
||
| 0. Optionally, build llvm if not done already | ||
| ``` bash | ||
| cd ${WAMR_ROOT}/wamr-compiler | ||
| ./build_llvm.sh # (or "./build_llvm_xtensa.sh" to support xtensa target) | ||
| ``` | ||
|
|
||
| 1. Build lldb (assume you have already built llvm) | ||
| ``` bash | ||
| cd ${WAMR_ROOT}/core/deps/llvm/build | ||
|
|
@@ -76,21 +98,21 @@ make -j $(nproc) | |
| ``` bash | ||
| cd ${WAMR_ROOT}/product-mini/platforms/linux | ||
| mkdir build && cd build | ||
| cmake .. -DWAMR_BUILD_DEBUG_AOT=1 | ||
| cmake .. -DCMAKE_BUILD_TYPE:STRING="Debug" -DWAMR_BUILD_DEBUG_AOT=1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must we build iwasm with Debug mode?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think so. i guess his intention was to match with the example below, where lldb is showing the source code of iwasm.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, how about we add a note here to mention that the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess it makes sense. @maht can you confirm? |
||
| make | ||
| ``` | ||
|
|
||
| 4. Compile wasm module to AOT module | ||
| ``` bash | ||
| wamrc -o test.aot test.wasm | ||
| ${WAMR_ROOT}/wamr-compiler/build/wamrc --opt-level=0 --size-level=0 -o test.aot test.wasm | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must we add
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when i created the example in #1496,
it was on x86-64 mac.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, @maht could you help confirm it? Since |
||
| ``` | ||
|
|
||
| 5. Execute iwasm using lldb | ||
|
|
||
| Then you can use lldb commands to debug both wamr runtime and your wasm application in ***current terminal***. | ||
|
|
||
| ``` bash | ||
| % lldb iwasm -- test.aot | ||
| % ${WAMR_ROOT}/core/deps/llvm/build/bin/lldb ${WAMR_ROOT}/product-mini/platforms/linux/build/iwasm -- test.aot | ||
| (lldb) target create "iwasm" | ||
| Current executable set to 'iwasm' (x86_64). | ||
| (lldb) settings set -- target.run-args "test.aot" | ||
|
|
@@ -129,7 +151,7 @@ wamrc -o test.aot test.wasm | |
| Current breakpoints: | ||
| 1: name = 'main', locations = 2, resolved = 2, hit count = 2 | ||
| 1.1: where = iwasm`main + 48 at main.c:294:11, address = 0x0000000100001020, resolved, hit count = 1 | ||
| 1.2: where = JIT(0x100298004)`main + 12 at hello.c:6:9, address = 0x00000001002980a0, resolved, hit count = 1 | ||
| 1.2: where = JIT(0x100298004)`main + 12 at test.c:6:9, address = 0x00000001002980a0, resolved, hit count = 1 | ||
|
|
||
| (lldb) | ||
| ``` | ||
|
|
@@ -139,7 +161,7 @@ wamrc -o test.aot test.wasm | |
| * The first `main` function, which is in `main.c`, is the main | ||
| function of the iwasm command. | ||
|
|
||
| * The second `main` function, which is in `hello.c`, is the main | ||
| * The second `main` function, which is in `test.c`, is the main | ||
| function of the AOT-compiled wasm module. | ||
|
|
||
| * WAMR AOT debugging uses the GDB JIT loader mechanism to load | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ will be generated. | |
|
|
||
| ```bash | ||
| cd build | ||
| ./iwasm --native-lib=libtest_add.so --native-lib=libtest_sqrt.so wasm-app/test.wasm | ||
| ./iwasm --native-lib=./libtest_add.so --native-lib=./libtest_sqrt.so wasm-app/test.wasm | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i picked this commit in #1643 as it conflicts otherwise. |
||
| ``` | ||
|
|
||
| The output is: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.