cdec0f8a93135cd10e0af34e3d6c552db2784998
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, Boston, MA 02111-1307, USA. */
25 int old_thread_from_wait
;
26 int extended_protocol
;
31 start_inferior (argv
, statusptr
)
35 inferior_pid
= create_inferior (argv
[0], argv
);
36 fprintf (stderr
, "Process %s created; pid = %d\n", argv
[0], inferior_pid
);
38 /* Wait till we are at 1st instruction in program, return signal number. */
39 return mywait (statusptr
);
42 extern int remote_debug
;
49 char ch
, status
, own_buf
[2000], mem_buf
[2000];
57 fprintf(stderr
, "Exiting\n");
62 error("Usage: gdbserver tty prog [args ...]");
64 /* Wait till we are at first instruction in program. */
65 signal
= start_inferior (&argv
[2], &status
);
67 /* We are now stopped at the first instruction of the target process */
71 remote_open (argv
[1]);
75 while (getpkt (own_buf
) > 0)
83 remote_debug
= !remote_debug
;
86 extended_protocol
= 1;
87 prepare_resume_reply (own_buf
, status
, signal
);
90 prepare_resume_reply (own_buf
, status
, signal
);
96 general_thread
= strtol (&own_buf
[2], NULL
, 16);
98 fetch_inferior_registers (0);
101 cont_thread
= strtol (&own_buf
[2], NULL
, 16);
105 /* Silently ignore it so that gdb can extend the protocol
106 without compatibility headaches. */
112 convert_int_to_ascii (registers
, own_buf
, REGISTER_BYTES
);
115 convert_ascii_to_int (&own_buf
[1], registers
, REGISTER_BYTES
);
116 store_inferior_registers (-1);
120 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
121 read_inferior_memory (mem_addr
, mem_buf
, len
);
122 convert_int_to_ascii (mem_buf
, own_buf
, len
);
125 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
126 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
132 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
134 signal
= mywait (&status
);
135 prepare_resume_reply (own_buf
, status
, signal
);
138 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
140 signal
= mywait (&status
);
141 prepare_resume_reply (own_buf
, status
, signal
);
145 signal
= mywait (&status
);
146 prepare_resume_reply (own_buf
, status
, signal
);
150 signal
= mywait (&status
);
151 prepare_resume_reply (own_buf
, status
, signal
);
154 fprintf (stderr
, "Killing inferior\n");
156 /* When using the extended protocol, we start up a new
157 debugging session. The traditional protocol will
159 if (extended_protocol
)
162 fprintf (stderr
, "GDBserver restarting\n");
164 /* Wait till we are at 1st instruction in prog. */
165 signal
= start_inferior (&argv
[2], &status
);
175 if (mythread_alive (strtol (&own_buf
[1], NULL
, 16)))
181 /* Restarting the inferior is only supported in the
182 extended protocol. */
183 if (extended_protocol
)
187 fprintf (stderr
, "GDBserver restarting\n");
189 /* Wait till we are at 1st instruction in prog. */
190 signal
= start_inferior (&argv
[2], &status
);
196 /* It is a request we don't understand. Respond with an
197 empty packet so that gdb knows that we don't support this
203 /* It is a request we don't understand. Respond with an
204 empty packet so that gdb knows that we don't support this
214 "\nChild exited with status %d\n", sig
);
216 fprintf (stderr
, "\nChild terminated with signal = 0x%x\n", sig
);
217 if (status
== 'W' || status
== 'X')
219 if (extended_protocol
)
221 fprintf (stderr
, "Killing inferior\n");
224 fprintf (stderr
, "GDBserver restarting\n");
226 /* Wait till we are at 1st instruction in prog. */
227 signal
= start_inferior (&argv
[2], &status
);
233 fprintf (stderr
, "GDBserver exiting\n");
239 /* We come here when getpkt fails.
241 For the extended remote protocol we exit (and this is the only
242 way we gracefully exit!).
244 For the traditional remote protocol close the connection,
245 and re-open it at the top of the loop. */
246 if (extended_protocol
)
253 fprintf (stderr
, "Remote side has terminated connection. GDBserver will reopen the connection.\n");
This page took 0.042941 seconds and 4 git commands to generate.