]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdbserver/README
elf: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX
[thirdparty/binutils-gdb.git] / gdbserver / README
CommitLineData
c906108c
SS
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
c00094dc
SM
8host. GDB and GDBserver communicate using the standard remote serial protocol.
9They communicate via either a serial line or a TCP connection.
c906108c 10
c00094dc
SM
11For more information about GDBserver, see the GDB manual:
12
13 https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html
2d717e4f 14
c906108c
SS
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
1915ef4f
PA
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
c906108c
SS
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
c00094dc
SM
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.
c906108c 49
1915ef4f 50On some targets, GDBserver can also attach to running programs. This is
84563040
DJ
51accomplished via the --attach argument. The syntax is:
52
2d717e4f 53 target> gdbserver --attach COMM PID
84563040
DJ
54
55PID is the process ID of a currently running process. It isn't necessary
1915ef4f 56to point GDBserver at a binary for the running process.
84563040 57
c906108c
SS
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
1915ef4f
PA
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'
c906108c
SS
78command, otherwise you may get an error that looks something like
79`Connection refused'.
80
1915ef4f 81Building GDBserver:
84563040 82
c00094dc
SM
83See the `configure.srv` file for the list of host triplets you can build
84GDBserver for.
c906108c 85
919adfe8
TT
86Building GDBserver for your host is very straightforward. If you build
87GDB natively on a host which GDBserver supports, it will be built
1915ef4f 88automatically when you build GDB. You can also build just GDBserver:
c906108c 89
84563040
DJ
90 % mkdir obj
91 % cd obj
919adfe8
TT
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.)
c906108c 98
84563040 99If you prefer to cross-compile to your target, then you can also build
c00094dc 100GDBserver that way. For example:
c906108c 101
84563040 102 % export CC=your-cross-compiler
c00094dc
SM
103 % path-to-topevel-sources/configure --disable-gdb
104 % make all-gdbserver
c906108c
SS
105
106Using GDBreplay:
107
1915ef4f
PA
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
c906108c 110initiate a remote debug session, use "set remotelogfile <filename>" to tell
1915ef4f
PA
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,
c906108c
SS
113regardless of whether the original session was via a serial link or tcp.
114
1915ef4f
PA
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):
c906108c
SS
118
119 $ gdbreplay logfile host:port
120
1915ef4f
PA
121Then start GDB (preferably in a different screen or window) and use the
122"target" command to connect to GDBreplay:
c906108c
SS
123
124 (gdb) target remote host:port
125
1915ef4f
PA
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
c906108c 132sync with the original session.