1 /* Main code for remote server for GDB.
2 Copyright 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 int old_thread_from_wait
;
28 int extended_protocol
;
33 start_inferior (char *argv
[], char *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
;
45 main (int argc
, char *argv
[])
47 char ch
, status
, own_buf
[PBUFSIZ
], mem_buf
[2000];
53 if (setjmp (toplevel
))
55 fprintf (stderr
, "Exiting\n");
60 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.040099 seconds and 4 git commands to generate.