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
;
64 fprintf(stderr
, "Exiting\n");
69 error("Usage: gdbserver tty prog [args ...]");
72 remote_open (argv
[1], 0);
75 for (i
= 2; i
< argc
; i
++)
76 strcat(argvec
, argv
[i
]);
78 inferior_pid
= create_inferior (argvec
, environ
);
79 fprintf (stderr
, "Process %s created; pid = %d\n", argv
[1], inferior_pid
);
81 signal
= mywait (&status
); /* Wait till we are at 1st instr in shell */
82 if (status
!= 'S' || signal
!= SIGTRAP
)
83 error ("Bad status from shell\n");
84 myresume (0, 0); /* Start up the shell */
85 signal
= mywait (&status
); /* Wait for program to start */
87 /* We are now stopped at the first instruction of the target process */
98 prepare_resume_reply (own_buf
, status
, signal
);
101 convert_int_to_ascii (registers
, own_buf
, REGISTER_BYTES
);
104 convert_ascii_to_int (&own_buf
[1], registers
, REGISTER_BYTES
);
105 store_inferior_registers (-1);
109 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
110 read_inferior_memory (mem_addr
, mem_buf
, len
);
111 convert_int_to_ascii (mem_buf
, own_buf
, len
);
114 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
115 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
122 signal
= mywait (&status
);
123 prepare_resume_reply (own_buf
, status
, signal
);
127 signal
= mywait (&status
);
128 prepare_resume_reply (own_buf
, status
, signal
);
132 sprintf (own_buf
, "q");
134 fprintf (stderr
, "Obtained kill request...terminating\n");
138 printf ("\nUnknown option chosen by master\n");
148 /** now get out of here**/
149 fprintf (stderr
, "Finished reading data from serial link - Bye!\n");
This page took 0.0324 seconds and 4 git commands to generate.