Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lldb/test/Shell/lldb-server/TestPlatformErrorMessages.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# UNSUPPORTED: system-windows

RUN: %platformserver 2>&1 | FileCheck --check-prefixes=NO_LISTEN,ALL %s
NO_LISTEN: error: either --listen or --child-platform-fd is required

RUN: %lldb-server platform --listen 2>&1 | FileCheck --check-prefixes=LISTEN_MISSING,ALL %s
LISTEN_MISSING: error: --listen: missing argument

RUN: %lldb-server p --bogus 2>&1 | FileCheck --check-prefixes=BOGUS,ALL %s
BOGUS: error: unknown argument '--bogus'

RUN: %platformserver --gdbserver-port 2>&1 | FileCheck --check-prefixes=GDBPORT_MISSING,ALL %s
GDBPORT_MISSING: error: --gdbserver-port: missing argument

RUN: %platformserver --gdbserver-port notanumber --listen :1234 2>&1 | FileCheck --check-prefixes=GDBPORT_INVALID %s
GDBPORT_INVALID: error: invalid --gdbserver-port value

RUN: %platformserver --socket-file 2>&1 | FileCheck --check-prefixes=SOCKETFILE_MISSING,ALL %s
SOCKETFILE_MISSING: error: --socket-file: missing argument

RUN: %platformserver --log-file 2>&1 | FileCheck --check-prefixes=LOGFILE_MISSING,ALL %s
LOGFILE_MISSING: error: --log-file: missing argument

RUN: %platformserver --log-channels 2>&1 | FileCheck --check-prefixes=LOGCHANNELS_MISSING,ALL %s
LOGCHANNELS_MISSING: error: --log-channels: missing argument

ALL: Use 'lldb-server {{p|platform}} --help' for a complete list of options.
41 changes: 41 additions & 0 deletions lldb/test/Shell/lldb-server/TestPlatformHelp.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# UNSUPPORTED: system-windows

RUN: %platformserver --help 2>&1 | FileCheck %s
RUN: %platformserver -h 2>&1 | FileCheck %s
RUN: %lldb-server p --help 2>&1 | FileCheck %s
RUN: %lldb-server p -h 2>&1 | FileCheck %s
RUN: %lldb-server platform --help 2>&1 | FileCheck %s
RUN: %lldb-server platform -h 2>&1 | FileCheck %s

