LinuxCommandLibrary

gdbserver

Enable remote debugging

SYNOPSIS

gdbserver [target-spec] PROGRAM [PROGRAM-ARGS...]
gdbserver [--attach PID] [target-spec]
gdbserver COMDEVICE [--attach PID] PROGRAM [PROGRAM-ARGS...]

where target-spec is host:port-number or host or :port-number (TCP) or COMDEVICE (serial).

PARAMETERS

--attach
    Attach to existing process with given PID instead of starting new one

--multi
    Enable multi-mode; listen for multiple connections after first inferior

--once
    Exit after one connection closes (default in single mode)

--wrapper
    Invoke PROGRAM via COMMAND (e.g., for valgrind)

--debug
    Enable debug logging

--debug-file
    Log debug output to specified FILE

--debug-format
    Set debug log format (gnu, csv, json)

-v or --verbose
    Increase verbosity

--version
    Print version information

--help
    Display usage summary


    TCP: host:port or :port; serial: device path


    Serial device (e.g., /dev/ttyS0)

DESCRIPTION

gdbserver is a lightweight daemon from the GNU Debugger (GDB) suite designed for remote debugging. It runs on a target system (e.g., embedded device, remote server, or Android) and allows a GDB instance on a host machine to control and debug programs executing on the target.

Key features include loading executables, setting breakpoints, inspecting memory and registers, stepping through code, and handling multi-threaded applications. Communication occurs over TCP/IP or serial connections, with the target providing raw process control while the host manages symbols and user interface.

Ideal for cross-platform development where installing full GDB on the target is impractical due to space or resource constraints. Common in embedded Linux, kernel modules, and mobile app debugging. It supports attaching to running processes and multi-inferior mode for debugging multiple programs simultaneously.

Security note: gdbserver exposes debugging interfaces; use firewalls and authentication in production.

CAVEATS

Requires ptrace permissions (often root or CAP_SYS_PTRACE); TCP mode insecure without TLS/firewall; no symbol handling on target—inferiors must match host GDB binary/symbols; limited on non-x86 arches.

BASIC TCP EXAMPLE

On target: gdbserver localhost:1234 /path/to/program
On host: gdb then target remote target-host:1234

ATTACH EXAMPLE

On target: gdbserver --attach :1234 1234 (attach PID 1234, listen on TCP 1234)

HISTORY

Developed by GNU Project as part of GDB since version 4.18 (1998); evolved for embedded/remote use, with multi-mode in GDB 7.x; now integral to GDB 14+ for cross-debugging.

SEE ALSO

gdb(1), gcore(1), strace(1), ptrace(2)

Copied to clipboard