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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 void read_inferior_memory ();
25 unsigned char mywait ();
28 int create_inferior ();
30 extern char registers
[];
32 extern char **environ
;
34 /* Descriptor for I/O to remote machine. */
45 void convert_ascii_to_int ();
46 void convert_int_to_ascii ();
47 void prepare_resume_reply ();
48 void decode_m_packet ();
49 void decode_M_packet ();
56 char ch
, status
, own_buf
[2000], mem_buf
[2000];
59 unsigned int mem_addr
, len
;
63 fprintf(stderr
, "Exiting\n");
68 error("Usage: gdbserver tty prog [args ...]");
71 remote_open (argv
[1], 0);
73 inferior_pid
= create_inferior (argv
[2], &argv
[2]);
74 fprintf (stderr
, "Process %s created; pid = %d\n", argv
[2], inferior_pid
);
76 signal
= mywait (&status
); /* Wait till we are at 1st instr in prog */
78 /* We are now stopped at the first instruction of the target process */
89 prepare_resume_reply (own_buf
, status
, signal
);
92 convert_int_to_ascii (registers
, own_buf
, REGISTER_BYTES
);
95 convert_ascii_to_int (&own_buf
[1], registers
, REGISTER_BYTES
);
96 store_inferior_registers (-1);
100 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
101 read_inferior_memory (mem_addr
, mem_buf
, len
);
102 convert_int_to_ascii (mem_buf
, own_buf
, len
);
105 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
106 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
113 signal
= mywait (&status
);
114 prepare_resume_reply (own_buf
, status
, signal
);
118 signal
= mywait (&status
);
119 prepare_resume_reply (own_buf
, status
, signal
);
123 sprintf (own_buf
, "q");
125 fprintf (stderr
, "Obtained kill request...terminating\n");
129 printf ("\nUnknown option chosen by master\n");
139 /** now get out of here**/
140 fprintf (stderr
, "Finished reading data from serial link - Bye!\n");
This page took 0.031087 seconds and 4 git commands to generate.