GDBSERVER(1)
GDBSERVER(1) π β¨
okay bestie so this is a page from the GNU Development Tools manual, and it's about gdbserver, which is genuinely one of the most useful little guys in the whole debugging toolbox. buckle up, we're gonna get you fluent in remote debugging fr fr π«Ά
πΈ NAME πΈ
gdbserver β the Remote Server for the GNU Debugger, aka GDB's long-distance boyfriend π
β¨ SYNOPSIS β¨
gdbserver comm prog [args...]
gdbserver --attach comm pid
gdbserver --multi comm
that's it. three vibes, three ways in. slay π
π¦ DESCRIPTION π¦
so gdbserver is literally the program that lets you run GDB on a completely different machine than the one actually running the program you're debugging. yes. two machines. one debugging session. iykyk π₯
π Usage (server (target) side)
first things first, bestie: you need a copy of the program you wanna debug sitting on the target system. and the good news? it can totally be stripped to save space, because gdbserver does not care about symbols at all. all that symbol handling? handled entirely by the GDB running on the host system. not gdbserver's problem, not gdbserver's business πββοΈ
to actually use the server, you log on to the target system and run the gdbserver program. you gotta tell it three things: (a) how to communicate with GDB, (b) the name of your program, and (c) its arguments. the general syntax is:
target> gdbserver <comm> <program> [<args> ...]
like, 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 communicate with GDB via /dev/com1. and then gdbserver just... waits patiently for the host GDB to communicate with it. iconic waiting behavior honestly β³
wanna use a TCP connection instead? you could say:
target> gdbserver host:2345 emacs foo.txt
which says pretty much the same thing as the last example, except now we're communicating with the host GDB via TCP. the host:2345 argument means we're expecting a TCP connection from host to local TCP port 2345. (and ngl, currently the host part is ignored β yeah, it just sits there being decorative π) you can pick any number you want for the port, as long as it doesn't conflict with 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're getting to in a sec. and heads up: if you pick a port number that conflicts with another service, gdbserver will print an error message and exit. no drama tolerated π
gdbserver can also attach to programs that are already running. this is the --attach argument's whole moment. syntax:
target> gdbserver --attach <comm> <pid>
pid is the process ID of a currently running process. and no, it is not necessary to point gdbserver at a binary for the running process. we love low-maintenance π«Ά
you can also start gdbserver without supplying an initial command to run or a process ID to attach β just use the --multi command line option. in that case you should connect using target extended-remote to start the program you want to debug:
target> gdbserver --multi <comm>
π Usage (host side)
okay now the host side. you need an unstripped copy of the target program on your host system, because GDB genuinely needs to examine its symbol tables and such. (this is the opposite of the target side which doesn't care, so keep track okay π)
start up GDB like you normally would, with the target program as the first argument. (you may need to use the --baud option if your serial line is running at anything other than 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 the 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 that same port number. β οΈ and note this: for TCP connections you must start up gdbserver before using the target remote command, otherwise you may get an error that looks something like Connection refused. order matters bestie, it always does π€
gdbserver can also debug multiple inferiors at once β that's all described in the GDB manual in node "Inferiors Connections and Programs", which you can reach with the shell command 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
and the gdbserver option --multi may or may not be used in such case. it's optional, it's chill, it's giving flexible π
π₯ OPTIONS π₯
okay so there are three different modes for invoking gdbserver. three. that's the whole menu:
- 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. clean. tidy. done. π
- 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. and 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. and 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. the way that it just keeps going ππ
in each of the modes you may specify these options:
--helpβ list all options, with brief explanations. your little map π--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. and again β it isn't necessary to point gdbserver at a binary for the running process. π«Ά
--multiβ to startgdbserverwithout supplying an initial command to run or process ID to attach, use this command line option. then you can connect usingtarget extended-remoteand start the program you want to debug. the syntax is:
target> gdbserver --multi <comm>
--debug[=option1,option2,...]β instructsgdbserverto display extra status information about the debugging process. this option is intended forgdbserverdevelopment and for bug reports to the developers. ngl it's the devs' toy, not yours πΈ
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. and if no options are passed to --debug then this is treated as equivalent to --debug=threads. β οΈ heads up though β this could change in future releases of gdbserver. so like, don't build your whole personality on it π
--debug-file=filenameβ instructsgdbserverto send any debug output to the given filename. this option is intended forgdbserverdevelopment and for bug reports to the developers.--debug-format=option1[,option2,...]β instructsgdbserverto 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. that--is the little velvet rope, don't forget it π--onceβ by default,gdbserverkeeps the listening TCP port open, so that additional connections are possible. however, if you startgdbserverwith the--onceoption, it will stop listening for any further connection attempts after connecting to the first GDB session. one and done. main character energy only π
π§ ENVIRONMENT π§
literally nothing here bestie. this section is empty in the manual. no environment variables for you. it's giving minimalism, it's giving empty nest π
π 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. go read it, it's long but it's worth it π
also on the shelf: Using GDB: A Guide to the GNU Source-Level Debugger, by Richard M. Stallman and Roland H. Pesch, July 1991. vintage. iconic. still cited π
π COPYRIGHT π
Copyright (c) 1988-2025 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."
aaaand that's the whole page, bestie π this one's from the gdb-17.1 era, dated 2025-12-20 β so go forth, debug something remote, and remember: start gdbserver before target remote, or you WILL get Connection refused and i WILL say i told you so π
β¨π¦
π¦ where this page comes from
- arch rolling: sh2-elf-gdb 17.1-2 Β· GPL3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms