]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbserver/server.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / gdbserver / server.c
CommitLineData
ab18bba0
PS
1/* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#include "server.h"
21
22main (argc, argv)
23 int argc;
24 char *argv[];
25{
26 char ch, status, own_buf[2000], mem_buf[2000];
27 int i = 0;
28 unsigned char signal;
29 unsigned int mem_addr, len;
30
31 if (setjmp(toplevel))
32 {
33 fprintf(stderr, "Exiting\n");
34 exit(1);
35 }
36
37 if (argc < 3)
38 error("Usage: gdbserver tty prog [args ...]");
39
40 inferior_pid = create_inferior (argv[2], &argv[2]);
41 fprintf (stderr, "Process %s created; pid = %d\n", argv[2], inferior_pid);
42
43 signal = mywait (&status); /* Wait till we are at 1st instr in prog */
44
45 /* We are now stopped at the first instruction of the target process */
46
47 while (1)
48 {
49 remote_open (argv[1]);
50
51 setjmp(toplevel);
52 while (getpkt (own_buf) > 0)
53 {
54 i = 0;
55 ch = own_buf[i++];
56 switch (ch)
57 {
58 case '?':
59 prepare_resume_reply (own_buf, status, signal);
60 break;
61 case 'g':
62 convert_int_to_ascii (registers, own_buf, REGISTER_BYTES);
63 break;
64 case 'G':
65 convert_ascii_to_int (&own_buf[1], registers, REGISTER_BYTES);
66 store_inferior_registers (-1);
67 write_ok (own_buf);
68 break;
69 case 'm':
70 decode_m_packet (&own_buf[1], &mem_addr, &len);
71 read_inferior_memory (mem_addr, mem_buf, len);
72 convert_int_to_ascii (mem_buf, own_buf, len);
73 break;
74 case 'M':
75 decode_M_packet (&own_buf[1], &mem_addr, &len, mem_buf);
76 if (write_inferior_memory (mem_addr, mem_buf, len) == 0)
77 write_ok (own_buf);
78 else
79 write_enn (own_buf);
80 break;
81 case 'c':
82 myresume (0, 0);
83 signal = mywait (&status);
84 prepare_resume_reply (own_buf, status, signal);
85 break;
86 case 's':
87 myresume (1, 0);
88 signal = mywait (&status);
89 prepare_resume_reply (own_buf, status, signal);
90 break;
91 case 'k':
92 fprintf (stderr, "Killing inferior\n");
93 kill_inferior ();
94 inferior_pid = create_inferior (argv[2], &argv[2]);
95 fprintf (stderr, "Process %s created; pid = %d\n", argv[2],
96 inferior_pid);
97 signal = mywait (&status); /* Wait till we are at 1st instr in prog */
98 break;
99 case 'q':
100 own_buf[0] = '\0';
101 break;
102 default:
103 printf ("\nUnknown option chosen by master\n");
104 write_enn (own_buf);
105 break;
106 }
107
108 putpkt (own_buf);
109 }
110
111 /* We come here when getpkt fails. Close the connection, and re-open it
112 at the top of the loop. */
113
114 fprintf (stderr, "Remote side has terminated connection. GDBserver will reopen the connection.\n");
115
116 remote_close ();
117 }
118}