GDBSERVER(1)

πŸ“¦ version 18.1, in arch rolling

πŸ‘‘ GDBSERVER(1) β€” the remote server for the GNU Debugger, bestie edition

okay so real quick β€” this is a page from GNU Development Tools, and it's literally the whole gdbserver manual but make it make sense. buckle up πŸ’–

✨ SYNOPSIS ✨

gdbserver comm prog [args...]

gdbserver --attach comm pid

gdbserver --multi comm

that's the whole vibe in three lines. slay.

πŸ’… DESCRIPTION πŸ’…

so gdbserver is this iconic little program that lets you run GDB on a different machine than the one actually running the program you're debugging. yes, two machines. main character energy on both ends fr fr πŸ¦‹

🌸 Usage (server / target side) 🌸

first things first: you need a copy of the program you wanna debug sitting on the target system. and no, it does NOT need symbols β€” you can strip it to save space if you're tight on room, because gdbserver doesn't care about symbols at all. all the symbol handling? that's GDB's job, on the host system. πŸŽ€

to use the server, you log on to the target system and run the gdbserver program. you gotta tell it three things, no cap:

  • (a) how to communicate with GDB,
  • (b) the name of your program,
  • (c) its arguments.

the general syntax is:

target> gdbserver <comm> <program> [<args> ...]

for example, using a serial port, you might say:

target> gdbserver /dev/com1 emacs foo.txt

which tells gdbserver to debug emacs with an argument of foo.txt, and to talk to GDB via /dev/com1. then gdbserver just waits patiently for the host GDB to hit it up. 🫢

to use a TCP connection instead, you could say:

target> gdbserver host:2345 emacs foo.txt

pretty much the same thing as the last example, except now we're communicating with the "host" GDB over TCP. the host:2345 argument means we're expecting a TCP connection from host to local TCP port 2345. (currently, the host part is ignored β€” lowkey iconic.) you can pick any port number you want as long as it doesn't conflict with any existing TCP ports on the target system. that same port number has to be used in the host GDB's target remote command, which we'll get to in a sec. and heads up: if you pick a port that conflicts with another service, gdbserver will print an error message and exit. πŸ’€

gdbserver can also attach to running programs β€” that's what the --attach argument is for. syntax:

target> gdbserver --attach <comm> <pid>

pid is the process ID of a currently running process. and ngl, you do NOT need to point gdbserver at a binary for the running process. convenient much?

to start gdbserver without supplying an initial command to run or a process ID to attach, use the --multi command line option. in that case you should connect using target extended-remote to start the program you wanna debug:

target> gdbserver --multi <comm>

πŸ¦‹ Usage (host side) πŸ¦‹

okay so on the host side, you need an unstripped copy of the target program, because GDB needs to examine its symbol tables and such. start up GDB like you normally would, with the target program as the first argument. (you may need to use the --baud option if the serial line is running at anything except 9600 baud.) so like, gdb TARGET-PROG, or gdb --baud BAUD TARGET-PROG. πŸ’«

after that, the only new command you need to know about is target remote (or target extended-remote). its argument is either a device name (usually a serial device, like /dev/ttyb), or a HOST:PORT descriptor. for example:

(gdb) target remote /dev/ttyb

communicates with the server via serial line /dev/ttyb, and:

(gdb) target remote the-target:2345

communicates via a TCP connection to port 2345 on host the-target, where you previously started up gdbserver with the same port number. ⭐

⚠️ note that for TCP connections, you MUST start up gdbserver prior to using the target remote command, otherwise you may get an error that looks something like Connection refused. ask me how I know 😭

gdbserver can also debug multiple inferiors at once β€” that's described in the GDB manual in node "Inferiors Connections and Programs", and the shell command for it is info -f gdb -n 'Inferiors Connections and Programs'. in such case, use the extended-remote GDB command variant:

(gdb) target extended-remote the-target:2345

the gdbserver option --multi may or may not be used in such case. your call, bestie. πŸ’…


πŸ”₯ OPTIONS πŸ”₯

there are three different modes for invoking gdbserver:

  • debug a specific program specified by its program name:
gdbserver <comm> <prog> [<args>...]

the comm parameter specifies how the server should communicate with GDB; it's either a device name (to use a serial line), a TCP port number (":1234"), or "-" or "stdio" to use stdin/stdout of "gdbserver". specify the name of the program to debug in prog. any remaining arguments get passed to the program verbatim. when the program exits, GDB will close the connection, and "gdbserver" will exit. πŸŽ€

  • debug a specific program by specifying the process ID of a running program:
