Commit | Line | Data |
---|---|---|
c906108c SS |
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 | |
c00094dc SM |
8 | host. GDB and GDBserver communicate using the standard remote serial protocol. |
9 | They communicate via either a serial line or a TCP connection. | |
c906108c | 10 | |
c00094dc SM |
11 | For more information about GDBserver, see the GDB manual: |
12 | ||
13 | https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html | |
2d717e4f | 14 | |
c906108c SS |
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 | ||
1915ef4f PA |
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 | |
c906108c SS |
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 | |
c00094dc SM |
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. | |
c906108c | 49 | |
1915ef4f | 50 | On some targets, GDBserver can also attach to running programs. This is |
84563040 DJ |
51 | accomplished via the --attach argument. The syntax is: |
52 | ||
2d717e4f | 53 | target> gdbserver --attach COMM PID |
84563040 DJ |
54 | |
55 | PID is the process ID of a currently running process. It isn't necessary | |
1915ef4f | 56 | to point GDBserver at a binary for the running process. |
84563040 | 57 | |
c906108c SS |
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 | |
1915ef4f PA |
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' | |
c906108c SS |
78 | command, otherwise you may get an error that looks something like |
79 | `Connection refused'. | |
80 | ||
1915ef4f | 81 | Building GDBserver: |
84563040 | 82 | |
c00094dc SM |
83 | See the `configure.srv` file for the list of host triplets you can build |
84 | GDBserver for. | |
c906108c | 85 | |
919adfe8 TT |
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 | |
1915ef4f | 88 | automatically 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 | |
96 | disable other directories when configuring, e.g., binutils, gas, gold, | |
97 | gprof, and ld.) | |
c906108c | 98 | |
84563040 | 99 | If you prefer to cross-compile to your target, then you can also build |
c00094dc | 100 | GDBserver 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 | |
106 | Using GDBreplay: | |
107 | ||
1915ef4f PA |
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 | |
c906108c | 110 | initiate a remote debug session, use "set remotelogfile <filename>" to tell |
1915ef4f PA |
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, | |
c906108c SS |
113 | regardless of whether the original session was via a serial link or tcp. |
114 | ||
1915ef4f PA |
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): | |
c906108c SS |
118 | |
119 | $ gdbreplay logfile host:port | |
120 | ||
1915ef4f PA |
121 | Then 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 |
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 | |
c906108c | 132 | sync with the original session. |