1 README for GDBserver & GDBreplay
2 by Stu Grossman and Fred Fish
6 This is GDBserver, a remote server for Un*x-like systems. It can be used to
7 control the execution of a program on a target system from a GDB on a different
8 host. GDB and GDBserver communicate using the standard remote serial protocol.
9 They communicate via either a serial line or a TCP connection.
11 For more information about GDBserver, see the GDB manual:
13 https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html
15 Usage (server (target) side):
17 First, you need to have a copy of the program you want to debug put onto
18 the target system. The program can be stripped to save space if needed, as
19 GDBserver doesn't care about symbols. All symbol handling is taken care of by
20 the GDB running on the host system.
22 To use the server, you log on to the target system, and run the `gdbserver'
23 program. You must tell it (a) how to communicate with GDB, (b) the name of
24 your program, and (c) its arguments. The general syntax is:
26 target> gdbserver COMM PROGRAM [ARGS ...]
28 For example, using a serial port, you might say:
30 target> gdbserver /dev/com1 emacs foo.txt
32 This tells GDBserver to debug emacs with an argument of foo.txt, and to
33 communicate with GDB via /dev/com1. GDBserver now waits patiently for the
34 host GDB to communicate with it.
36 To use a TCP connection, you could say:
38 target> gdbserver host:2345 emacs foo.txt
40 This says pretty much the same thing as the last example, except that we are
41 going to communicate with the host GDB via TCP. The `host:2345' argument means
42 that we are expecting to see a TCP connection to local TCP port 2345.
43 (Currently, the `host' part is ignored.) You can choose any number you want for
44 the port number as long as it does not conflict with any existing TCP ports on
45 the target system. This same port number must be used in the host GDB's
46 `target remote' command, which will be described shortly. Note that if you chose
47 a port number that conflicts with another service, GDBserver will print an error
50 On some targets, GDBserver can also attach to running programs. This is
51 accomplished via the --attach argument. The syntax is:
53 target> gdbserver --attach COMM PID
55 PID is the process ID of a currently running process. It isn't necessary
56 to point GDBserver at a binary for the running process.
60 You need an unstripped copy of the target program on your host system, since
61 GDB needs to examine it's symbol tables and such. Start up GDB as you normally
62 would, with the target program as the first argument. (You may need to use the
63 --baud option if the serial line is running at anything except 9600 baud.)
64 Ie: `gdb TARGET-PROG', or `gdb --baud BAUD TARGET-PROG'. After that, the only
65 new command you need to know about is `target remote'. It's argument is either
66 a device name (usually a serial device, like `/dev/ttyb'), or a HOST:PORT
67 descriptor. For example:
69 (gdb) target remote /dev/ttyb
71 communicates with the server via serial line /dev/ttyb, and:
73 (gdb) target remote the-target:2345
75 communicates via a TCP connection to port 2345 on host `the-target', where
76 you previously started up GDBserver with the same port number. Note that for
77 TCP connections, you must start up GDBserver prior to using the `target remote'
78 command, otherwise you may get an error that looks something like
83 See the `configure.srv` file for the list of host triplets you can build
86 Building GDBserver for your host is very straightforward. If you build
87 GDB natively on a host which GDBserver supports, it will be built
88 automatically when you build GDB. You can also build just GDBserver:
92 % path-to-toplevel-sources/configure --disable-gdb
95 (If you have a combined binutils+gdb tree, you may want to also
96 disable other directories when configuring, e.g., binutils, gas, gold,
99 If you prefer to cross-compile to your target, then you can also build
100 GDBserver that way. For example:
102 % export CC=your-cross-compiler
103 % path-to-topevel-sources/configure --disable-gdb
108 A special hacked down version of GDBserver can be used to replay remote
109 debug log files created by GDB. Before using the GDB "target" command to
110 initiate a remote debug session, use "set remotelogfile <filename>" to tell
111 GDB that you want to make a recording of the serial or tcp session. Note
112 that when replaying the session, GDB communicates with GDBreplay via tcp,
113 regardless of whether the original session was via a serial link or tcp.
115 Once you are done with the remote debug session, start GDBreplay and
116 tell it the name of the log file and the host and port number that GDB
117 should connect to (typically the same as the host running GDB):
119 $ gdbreplay logfile host:port
121 Then start GDB (preferably in a different screen or window) and use the
122 "target" command to connect to GDBreplay:
124 (gdb) target remote host:port
126 Repeat the same sequence of user commands to GDB that you gave in the
127 original debug session. GDB should not be able to tell that it is talking
128 to GDBreplay rather than a real target, all other things being equal.
130 As GDBreplay communicates with GDB, it outputs only the commands
131 it expects from GDB. The --debug-logging option turns printing the
132 remotelogfile to stderr on. GDBreplay then echos the command lines
133 to stderr, as well as the contents of the packets it sends and receives.