@@ -86,11 +86,71 @@ wamrc -o test.aot test.wasm
86
86
```
87
87
88
88
5 . Execute iwasm using lldb
89
- ``` bash
90
- lldb-12 iwasm -- test.aot
91
- ```
92
89
93
- Then you can use lldb commands to debug both wamr runtime and your wasm application in *** current terminal***
90
+ Then you can use lldb commands to debug both wamr runtime and your wasm application in *** current terminal*** .
91
+
92
+ ``` bash
93
+ % lldb iwasm -- test.aot
94
+ (lldb) target create " iwasm"
95
+ Current executable set to ' iwasm' (x86_64).
96
+ (lldb) settings set -- target.run-args " test.aot"
97
+ (lldb) settings set plugin.jit-loader.gdb.enable on
98
+ (lldb) b main
99
+ Breakpoint 1: where = iwasm` main + 48 at main.c:294:11, address = 0x0000000100001020
100
+ (lldb) run
101
+ Process 27954 launched: ' /tmp/bin/iwasm' (x86_64)
102
+ Process 27954 stopped
103
+ * thread # 1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
104
+ frame #0: 0x0000000100001020 iwasm ` main(argc=2, argv=0x00007ff7bfeff678) at main.c:294:11
105
+ 291 int
106
+ 292 main(int argc, char * argv[])
107
+ 293 {
108
+ -> 294 int32 ret = -1;
109
+ 295 char * wasm_file = NULL;
110
+ 296 const char * func_name = NULL;
111
+ 297 uint8 * wasm_file_buf = NULL;
112
+ Target 0: (iwasm) stopped.
113
+ (lldb) c
114
+ Process 27954 resuming
115
+ 1 location added to breakpoint 1
116
+ error: need to add support for DW_TAG_base_type ' void' encoded with DW_ATE = 0x0, bit_size = 0
117
+ Process 27954 stopped
118
+ * thread # 1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
119
+ frame # 0: 0x00000001002980a0 JIT(0x100298004)`main(exenv=0x0000000301808200) at hello.c:6:9
120
+ 3 int
121
+ 4 main(void)
122
+ 5 {
123
+ -> 6 printf(" hello\n" );
124
+ 7
125
+ 8 return 0;
126
+ 9 }
127
+ Target 0: (iwasm) stopped.
128
+ (lldb) br l
129
+ Current breakpoints:
130
+ 1: name = ' main' , locations = 2, resolved = 2, hit count = 2
131
+ 1.1: where = iwasm` main + 48 at main.c:294:11, address = 0x0000000100001020, resolved, hit count = 1
132
+ 1.2: where = JIT(0x100298004)` main + 12 at hello.c:6:9, address = 0x00000001002980a0, resolved, hit count = 1
133
+
134
+ (lldb)
135
+ ` ` `
136
+
137
+ * In the above example,
138
+
139
+ * The first ` main` function, which is in ` main.c` , is the main
140
+ function of the iwasm command.
141
+
142
+ * The second ` main` function, which is in ` hello.c` , is the main
143
+ function of the AOT-compiled wasm module.
144
+
145
+ * WAMR AOT debugging uses the GDB JIT loader mechanism to load
146
+ the debug info of the debugee module.
147
+ On some platforms including macOS, you need to enable it explicitly.
148
+ (` settings set plugin.jit-loader.gdb.enable on` )
149
+
150
+ References:
151
+
152
+ * https://github.com/llvm/llvm-project/blob/main/llvm/docs/DebuggingJITedCode.rst
153
+ * https://sourceware.org/gdb/current/onlinedocs/gdb/JIT-Interface.html
94
154
95
155
# # Enable debugging in embedders (for interpreter)
96
156
0 commit comments