gdbserver --attach <comm> <pid>

the comm parameter is as described above. supply the process ID of a running program in pid; GDB will do everything else. like with the previous mode, when the process pid exits, GDB will close the connection, and "gdbserver" will exit. 🫢

  • multi-process mode β€” debug more than one program/process:
gdbserver --multi <comm>

in this mode, GDB can instruct gdbserver which command(s) to run. unlike the other 2 modes, GDB will not close the connection when a process being debugged exits, so you can debug several processes in the same session. obsessed. 🌈

in each of the modes you may specify these options:

  • --help β€” lists all options, with brief explanations.
  • --version β€” causes gdbserver to print its version number and exit.
  • --attach β€” gdbserver will attach to a running program. the syntax is:
target> gdbserver --attach <comm> <pid>

pid is the process ID of a currently running process. it isn't necessary to point gdbserver at a binary for the running process.

  • --multi β€” to start "gdbserver" without supplying an initial command to run or process ID to attach, use this command line option. then you can connect using "target extended-remote" and start the program you wanna debug. the syntax is:
target> gdbserver --multi <comm>
  • --debug[=option1,option2,...] β€” instruct "gdbserver" to display extra status information about the debugging process. this option is intended for "gdbserver" development and for bug reports to the developers. please note I said developers β€” this is not a casual little toggle, it's for the ppl who build this thing. πŸ™ˆ

each option is the name of a component for which debugging should be enabled. the list of possible options is all, threads, event-loop, remote. the special option all enables all components. the option list is processed left to right, and an option can be prefixed with the "-" character to disable output for that component, so you could write:

target> gdbserver --debug=all,-event-loop

to turn on debug output for all components except event-loop. if no options are passed to --debug then this is treated as equivalent to --debug=threads. this could change in future releases of "gdbserver". πŸ”₯

  • --debug-file=filename β€” instruct "gdbserver" to send any debug output to the given filename. this option is intended for "gdbserver" development and for bug reports to the developers.
  • --debug-format=option1[,option2,...] β€” instruct "gdbserver" to include extra information in each line of debugging output.
  • --wrapper β€” specify a wrapper to launch programs for debugging. the option should be followed by the name of the wrapper, then any command-line arguments to pass to the wrapper, then "--" indicating the end of the wrapper arguments.
  • --once β€” by default, gdbserver keeps the listening TCP port open, so that additional connections are possible. however, if you start "gdbserver" with the --once option, it will stop listening for any further connection attempts after connecting to the first GDB session. one and done, literally. ✨
  • --no-escape-args β€” by default, inferior arguments passed on the gdbserver command line will have any special shell characters escaped by gdbserver. this ensures that when gdbserver invokes the inferior, the arguments passed to the inferior are identical to the arguments passed to gdbserver.

to disable this escaping, use --no-escape-args. with this option special shell characters will not be escaped. when gdbserver starts a new shell in order to invoke the inferior, this new shell will expand any special shell characters. 🐚


🌸 ENVIRONMENT 🌸

okay so there's literally nothing listed here β€” this section is empty in the original. no environment variables, no cap. consider this a vibe check that passed with zero notes. πŸ’œ


πŸŽ€ SEE ALSO πŸŽ€

the full documentation for GDB is maintained as a Texinfo manual. if the "info" and "gdb" programs and GDB's Texinfo documentation are properly installed at your site, the command

info gdb

should give you access to the complete manual. πŸ¦‹

Using GDB: A Guide to the GNU Source-Level Debugger, Richard M. Stallman and Roland H. Pesch, July 1991. yes that's the real citation, iconic duo fr fr.


Copyright (c) 1988-2026 Free Software Foundation, Inc.

permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Free Software" and "Free Software Needs Free Documentation", with the Front-Cover Texts being "A GNU Manual," and with the Back-Cover Texts as in (a) below.

(a) the FSF's Back-Cover Text is: "You are free to copy and modify this GNU Manual. Buying copies from GNU Press supports the FSF in developing GNU and promoting software freedom."


and that's the whole page bestie!! this edition was brought to you by gdb-18.1, dated 2026-09-25 β€” go debug something iconic, and remember: start gdbserver BEFORE target remote. mwah πŸŽ€πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from