]> sourceware.org Git - binutils-gdb.git/blob - gdbserver/README
gdb/testsuite: Add libc_has_debug_info require helper
[binutils-gdb.git] / gdbserver / README
1 README for GDBserver & GDBreplay
2 by Stu Grossman and Fred Fish
3
4 Introduction:
5
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.
10
11 For more information about GDBserver, see the GDB manual:
12
13 https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html
14
15 Usage (server (target) side):
16
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.
21
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:
25
26 target> gdbserver COMM PROGRAM [ARGS ...]
27
28 For example, using a serial port, you might say:
29
30 target> gdbserver /dev/com1 emacs foo.txt
31
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.
35
36 To use a TCP connection, you could say:
37
38 target> gdbserver host:2345 emacs foo.txt
39
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
48 message and exit.
49
50 On some targets, GDBserver can also attach to running programs. This is
51 accomplished via the --attach argument. The syntax is:
52
53 target> gdbserver --attach COMM PID
54
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.
57
58 Usage (host side):
59
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:
68
69 (gdb) target remote /dev/ttyb
70
71 communicates with the server via serial line /dev/ttyb, and:
72
73 (gdb) target remote the-target:2345
74
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
79 `Connection refused'.
80
81 Building GDBserver:
82
83 See the `configure.srv` file for the list of host triplets you can build
84 GDBserver for.
85
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:
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
96 disable other directories when configuring, e.g., binutils, gas, gold,
97 gprof, and ld.)
98
99 If you prefer to cross-compile to your target, then you can also build
100 GDBserver that way. For example:
101
102 % export CC=your-cross-compiler
103 % path-to-topevel-sources/configure --disable-gdb
104 % make all-gdbserver
105
106 Using GDBreplay:
107
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.
114
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):
118
119 $ gdbreplay logfile host:port
120
121 Then 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
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. Note
129 that GDBreplay echos the command lines to stderr, as well as the contents of
130 the packets it sends and receives. The last command echoed by GDBreplay is
131 the next command that needs to be typed to GDB to continue the session in
132 sync with the original session.
This page took 0.04439 seconds and 6 git commands to generate.