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