This is an archive of the discontinued LLVM Phabricator instance.

[WIP] Add command interpreter to lldb-vscode
AbandonedPublic

Authored by lanza on May 2 2019, 6:56 PM.

Details

Reviewers
clayborg
xiaobai
Summary

Add a check for a supportsCommandInterpreter option in the
initialize packet for the debug adapter protocol. If this is
supported then we can attack the CommandInterpreter to stdin/stdout
and have the typical lldb command line interface.

Event Timeline

lanza created this revision.May 2 2019, 6:56 PM

It is very dangerous to play with any real STDIN, STDOUT, or STDERR in the lldb-vscode world since this is what is usually the file descriptors used for all the packets.

I would suggest an alternate form for this:

  • in the response to the "initialize" packet, we return a new key/value pair like: "supportsCLI":true
  • if "supportsCLI" was true, then VSCode will create a new terminal window using the master side of a pty (pseudo terminal) and send the slave path down using a new packet:
{"command":"cli","arguments":{"path":"/path/to/slavepty"}}
  • then in lldb-vscode.cpp, we open this file once for read only and once for write only and call:
FILE* in = fopen(pty_slave_path, ...);
FILE* out = fopen(pty_slave_path, ...);
g_vsc.debugger.SetInputFileHandle(in, true);
g_vsc.debugger.SetOutputFileHandle(out, true);
g_vsc.debugger.SetErrorFileHandle(out, false);

And it will be all hooked up without needing to launch with socket? This would only work locally of course, but I believe that the currently proposed solution would only work locally as well right?

actually lldb-vscode is always running locally so my previous concern is no longer valid.

lanza added a comment.May 7 2019, 2:32 PM

So I was looking at something like this, but I don't see a way to access PTYs & VSCode terminal emulators at that level of granularity. The current api (vscode.window.createTerminal) only let's you launch a single process which is automatically attached to the terminal emulator within vscode. There seems to be a proposed API that would offer this control, but it seems that this has been stuck as a proposed API (e.g. not usable for public plugins) for over a year now.

I like the idea of this commit, it seems like we can have lldb-vscode be more useful than just a DAP frontend to lldb.

One thing I noticed is that you are using termios.h a lot, which is not available on windows. I know this is a WIP, but it's something to consider for this patch.

tools/lldb-vscode/lldb-vscode.cpp
476

Could you insert a link to the bug report if it's public?

rmaz added a subscriber: rmaz.Sep 19 2019, 1:41 PM
rmaz added inline comments.
tools/lldb-vscode/lldb-vscode.cpp
810

shouldn't this be g_vsc.command_interpreter_thread.join()?

lanza abandoned this revision.Aug 13 2021, 11:51 AM