GDBSERVER(1)
π 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 upgdbserverprior to using thetarget remotecommand, otherwise you may get an error that looks something likeConnection 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β causesgdbserverto print its version number and exit.--attachβgdbserverwill 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 givenfilename. 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,gdbserverkeeps the listening TCP port open, so that additional connections are possible. however, if you start"gdbserver"with the--onceoption, 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 thegdbservercommand line will have any special shell characters escaped bygdbserver. this ensures that whengdbserverinvokes the inferior, the arguments passed to the inferior are identical to the arguments passed togdbserver.
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 π
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
- arch rolling: gdb 18.1-1 Β· GPL-3.0-or-later AND LGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms