After #185537, `lldb-server` would crash with an assertion because it
calls`exit()` instead of returning from `main`. This means that we never
get an opportunity to call `Terminate` before the static
`SystemLifetimeManager` is destroyed.
I could've created a static RAII object to wrap this in (similar to what
Aiden did in #186133) but that's not necessary. I updated the helper
functions to return an `llvm::Error` while `main_gdbserver` and
`main_platform` now return an `int`.
Fixes#186207
* original change #162730
* with windows fix#164843
* remove timeout that was pointed out in the comment above
* Remove test that starts and listens on a socket to avoid timeout
issues
Fix windows test failures from
https://github.com/llvm/llvm-project/pull/162730 by including and
optional .exe on the lldb-server name. Still passes on linux, but should
pass on windows now.
```
> bin/llvm-lit -v tools/lldb/test/Shell/lldb-server/
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using clang: llvm-project/build/bin/clang
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld.lld: /usr/bin/ld.lld
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using lld-link: /usr/bin/lld-link
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using ld64.lld: /usr/bin/ld64.lld
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/config.py:531: note: using wasm-ld: /usr/bin/wasm-ld
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did not find obj2yaml in llvm-project/build/./bin:llvm-project/build/./bin
llvm-lit: llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did not find llvm-objdump in llvm-project/build/./bin:llvm-project/build/./bin
llvm-lit: llvm-project/lldb/test/Shell/lit.cfg.py:125: warning: Could not set a default per-test timeout. Requires the Python psutil module but it could not be found. Try installing it via pip or via your operating system's package manager.
-- Testing: 4 tests, 4 workers --
PASS: lldb-shell :: lldb-server/TestGdbserverErrorMessages.test (1 of 4)
PASS: lldb-shell :: lldb-server/TestPlatformHelp.test (2 of 4)
PASS: lldb-shell :: lldb-server/TestPlatformErrorMessages.test (3 of 4)
PASS: lldb-shell :: lldb-server/TestPlatformSuccessfulStartup.test (4 of 4)
Testing Time: 1.10s
Total Discovered Tests: 4
Passed: 4 (100.00%)
1 warning(s) in tests
```
The lldb-server platform help text is inconsistent with lldb-server
gdbserver help text. This PR modernizes the platform server to use
LLVM's [TableGen](https://llvm.org/docs/TableGen/)-based option parsing
(matching the existing gdbserver implementation), which auto-generates
option parsing code and help text.
The changes improve documentation quality by adding comprehensive option
descriptions,, adding support for `-h`/`--help` flags, and organizing
help output with DESCRIPTION and EXAMPLES sections. Internal-only
options (`--child-platform-fd`) and unused legacy options (`--debug`,
`--verbose`) are now hidden from help while maintaining backward
compatibility. All functional behavior remains unchanged—this is purely
a documentation and code modernization improvement.
## before
```
> /opt/llvm/bin/lldb-server p -h
p: unrecognized option '-h'
Usage:
/opt/llvm/bin/lldb-server p [--log-file log-file-name] [--log-channels log-channel-list] [--port-file port-file-path] --server --listen port
```
## after
```
lldb-server p -h
OVERVIEW: lldb-server platform
USAGE: lldb-server p [options] --listen <[host]:port> [[--] program args...]
CONNECTION OPTIONS:
--gdbserver-port <port> Port to use for spawned gdbserver instances. If 0 or unspecified, a port will be chosen automatically. Short form: -P
--listen <[host]:port> Host and port to listen on. Format: [host]:port or protocol://[host]:port (e.g., tcp://localhost:1234, unix:///path/to/socket). Short form: -L
--socket-file <path> Write listening socket information (port number for TCP or path for Unix domain sockets) to the specified file. Short form: -f
GENERAL OPTIONS:
--help Display this help message and exit.
--log-channels <channel1 categories...:channel2 categories...>
Channels to log. A colon-separated list of entries. Each entry starts with a channel followed by a space-separated list of categories. Common channels: lldb, gdb-remote, platform, process. Short form: -c
--log-file <file> Destination file to log to. If empty, log to stderr. Short form: -l
--server Run in server mode, accepting multiple client connections sequentially. Without this flag, the server exits after handling the first connection.
OPTIONS:
-- program args Arguments to pass to launched gdbserver instances.
DESCRIPTION
Acts as a platform server for remote debugging. When LLDB clients connect,
the platform server handles platform operations (file transfers, process
launching) and spawns debug server instances (lldb-server gdbserver) to
handle actual debugging sessions.
By default, the server exits after handling one connection. Use --server
to keep running and accept multiple connections sequentially.
EXAMPLES
# Listen on port 1234, exit after first connection
lldb-server platform --listen tcp://0.0.0.0:1234
# Listen on port 5555, accept multiple connections
lldb-server platform --server --listen tcp://localhost:5555
# Listen on Unix domain socket
lldb-server platform --listen unix:///tmp/lldb-server.sock
```
For comparison, here is the **gdbserver** help text:
```
lldb-server g -h
OVERVIEW: lldb-server
USAGE: lldb-server g[dbserver] [options] [[host]:port] [[--] program args...]
CONNECTION:
--fd <fd> Communicate over the given file descriptor.
--named-pipe <name> Write port lldb-server will listen on to the given named pipe.
--pipe <fd> Write port lldb-server will listen on to the given file descriptor.
--reverse-connect Connect to the client instead of passively waiting for a connection. In this case [host]:port denotes the remote address to connect to.
GENERAL OPTIONS:
--help Prints out the usage information for lldb-server.
--log-channels <channel1 categories...:channel2 categories...>
Channels to log. A colon-separated list of entries. Each entry starts with a channel followed by a space-separated list of categories.
--log-file <file> Destination file to log to. If empty, log to stderr.
--setsid Run lldb-server in a new session.
TARGET SELECTION:
--attach <pid-or-name> Attach to the process given by a (numeric) process id or a name.
-- program args Launch program for debugging.
DESCRIPTION
lldb-server connects to the LLDB client, which drives the debugging session.
If no connection options are given, the [host]:port argument must be present
and will denote the address that lldb-server will listen on. [host] defaults
to "localhost" if empty. Port can be zero, in which case the port number will
be chosen dynamically and written to destinations given by --named-pipe and
--pipe arguments.
If no target is selected at startup, lldb-server can be directed by the LLDB
client to launch or attach to a process.
```