CHECK: OVERVIEW: lldb-server platform
CHECK: USAGE: lldb-server {{p|platform}} [options] --listen <{{[[]}}host]:port> {{[[]}}[--] program args...]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm what {{ are part of the output and which are some kind of escape character? ISTR FileCheck regex uses {{}} so not sure what is what.


CHECK: CONNECTION OPTIONS:
CHECK: --gdbserver-port <port>
CHECK-SAME: Short form: -P
CHECK: --listen <{{[[]}}host]:port>
CHECK-SAME: Short form: -L
CHECK: --socket-file <path>
CHECK-SAME: Short form: -f

CHECK: GENERAL OPTIONS:
CHECK: --help
CHECK: --log-channels <channel1 categories...:channel2 categories...>
CHECK: Short form: -c
CHECK: --log-file <file>
CHECK-SAME: Short form: -l
CHECK: --server

CHECK: OPTIONS:
CHECK: -- program args

CHECK: DESCRIPTION
CHECK: Acts as a platform server for remote debugging

CHECK: EXAMPLES
CHECK: # Listen on port 1234, exit after first connection
CHECK: lldb-server platform --listen tcp://0.0.0.0:1234
CHECK: # Listen on port 5555, accept multiple connections
CHECK: lldb-server platform --server --listen tcp://localhost:5555
CHECK: # Listen on Unix domain socket
CHECK: lldb-server platform --listen unix:///tmp/lldb-server.sock
37 changes: 37 additions & 0 deletions lldb/test/Shell/lldb-server/TestPlatformSuccessfulStartup.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# UNSUPPORTED: system-windows

# Test successful startup with valid TCP listen address
# The socket file is created immediately when the server is ready to accept connections,
# so we can verify successful startup without arbitrary sleep delays.
RUN: rm -f %t.socket1
RUN: timeout 0.2s %platformserver --listen tcp://127.0.0.1:0 --socket-file %t.socket1 > %t.out1 2>&1 || true
RUN: test -f %t.socket1
RUN: FileCheck --allow-empty --check-prefix=NO-ERROR %s < %t.out1

# Test successful startup with valid gdbserver-port
RUN: rm -f %t.socket3
RUN: timeout 0.2s %platformserver --listen tcp://127.0.0.1:0 --gdbserver-port 0 --socket-file %t.socket3 > %t.out3 2>&1 || true
RUN: test -f %t.socket3
RUN: FileCheck --allow-empty --check-prefix=NO-ERROR %s < %t.out3

# Test successful startup with specific valid gdbserver-port number
RUN: rm -f %t.socket4
RUN: timeout 0.2s %platformserver --listen tcp://127.0.0.1:0 --gdbserver-port 12345 --socket-file %t.socket4 > %t.out4 2>&1 || true
RUN: test -f %t.socket4
RUN: FileCheck --allow-empty --check-prefix=NO-ERROR %s < %t.out4

# Test successful startup with server mode (accepting multiple connections)
RUN: rm -f %t.socket5
RUN: timeout 0.2s %platformserver --server --listen tcp://127.0.0.1:0 --socket-file %t.socket5 > %t.out5 2>&1 || true
RUN: test -f %t.socket5
RUN: FileCheck --allow-empty --check-prefix=NO-ERROR %s < %t.out5

# Test successful startup with abbreviated 'p' command
RUN: rm -f %t.socket6
RUN: timeout 0.2s %lldb-server p --listen tcp://127.0.0.1:0 --socket-file %t.socket6 > %t.out6 2>&1 || true
RUN: test -f %t.socket6
RUN: FileCheck --allow-empty --check-prefix=NO-ERROR %s < %t.out6

# Verify no error or warning messages appear in successful startup
NO-ERROR-NOT: error:
NO-ERROR-NOT: warning:
5 changes: 5 additions & 0 deletions lldb/tools/lldb-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ set(LLVM_TARGET_DEFINITIONS LLGSOptions.td)
tablegen(LLVM LLGSOptions.inc -gen-opt-parser-defs)
add_public_tablegen_target(LLGSOptionsTableGen)

set(LLVM_TARGET_DEFINITIONS PlatformOptions.td)
tablegen(LLVM PlatformOptions.inc -gen-opt-parser-defs)
add_public_tablegen_target(PlatformOptionsTableGen)

set(LLDB_PLUGINS)

if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
Expand Down Expand Up @@ -67,6 +71,7 @@ add_lldb_tool(lldb-server

add_dependencies(lldb-server
LLGSOptionsTableGen
PlatformOptionsTableGen
${tablegen_deps}
)
target_include_directories(lldb-server PRIVATE "${LLDB_SOURCE_DIR}/source")
Expand Down
75 changes: 75 additions & 0 deletions lldb/tools/lldb-server/PlatformOptions.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
include "llvm/Option/OptParser.td"

class F<string name>: Flag<["--", "-"], name>;
class R<list<string> prefixes, string name>
: Option<prefixes, name, KIND_REMAINING_ARGS>;

multiclass SJ<string name, string help> {
def NAME: Separate<["--", "-"], name>,
HelpText<help>;
def NAME # _eq: Joined<["--", "-"], name # "=">,
Alias<!cast<Separate>(NAME)>;
}

def grp_connect : OptionGroup<"connection">, HelpText<"CONNECTION OPTIONS">;

defm listen: SJ<"listen", "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">,
MetaVarName<"<[host]:port>">,
Group<grp_connect>;
def: Separate<["-"], "L">, Alias<listen>,
Group<grp_connect>;

defm socket_file: SJ<"socket-file", "Write listening socket information (port number for TCP or path for Unix domain sockets) to the specified file. Short form: -f">,
MetaVarName<"<path>">,
Group<grp_connect>;
def: Separate<["-"], "f">, Alias<socket_file>,
Group<grp_connect>;

defm gdbserver_port: SJ<"gdbserver-port", "Port to use for spawned gdbserver instances. If 0 or unspecified, a port will be chosen automatically. Short form: -P">,
MetaVarName<"<port>">,
Group<grp_connect>;
def: Separate<["-"], "P">, Alias<gdbserver_port>,
Group<grp_connect>;

defm child_platform_fd: SJ<"child-platform-fd", "File descriptor for communication with parent platform process (internal use only).">,
MetaVarName<"<fd>">,
Group<grp_connect>,
Flags<[HelpHidden]>;

def grp_general : OptionGroup<"general options">, HelpText<"GENERAL OPTIONS">;

def server: F<"server">,
HelpText<"Run in server mode, accepting multiple client connections sequentially. Without this flag, the server exits after handling the first connection.">,
Group<grp_general>;

defm log_channels: SJ<"log-channels", "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">,
MetaVarName<"<channel1 categories...:channel2 categories...>">,
Group<grp_general>;
def: Separate<["-"], "c">, Alias<log_channels>,
Group<grp_general>;

defm log_file: SJ<"log-file", "Destination file to log to. If empty, log to stderr. Short form: -l">,
MetaVarName<"<file>">,
Group<grp_general>;
def: Separate<["-"], "l">, Alias<log_file>,
Group<grp_general>;

def debug: F<"debug">,
HelpText<"(Unused, kept for backward compatibility)">,
Group<grp_general>,
Flags<[HelpHidden]>;

def verbose: F<"verbose">,
HelpText<"(Unused, kept for backward compatibility)">,
Group<grp_general>,
Flags<[HelpHidden]>;

def help: F<"help">,
HelpText<"Display this help message and exit.">,
Group<grp_general>;
def: Flag<["-"], "h">, Alias<help>,
Group<grp_general>;

def REM : R<["--"], "">,
HelpText<"Arguments to pass to launched gdbserver instances.">,
MetaVarName<"program args">;
Loading
Loading