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