1 /* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 int old_thread_from_wait
;
27 int extended_protocol
;
32 start_inferior (char *argv
[], char *statusptr
)
34 inferior_pid
= create_inferior (argv
[0], argv
);
35 fprintf (stderr
, "Process %s created; pid = %d\n", argv
[0], inferior_pid
);
37 /* Wait till we are at 1st instruction in program, return signal number. */
38 return mywait (statusptr
);
41 extern int remote_debug
;
44 main (int argc
, char *argv
[])
46 char ch
, status
, own_buf
[PBUFSIZ
], mem_buf
[2000];
52 if (setjmp (toplevel
))
54 fprintf (stderr
, "Exiting\n");
59 error ("Usage: gdbserver tty prog [args ...]");
63 /* Wait till we are at first instruction in program. */
64 signal
= start_inferior (&argv
[2], &status
);
66 /* We are now stopped at the first instruction of the target process */
70 remote_open (argv
[1]);
74 while (getpkt (own_buf
) > 0)
82 remote_debug
= !remote_debug
;
85 extended_protocol
= 1;
86 prepare_resume_reply (own_buf
, status
, signal
);
89 prepare_resume_reply (own_buf
, status
, signal
);
95 general_thread
= strtol (&own_buf
[2], NULL
, 16);
97 fetch_inferior_registers (0);
100 cont_thread
= strtol (&own_buf
[2], NULL
, 16);
104 /* Silently ignore it so that gdb can extend the protocol
105 without compatibility headaches. */
111 convert_int_to_ascii (registers
, own_buf
, REGISTER_BYTES
);
114 convert_ascii_to_int (&own_buf
[1], registers
, REGISTER_BYTES
);
115 store_inferior_registers (-1);
119 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
120 read_inferior_memory (mem_addr
, mem_buf
, len
);
121 convert_int_to_ascii (mem_buf
, own_buf
, len
);
124 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
125 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
131 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
133 signal
= mywait (&status
);
134 prepare_resume_reply (own_buf
, status
, signal
);
137 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
139 signal
= mywait (&status
);
140 prepare_resume_reply (own_buf
, status
, signal
);
144 signal
= mywait (&status
);
145 prepare_resume_reply (own_buf
, status
, signal
);
149 signal
= mywait (&status
);
150 prepare_resume_reply (own_buf
, status
, signal
);
153 fprintf (stderr
, "Killing inferior\n");
155 /* When using the extended protocol, we start up a new
156 debugging session. The traditional protocol will
158 if (extended_protocol
)
161 fprintf (stderr
, "GDBserver restarting\n");
163 /* Wait till we are at 1st instruction in prog. */
164 signal
= start_inferior (&argv
[2], &status
);
174 if (mythread_alive (strtol (&own_buf
[1], NULL
, 16)))
180 /* Restarting the inferior is only supported in the
181 extended protocol. */
182 if (extended_protocol
)
186 fprintf (stderr
, "GDBserver restarting\n");
188 /* Wait till we are at 1st instruction in prog. */
189 signal
= start_inferior (&argv
[2], &status
);
195 /* It is a request we don't understand. Respond with an
196 empty packet so that gdb knows that we don't support this
202 /* It is a request we don't understand. Respond with an
203 empty packet so that gdb knows that we don't support this
213 "\nChild exited with status %d\n", sig
);
215 fprintf (stderr
, "\nChild terminated with signal = 0x%x\n", sig
);
216 if (status
== 'W' || status
== 'X')
218 if (extended_protocol
)
220 fprintf (stderr
, "Killing inferior\n");
223 fprintf (stderr
, "GDBserver restarting\n");
225 /* Wait till we are at 1st instruction in prog. */
226 signal
= start_inferior (&argv
[2], &status
);
232 fprintf (stderr
, "GDBserver exiting\n");
238 /* We come here when getpkt fails.
240 For the extended remote protocol we exit (and this is the only
241 way we gracefully exit!).
243 For the traditional remote protocol close the connection,
244 and re-open it at the top of the loop. */
245 if (extended_protocol
)
252 fprintf (stderr
, "Remote side has terminated connection. GDBserver will reopen the connection.\n");
This page took 0.033893 seconds and 4 git commands to generate.