llvm / llvm/llvm-project

[lldb] Allow notifying LLDB of a stop from the scripting API

Open
#190,813 8 comments 0 reactions 0 assignees View on GitHub
lldb
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I have been working on supporting the step back feature supported by our wasm runtime/debugger WARDuino in LLDB. Since LLDB does not offer a native step back feature (although some support does exist in the gdb remote code), I am attempting to support it through a plugin.

At first, I thought I would simply send a `bs` back step packet using `process plugin packet send bs`, but when doing this LLDB does not know that the state of the process has actually updated. So I have been doing some trickery so LLDB correctly updates the state by re-using the gdb rsp `s` step command for both stepping forwards and backwards. I first send a custom GDB rsp packet to set the step direction, then step in that direction and I then reset the direction to forwards. This works, but it's a rather ugly work around, additionally for more complex operations this gets increasingly tricky.

```python
ci = debugger.GetCommandInterpreter()
res = lldb.SBCommandReturnObject()

ci.HandleCommand('process plugin packet send "QSetStepDir:1"', res)
debugger.HandleCommand("stepi")
ci.HandleCommand('process plugin packet send "QSetStepDir:0"', res)
```

```
Process 1 stopped
* thread #1, name = 'warduino', stop reason = instruction step into
frame #0: 0x00000117 test-dbg.wasm`_main at test-dbg.c:18:9
15 __attribute__((export_name("main")))
16 void _main() {
17 for (int i = 0; i < 50; i++) {
-> 18 print_int(i);
19 print_int(fib(i));
20 }
21 }
(lldb) si
Process 1 stopped
* thread #1, name = 'warduino', stop reason = instruction step into
frame #0: 0x0000011d test-dbg.wasm`_main at test-dbg.c:19:23
16 void _main() {
17 for (int i = 0; i < 50; i++) {
18 print_int(i);
-> 19 print_int(fib(i));
20 }
21 }
22
(lldb) bs
Process 1 stopped
* thread #1, name = 'warduino', stop reason = instruction step into
frame #0: 0x00000117 test-dbg.wasm`_main at test-dbg.c:18:9
15 __attribute__((export_name("main")))
16 void _main() {
17 for (int i = 0; i < 50; i++) {
-> 18 print_int(i);
19 print_int(fib(i));
20 }
21 }
```

Ideally, I would just send the `bs` packet and then call some function to tell LLDB that the state has changed/the thread has stopped. This way any custom operations affecting the execution could easily be implemented and added through the scripting API without any complicated workarounds. It appears such function currently does not exist (to my knowledge).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.