[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Sun Sep 8 23:54:16 PDT 2024
https://github.com/labath commented:
I wrote a fairly long comment on Friday, but I don't see it anymore so, it looks like github has swallowed it. Here's my reconstruction of it:
LLDB commands have the notion of a "repeat command", which can sometimes be more complicated than just running the same string over and over again. This can be e.g. seen with the `memory read` command, which doesn't just print the same memory again -- it actually prints the memory that comes *after* it (a pretty nifty feature actually):
```
(lldb) memory read argv
0x7fffffffd8a8: 49 dc ff ff ff 7f 00 00 00 00 00 00 00 00 00 00 I...............
0x7fffffffd8b8: 6c dc ff ff ff 7f 00 00 ae dc ff ff ff 7f 00 00 l...............
(lldb)
0x7fffffffd8c8: c4 dc ff ff ff 7f 00 00 cf dc ff ff ff 7f 00 00 ................
0x7fffffffd8d8: 09 dd ff ff ff 7f 00 00 18 dd ff ff ff 7f 00 00 ................
(lldb)
0x7fffffffd8e8: 40 dd ff ff ff 7f 00 00 7d dd ff ff ff 7f 00 00 @.......}.......
0x7fffffffd8f8: 81 e5 ff ff ff 7f 00 00 9d e5 ff ff ff 7f 00 00 ................
(lldb) memory read argv
0x7fffffffd8a8: 49 dc ff ff ff 7f 00 00 00 00 00 00 00 00 00 00 I...............
0x7fffffffd8b8: 6c dc ff ff ff 7f 00 00 ae dc ff ff ff 7f 00 00 l...............
```
Storing (and repeating) the command string in lldb-dap would break this behavior. What we'd ideally want is to actually take the empty string and pass it to lldb's command interpreter so that the proper repeat logic kicks in.
The thing which makes this tricky (but not too complicated I think) is that lldb-dap multiplexes expression commands and CLI commands into the same string (the `DetectExpressionContext` does the demultiplexing).
I think the proper repeat handling could be two things about each command:
- the type ("expression context") of the command
- the command string itself, if the command was not a CLI command (so we can repeat the expression)
Then, when we get an empty string, we check the type of the previous command:
- if it was a CLI command (`ExpressionContext::Command`), we change send the empty string to lldb command interpreter, so that it does the right thing
- otherwise, we take the expression string and re-evaluate it (like you do here).
https://github.com/llvm/llvm-project/pull/107485
More information about the lldb-commits
mailing list