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