66afb888efdf81e8349d724d009e49d6aa6fbbf6
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 (argv
, statusptr
)
36 inferior_pid
= create_inferior (argv
[0], argv
);
37 fprintf (stderr
, "Process %s created; pid = %d\n", argv
[0], inferior_pid
);
39 /* Wait till we are at 1st instruction in program, return signal number. */
40 return mywait (statusptr
);
43 extern int remote_debug
;
50 char ch
, status
, own_buf
[2000], mem_buf
[2000];
56 if (setjmp (toplevel
))
58 fprintf (stderr
, "Exiting\n");
63 error ("Usage: gdbserver tty prog [args ...]");
65 /* Wait till we are at first instruction in program. */
66 signal
= start_inferior (&argv
[2], &status
);
68 /* We are now stopped at the first instruction of the target process */
72 remote_open (argv
[1]);
76 while (getpkt (own_buf
) > 0)
84 remote_debug
= !remote_debug
;
87 extended_protocol
= 1;
88 prepare_resume_reply (own_buf
, status
, signal
);
91 prepare_resume_reply (own_buf
, status
, signal
);
97 general_thread
= strtol (&own_buf
[2], NULL
, 16);
99 fetch_inferior_registers (0);
102 cont_thread
= strtol (&own_buf
[2], NULL
, 16);
106 /* Silently ignore it so that gdb can extend the protocol
107 without compatibility headaches. */
113 convert_int_to_ascii (registers
, own_buf
, REGISTER_BYTES
);
116 convert_ascii_to_int (&own_buf
[1], registers
, REGISTER_BYTES
);
117 store_inferior_registers (-1);
121 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
122 read_inferior_memory (mem_addr
, mem_buf
, len
);
123 convert_int_to_ascii (mem_buf
, own_buf
, len
);
126 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
127 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
133 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
135 signal
= mywait (&status
);
136 prepare_resume_reply (own_buf
, status
, signal
);
139 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
141 signal
= mywait (&status
);
142 prepare_resume_reply (own_buf
, status
, signal
);
146 signal
= mywait (&status
);
147 prepare_resume_reply (own_buf
, status
, signal
);
151 signal
= mywait (&status
);
152 prepare_resume_reply (own_buf
, status
, signal
);
155 fprintf (stderr
, "Killing inferior\n");
157 /* When using the extended protocol, we start up a new
158 debugging session. The traditional protocol will
160 if (extended_protocol
)
163 fprintf (stderr
, "GDBserver restarting\n");
165 /* Wait till we are at 1st instruction in prog. */
166 signal
= start_inferior (&argv
[2], &status
);
176 if (mythread_alive (strtol (&own_buf
[1], NULL
, 16)))
182 /* Restarting the inferior is only supported in the
183 extended protocol. */
184 if (extended_protocol
)
188 fprintf (stderr
, "GDBserver restarting\n");
190 /* Wait till we are at 1st instruction in prog. */
191 signal
= start_inferior (&argv
[2], &status
);
197 /* It is a request we don't understand. Respond with an
198 empty packet so that gdb knows that we don't support this
204 /* It is a request we don't understand. Respond with an
205 empty packet so that gdb knows that we don't support this
215 "\nChild exited with status %d\n", sig
);
217 fprintf (stderr
, "\nChild terminated with signal = 0x%x\n", sig
);
218 if (status
== 'W' || status
== 'X')
220 if (extended_protocol
)
222 fprintf (stderr
, "Killing inferior\n");
225 fprintf (stderr
, "GDBserver restarting\n");
227 /* Wait till we are at 1st instruction in prog. */
228 signal
= start_inferior (&argv
[2], &status
);
234 fprintf (stderr
, "GDBserver exiting\n");
240 /* We come here when getpkt fails.
242 For the extended remote protocol we exit (and this is the only
243 way we gracefully exit!).
245 For the traditional remote protocol close the connection,
246 and re-open it at the top of the loop. */
247 if (extended_protocol
)
254 fprintf (stderr
, "Remote side has terminated connection. GDBserver will reopen the connection.\n");
This page took 0.035712 seconds and 3 git commands to generate.