Files
clang-p2996/lldb/tools/lldb-vscode/Options.td
Walter Erquinigo 0f0462cacf [vscode] Improve runInTerminal and support linux
Depends on D93874.

runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:

- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere

As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:

- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.

Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.

The existing test which didn't pass on Linux, now passes.

Differential Revision: https://reviews.llvm.org/D93951
2021-01-25 12:30:05 -08:00

37 lines
1.2 KiB
TableGen

include "llvm/Option/OptParser.td"
class F<string name>: Flag<["--", "-"], name>;
class S<string name>: Separate<["--", "-"], name>;
class R<list<string> prefixes, string name>
: Option<prefixes, name, KIND_REMAINING_ARGS>;
def help: F<"help">,
HelpText<"Prints out the usage information for the LLDB VSCode tool.">;
def: Flag<["-"], "h">,
Alias<help>,
HelpText<"Alias for --help">;
def wait_for_debugger: F<"wait-for-debugger">,
HelpText<"Pause the program at startup.">;
def: Flag<["-"], "g">,
Alias<wait_for_debugger>,
HelpText<"Alias for --wait-for-debugger">;
def port: Separate<["--", "-"], "port">,
MetaVarName<"<port>">,
HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
def: Separate<["-"], "p">,
Alias<port>,
HelpText<"Alias for --port">;
def launch_target: Separate<["--", "-"], "launch-target">,
MetaVarName<"<target>">,
HelpText<"Launch a target for the launchInTerminal request. Any argument "
"provided after this one will be passed to the target. The parameter "
"--comm-files-prefix must also be specified.">;
def comm_file: Separate<["--", "-"], "comm-file">,
MetaVarName<"<file>">,
HelpText<"The fifo file used to communicate the with the debug adaptor"
"when using --launch-target.">;