[lldb] Add a C language REPL to test LLDB's REPL infrastructure
authorRaphael Isemann <teemperor@gmail.com>
Thu, 23 Sep 2021 17:13:50 +0000 (19:13 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 23 Sep 2021 17:31:02 +0000 (19:31 +0200)
commitc22329972f02f9d51e2f9ea54d9075a4a808ffde
tree37ce5ab647484bc17dc9b6dbff72bb874973bd46
parent6bc9c8dfe32cc4662f2ed9041af527f69dfff13b
[lldb] Add a C language REPL to test LLDB's REPL infrastructure

LLDB has a bunch of code that implements REPL support, but all that code is
unreachable as no language in master currently has an implemented REPL backend.
The only REPL that exists is in the downstream Swift fork. All patches for this
generic REPL code therefore also only have tests downstream which is clearly not
a good situation.

This patch implements a basic C language REPL on top of LLDB's REPL framework.
Beside implementing the REPL interface and hooking it up into the plugin
manager, the only other small part of this patch is making the `--language` flag
of the expression command compatible with the `--repl` flag. The `--repl` flag
uses the value of `--language` to see which REPL should be started, but right
now the `--language` flag is only available in OptionGroups 1 and 2, but not in
OptionGroup 3 where the `--repl` flag is declared.

The REPL currently can currently only start if a running target exists. I'll add
the 'create and run a dummy executable' logic from Swift (which is requires when
doing `lldb --repl`) when I have time to translate all this logic to something
that will work with Clang.

I should point out that the REPL currently uses the C expression parser's
approach to persistent variables where only result variables and the ones
starting with a '$' are transferred between expressions. I'll fix that in a
follow up patch. Also the REPL currently doesn't work in a non-interactive
terminal. This seems to be fixed in the Swift fork, so I assume one of our many
REPL downstream changes addresses the issue.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D87281
lldb/source/Commands/Options.td
lldb/source/Plugins/CMakeLists.txt
lldb/source/Plugins/REPL/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/REPL/Clang/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/REPL/Clang/ClangREPL.cpp [new file with mode: 0644]
lldb/source/Plugins/REPL/Clang/ClangREPL.h [new file with mode: 0644]
lldb/test/API/repl/clang/Makefile [new file with mode: 0644]
lldb/test/API/repl/clang/TestClangREPL.py [new file with mode: 0644]
lldb/test/API/repl/clang/main.c [new file with mode: 0644]