]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/monitor.c
Make gdb compile & link cleanly on powerpc-linux
[thirdparty/binutils-gdb.git] / gdb / monitor.c
1 /* Remote debugging interface for boot monitors, for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1995, 1996
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
5 Resurrected from the ashes by Stu Grossman.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23 /* This file was derived from various remote-* modules. It is a collection
24 of generic support functions so GDB can talk directly to a ROM based
25 monitor. This saves use from having to hack an exception based handler
26 into existance, and makes for quick porting.
27
28 This module talks to a debug monitor called 'MONITOR', which
29 We communicate with MONITOR via either a direct serial line, or a TCP
30 (or possibly TELNET) stream to a terminal multiplexor,
31 which in turn talks to the target board. */
32
33 /* FIXME 32x64: This code assumes that registers and addresses are at
34 most 32 bits long. If they can be larger, you will need to declare
35 values as LONGEST and use %llx or some such to print values when
36 building commands to send to the monitor. Since we don't know of
37 any actual 64-bit targets with ROM monitors that use this code,
38 it's not an issue right now. -sts 4/18/96 */
39
40 #include "defs.h"
41 #include "gdbcore.h"
42 #include "target.h"
43 #include "wait.h"
44 #ifdef ANSI_PROTOTYPES
45 #include <stdarg.h>
46 #else
47 #include <varargs.h>
48 #endif
49 #include <signal.h>
50 #include <ctype.h>
51 #include "gdb_string.h"
52 #include <sys/types.h>
53 #include "command.h"
54 #include "serial.h"
55 #include "monitor.h"
56 #include "gdbcmd.h"
57 #include "inferior.h"
58 #include "gnu-regex.h"
59 #include "dcache.h"
60 #include "srec.h"
61
62 static char *dev_name;
63 static struct target_ops *targ_ops;
64
65 static int readchar PARAMS ((int timeout));
66
67 static void monitor_command PARAMS ((char *args, int fromtty));
68
69 static void monitor_fetch_register PARAMS ((int regno));
70 static void monitor_store_register PARAMS ((int regno));
71
72 static void monitor_detach PARAMS ((char *args, int from_tty));
73 static void monitor_resume PARAMS ((int pid, int step, enum target_signal sig));
74 static void monitor_interrupt PARAMS ((int signo));
75 static void monitor_interrupt_twice PARAMS ((int signo));
76 static void monitor_interrupt_query PARAMS ((void));
77 static void monitor_wait_cleanup PARAMS ((int old_timeout));
78
79 static int monitor_wait PARAMS ((int pid, struct target_waitstatus *status));
80 static void monitor_fetch_registers PARAMS ((int regno));
81 static void monitor_store_registers PARAMS ((int regno));
82 static void monitor_prepare_to_store PARAMS ((void));
83 static int monitor_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len, int write, struct target_ops *target));
84 static void monitor_files_info PARAMS ((struct target_ops *ops));
85 static int monitor_insert_breakpoint PARAMS ((CORE_ADDR addr, char *shadow));
86 static int monitor_remove_breakpoint PARAMS ((CORE_ADDR addr, char *shadow));
87 static void monitor_kill PARAMS ((void));
88 static void monitor_load PARAMS ((char *file, int from_tty));
89 static void monitor_mourn_inferior PARAMS ((void));
90 static void monitor_stop PARAMS ((void));
91 static void monitor_debug PARAMS ((char *prefix, char *string, char *suffix));
92
93 static int monitor_read_memory PARAMS ((CORE_ADDR addr, char *myaddr,int len));
94 static int monitor_write_memory PARAMS ((CORE_ADDR addr, char *myaddr,int len));
95
96 static int monitor_expect_regexp PARAMS ((struct re_pattern_buffer *pat,
97 char *buf, int buflen));
98 static int from_hex PARAMS ((int a));
99 static unsigned long get_hex_word PARAMS ((void));
100
101 static struct monitor_ops *current_monitor;
102
103 static int hashmark; /* flag set by "set hash" */
104
105 static int timeout = 30;
106
107 static int in_monitor_wait = 0; /* Non-zero means we are in monitor_wait() */
108
109 static void (*ofunc)(); /* Old SIGINT signal handler */
110
111 /* Descriptor for I/O to remote machine. Initialize it to NULL so
112 that monitor_open knows that we don't have a file open when the
113 program starts. */
114
115 static serial_t monitor_desc = NULL;
116
117 /* Pointer to regexp pattern matching data */
118
119 static struct re_pattern_buffer register_pattern;
120 static char register_fastmap[256];
121
122 static struct re_pattern_buffer getmem_resp_delim_pattern;
123 static char getmem_resp_delim_fastmap[256];
124
125 static int dump_reg_flag; /* Non-zero means do a dump_registers cmd when
126 monitor_wait wakes up. */
127
128 static DCACHE *remote_dcache;
129 static int first_time=0; /* is this the first time we're executing after
130 gaving created the child proccess? */
131
132 /* monitor_debug is like fputs_unfiltered, except it prints special
133 characters in printable fashion. */
134
135 static void
136 monitor_debug (prefix, string, suffix)
137 char *prefix;
138 char *string;
139 char *suffix;
140 {
141 int ch;
142
143 /* print prefix and suffix after each line */
144 static int new_line=1;
145 static char *prev_prefix = "";
146 static char *prev_suffix = "";
147
148 /* if the prefix is changing, print the previous suffix, a new line,
149 and the new prefix */
150 if (strcmp(prev_prefix, prefix) != 0 && !new_line)
151 {
152 fputs_unfiltered (prev_suffix, gdb_stderr);
153 fputs_unfiltered ("\n", gdb_stderr);
154 fputs_unfiltered (prefix, gdb_stderr);
155 }
156 prev_prefix = prefix;
157 prev_suffix = suffix;
158
159 /* print prefix if last char was a newline*/
160
161 if (new_line == 1) {
162 fputs_unfiltered (prefix, gdb_stderr);
163 new_line=0;
164 }
165 if (strchr(string,'\n')) /* save state for next call */
166 new_line=1;
167
168 while ((ch = *string++) != '\0')
169 {
170 switch (ch) {
171 default:
172 if (isprint (ch))
173 fputc_unfiltered (ch, gdb_stderr);
174
175 else
176 fprintf_unfiltered (gdb_stderr, "\\%03o", ch);
177
178 break;
179
180 case '\\': fputs_unfiltered ("\\\\", gdb_stderr); break;
181 case '\b': fputs_unfiltered ("\\b", gdb_stderr); break;
182 case '\f': fputs_unfiltered ("\\f", gdb_stderr); break;
183 case '\n': fputs_unfiltered ("\\n", gdb_stderr); break;
184 case '\r': fputs_unfiltered ("\\r", gdb_stderr); break;
185 case '\t': fputs_unfiltered ("\\t", gdb_stderr); break;
186 case '\v': fputs_unfiltered ("\\v", gdb_stderr); break;
187 }
188 }
189
190 if (new_line==1) { /* print suffix if last char was a newline */
191 fputs_unfiltered (suffix, gdb_stderr);
192 fputs_unfiltered ("\n", gdb_stderr);
193 }
194 }
195
196 /* monitor_printf_noecho -- Send data to monitor, but don't expect an echo.
197 Works just like printf. */
198
199 void
200 #ifdef ANSI_PROTOTYPES
201 monitor_printf_noecho (char *pattern, ...)
202 #else
203 monitor_printf_noecho (va_alist)
204 va_dcl
205 #endif
206 {
207 va_list args;
208 char sndbuf[2000];
209 int len;
210
211 #if ANSI_PROTOTYPES
212 va_start (args, pattern);
213 #else
214 char *pattern;
215 va_start (args);
216 pattern = va_arg (args, char *);
217 #endif
218
219 vsprintf (sndbuf, pattern, args);
220
221 if (remote_debug > 0)
222 monitor_debug ("sent -->", sndbuf, "<--");
223
224 len = strlen (sndbuf);
225
226 if (len + 1 > sizeof sndbuf)
227 abort ();
228
229 if (SERIAL_WRITE(monitor_desc, sndbuf, len))
230 fprintf_unfiltered (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
231 }
232
233 /* monitor_printf -- Send data to monitor and check the echo. Works just like
234 printf. */
235
236 void
237 #ifdef ANSI_PROTOTYPES
238 monitor_printf (char *pattern, ...)
239 #else
240 monitor_printf (va_alist)
241 va_dcl
242 #endif
243 {
244 va_list args;
245 char sndbuf[2000];
246 int len;
247
248 #ifdef ANSI_PROTOTYPES
249 va_start (args, pattern);
250 #else
251 char *pattern;
252 va_start (args);
253 pattern = va_arg (args, char *);
254 #endif
255
256 vsprintf (sndbuf, pattern, args);
257
258 if (remote_debug > 0)
259 monitor_debug ("sent -->", sndbuf, "<--");
260
261 len = strlen (sndbuf);
262
263 if (len + 1 > sizeof sndbuf)
264 abort ();
265
266 if (SERIAL_WRITE(monitor_desc, sndbuf, len))
267 fprintf_unfiltered (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
268
269 /* We used to expect that the next immediate output was the characters we
270 just output, but sometimes some extra junk appeared before the characters
271 we expected, like an extra prompt, or a portmaster sending telnet negotiations.
272 So, just start searching for what we sent, and skip anything unknown. */
273 monitor_expect (sndbuf, (char *)0, 0);
274 }
275
276 /* Read a character from the remote system, doing all the fancy
277 timeout stuff. */
278
279 static int
280 readchar (timeout)
281 int timeout;
282 {
283 int c;
284 static enum { last_random, last_nl, last_cr, last_crnl } state = last_random;
285 int looping;
286
287 do
288 {
289 looping = 0;
290 c = SERIAL_READCHAR (monitor_desc, timeout);
291
292 if (c >= 0)
293 {
294 c &= 0x7f;
295 if (remote_debug > 0)
296 {
297 char buf[2];
298 buf[0] = c;
299 buf[1] = '\0';
300 monitor_debug ("read -->", buf, "<--");
301 }
302 }
303
304 /* Canonicialize \n\r combinations into one \r */
305 if ((current_monitor->flags & MO_HANDLE_NL) != 0)
306 {
307 if ((c == '\r' && state == last_nl)
308 || (c == '\n' && state == last_cr))
309 {
310 state = last_crnl;
311 looping = 1;
312 }
313 else if (c == '\r')
314 state = last_cr;
315 else if (c != '\n')
316 state = last_random;
317 else
318 {
319 state = last_nl;
320 c = '\r';
321 }
322 }
323 }
324 while (looping);
325
326 if (c >= 0)
327 return c;
328
329 if (c == SERIAL_TIMEOUT)
330 #ifdef MAINTENANCE_CMDS
331 if (in_monitor_wait) /* Watchdog went off */
332 {
333 target_mourn_inferior ();
334 error ("Watchdog has expired. Target detached.\n");
335 }
336 else
337 #endif
338 error ("Timeout reading from remote system.");
339
340 perror_with_name ("remote-monitor");
341 }
342
343 /* Scan input from the remote system, until STRING is found. If BUF is non-
344 zero, then collect input until we have collected either STRING or BUFLEN-1
345 chars. In either case we terminate BUF with a 0. If input overflows BUF
346 because STRING can't be found, return -1, else return number of chars in BUF
347 (minus the terminating NUL). Note that in the non-overflow case, STRING
348 will be at the end of BUF. */
349
350 int
351 monitor_expect (string, buf, buflen)
352 char *string;
353 char *buf;
354 int buflen;
355 {
356 char *p = string;
357 int obuflen = buflen;
358 int c;
359 extern struct target_ops *targ_ops;
360
361 immediate_quit = 1;
362 while (1)
363 {
364 if (buf)
365 {
366 if (buflen < 2)
367 {
368 *buf = '\000';
369 immediate_quit = 0;
370 return -1;
371 }
372
373 c = readchar (timeout);
374 if (c == '\000')
375 continue;
376 *buf++ = c;
377 buflen--;
378 }
379 else
380 c = readchar (timeout);
381
382 /* Don't expect any ^C sent to be echoed */
383
384 if (*p == '\003' || c == *p)
385 {
386 p++;
387 if (*p == '\0')
388 {
389 immediate_quit = 0;
390
391 if (buf)
392 {
393 *buf++ = '\000';
394 return obuflen - buflen;
395 }
396 else
397 return 0;
398 }
399 }
400 else if ((c == '\021' || c == '\023') &&
401 (strcmp(targ_ops->to_shortname, "m32r") == 0))
402 { /* m32r monitor emits random DC1/DC3 chars */
403 continue;
404 }
405 else
406 {
407 p = string;
408 if (c == *p)
409 p++;
410 }
411 }
412 }
413
414 /* Search for a regexp. */
415
416 static int
417 monitor_expect_regexp (pat, buf, buflen)
418 struct re_pattern_buffer *pat;
419 char *buf;
420 int buflen;
421 {
422 char *mybuf;
423 char *p;
424
425 if (buf)
426 mybuf = buf;
427 else
428 {
429 mybuf = alloca (1024);
430 buflen = 1024;
431 }
432
433 p = mybuf;
434 while (1)
435 {
436 int retval;
437
438 if (p - mybuf >= buflen)
439 { /* Buffer about to overflow */
440
441 /* On overflow, we copy the upper half of the buffer to the lower half. Not
442 great, but it usually works... */
443
444 memcpy (mybuf, mybuf + buflen / 2, buflen / 2);
445 p = mybuf + buflen / 2;
446 }
447
448 *p++ = readchar (timeout);
449
450 retval = re_search (pat, mybuf, p - mybuf, 0, p - mybuf, NULL);
451 if (retval >= 0)
452 return 1;
453 }
454 }
455
456 /* Keep discarding input until we see the MONITOR prompt.
457
458 The convention for dealing with the prompt is that you
459 o give your command
460 o *then* wait for the prompt.
461
462 Thus the last thing that a procedure does with the serial line
463 will be an monitor_expect_prompt(). Exception: monitor_resume does not
464 wait for the prompt, because the terminal is being handed over
465 to the inferior. However, the next thing which happens after that
466 is a monitor_wait which does wait for the prompt.
467 Note that this includes abnormal exit, e.g. error(). This is
468 necessary to prevent getting into states from which we can't
469 recover. */
470
471 int
472 monitor_expect_prompt (buf, buflen)
473 char *buf;
474 int buflen;
475 {
476 return monitor_expect (current_monitor->prompt, buf, buflen);
477 }
478
479 /* Get N 32-bit words from remote, each preceded by a space, and put
480 them in registers starting at REGNO. */
481
482 static unsigned long
483 get_hex_word ()
484 {
485 unsigned long val;
486 int i;
487 int ch;
488
489 do
490 ch = readchar (timeout);
491 while (isspace(ch));
492
493 val = from_hex (ch);
494
495 for (i = 7; i >= 1; i--)
496 {
497 ch = readchar (timeout);
498 if (!isxdigit (ch))
499 break;
500 val = (val << 4) | from_hex (ch);
501 }
502
503 return val;
504 }
505
506 static void
507 compile_pattern (pattern, compiled_pattern, fastmap)
508 char *pattern;
509 struct re_pattern_buffer *compiled_pattern;
510 char *fastmap;
511 {
512 int tmp;
513 char *val;
514
515 compiled_pattern->fastmap = fastmap;
516
517 tmp = re_set_syntax (RE_SYNTAX_EMACS);
518 val = re_compile_pattern (pattern,
519 strlen (pattern),
520 compiled_pattern);
521 re_set_syntax (tmp);
522
523 if (val)
524 error ("compile_pattern: Can't compile pattern string `%s': %s!", pattern, val);
525
526 if (fastmap)
527 re_compile_fastmap (compiled_pattern);
528 }
529
530 /* Open a connection to a remote debugger. NAME is the filename used
531 for communication. */
532
533 void
534 monitor_open (args, mon_ops, from_tty)
535 char *args;
536 struct monitor_ops *mon_ops;
537 int from_tty;
538 {
539 char *name;
540 int i;
541 char **p;
542
543 if (mon_ops->magic != MONITOR_OPS_MAGIC)
544 error ("Magic number of monitor_ops struct wrong.");
545
546 targ_ops = mon_ops->target;
547 name = targ_ops->to_shortname;
548
549 if (!args)
550 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
551 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name, name);
552
553 target_preopen (from_tty);
554
555 /* Setup pattern for register dump */
556
557 if (mon_ops->register_pattern)
558 compile_pattern (mon_ops->register_pattern, &register_pattern,
559 register_fastmap);
560
561 if (mon_ops->getmem.resp_delim)
562 compile_pattern (mon_ops->getmem.resp_delim, &getmem_resp_delim_pattern,
563 getmem_resp_delim_fastmap);
564
565 unpush_target (targ_ops);
566
567 if (dev_name)
568 free (dev_name);
569 dev_name = strsave (args);
570
571 monitor_desc = SERIAL_OPEN (dev_name);
572
573 if (!monitor_desc)
574 perror_with_name (dev_name);
575
576 if (baud_rate != -1)
577 {
578 if (SERIAL_SETBAUDRATE (monitor_desc, baud_rate))
579 {
580 SERIAL_CLOSE (monitor_desc);
581 perror_with_name (dev_name);
582 }
583 }
584
585 SERIAL_RAW (monitor_desc);
586
587 SERIAL_FLUSH_INPUT (monitor_desc);
588
589 /* some systems only work with 2 stop bits */
590
591 SERIAL_SETSTOPBITS (monitor_desc, mon_ops->stopbits);
592
593 current_monitor = mon_ops;
594
595 /* See if we can wake up the monitor. First, try sending a stop sequence,
596 then send the init strings. Last, remove all breakpoints. */
597
598 if (current_monitor->stop)
599 {
600 monitor_stop ();
601 if ((current_monitor->flags & MO_NO_ECHO_ON_OPEN) == 0)
602 {
603 monitor_expect_prompt (NULL, 0);
604 }
605 }
606
607 /* wake up the monitor and see if it's alive */
608 for (p = mon_ops->init; *p != NULL; p++)
609 {
610 /* Some of the characters we send may not be echoed,
611 but we hope to get a prompt at the end of it all. */
612
613 if ((current_monitor->flags & MO_NO_ECHO_ON_OPEN) == 0)
614 monitor_printf(*p);
615 else
616 monitor_printf_noecho (*p);
617 monitor_expect_prompt (NULL, 0);
618 }
619
620 SERIAL_FLUSH_INPUT (monitor_desc);
621
622 /* Remove all breakpoints */
623
624 if (mon_ops->clr_all_break)
625 {
626 monitor_printf (mon_ops->clr_all_break);
627 monitor_expect_prompt (NULL, 0);
628 }
629
630 if (from_tty)
631 printf_unfiltered ("Remote target %s connected to %s\n", name, dev_name);
632
633 push_target (targ_ops);
634
635 inferior_pid = 42000; /* Make run command think we are busy... */
636
637 /* Give monitor_wait something to read */
638
639 monitor_printf (current_monitor->line_term);
640
641 remote_dcache = dcache_init (monitor_read_memory, monitor_write_memory);
642
643 start_remote ();
644 }
645
646 /* Close out all files and local state before this target loses
647 control. */
648
649 void
650 monitor_close (quitting)
651 int quitting;
652 {
653 if (monitor_desc)
654 SERIAL_CLOSE (monitor_desc);
655 monitor_desc = NULL;
656 }
657
658 /* Terminate the open connection to the remote debugger. Use this
659 when you want to detach and do something else with your gdb. */
660
661 static void
662 monitor_detach (args, from_tty)
663 char *args;
664 int from_tty;
665 {
666 pop_target (); /* calls monitor_close to do the real work */
667 if (from_tty)
668 printf_unfiltered ("Ending remote %s debugging\n", target_shortname);
669 }
670
671 /* Convert VALSTR into the target byte-ordered value of REGNO and store it. */
672
673 char *
674 monitor_supply_register (regno, valstr)
675 int regno;
676 char *valstr;
677 {
678 unsigned int val;
679 unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
680 char *p;
681
682 val = strtoul (valstr, &p, 16);
683
684 if (val == 0 && valstr == p)
685 error ("monitor_supply_register (%d): bad value from monitor: %s.",
686 regno, valstr);
687
688 /* supply register stores in target byte order, so swap here */
689
690 store_unsigned_integer (regbuf, REGISTER_RAW_SIZE (regno), val);
691
692 supply_register (regno, regbuf);
693
694 return p;
695 }
696
697 /* Tell the remote machine to resume. */
698
699 static void
700 monitor_resume (pid, step, sig)
701 int pid, step;
702 enum target_signal sig;
703 {
704 /* Some monitors require a different command when starting a program */
705 if (current_monitor->flags & MO_RUN_FIRST_TIME && first_time == 1)
706 {
707 first_time = 0;
708 monitor_printf ("run\r");
709 if (current_monitor->flags & MO_NEED_REGDUMP_AFTER_CONT)
710 dump_reg_flag = 1;
711 return;
712 }
713 dcache_flush (remote_dcache);
714 if (step)
715 monitor_printf (current_monitor->step);
716 else
717 {
718 monitor_printf (current_monitor->cont);
719 if (current_monitor->flags & MO_NEED_REGDUMP_AFTER_CONT)
720 dump_reg_flag = 1;
721 }
722 }
723
724 /* Parse the output of a register dump command. A monitor specific
725 regexp is used to extract individual register descriptions of the
726 form REG=VAL. Each description is split up into a name and a value
727 string which are passed down to monitor specific code. */
728
729 static char *
730 parse_register_dump (buf, len)
731 char *buf;
732 int len;
733 {
734 while (1)
735 {
736 int regnamelen, vallen;
737 char *regname, *val;
738 /* Element 0 points to start of register name, and element 1
739 points to the start of the register value. */
740 struct re_registers register_strings;
741
742 if (re_search (&register_pattern, buf, len, 0, len,
743 &register_strings) == -1)
744 break;
745
746 regnamelen = register_strings.end[1] - register_strings.start[1];
747 regname = buf + register_strings.start[1];
748 vallen = register_strings.end[2] - register_strings.start[2];
749 val = buf + register_strings.start[2];
750
751 current_monitor->supply_register (regname, regnamelen, val, vallen);
752
753 buf += register_strings.end[0];
754 len -= register_strings.end[0];
755 }
756 }
757
758 /* Send ^C to target to halt it. Target will respond, and send us a
759 packet. */
760
761 static void
762 monitor_interrupt (signo)
763 int signo;
764 {
765 /* If this doesn't work, try more severe steps. */
766 signal (signo, monitor_interrupt_twice);
767
768 if (remote_debug)
769 printf_unfiltered ("monitor_interrupt called\n");
770
771 target_stop ();
772 }
773
774 /* The user typed ^C twice. */
775
776 static void
777 monitor_interrupt_twice (signo)
778 int signo;
779 {
780 signal (signo, ofunc);
781
782 monitor_interrupt_query ();
783
784 signal (signo, monitor_interrupt);
785 }
786
787 /* Ask the user what to do when an interrupt is received. */
788
789 static void
790 monitor_interrupt_query ()
791 {
792 target_terminal_ours ();
793
794 if (query ("Interrupted while waiting for the program.\n\
795 Give up (and stop debugging it)? "))
796 {
797 target_mourn_inferior ();
798 return_to_top_level (RETURN_QUIT);
799 }
800
801 target_terminal_inferior ();
802 }
803
804 static void
805 monitor_wait_cleanup (old_timeout)
806 int old_timeout;
807 {
808 timeout = old_timeout;
809 signal (SIGINT, ofunc);
810 in_monitor_wait = 0;
811 }
812
813 /* Wait until the remote machine stops, then return, storing status in
814 status just as `wait' would. */
815
816 static int
817 monitor_wait (pid, status)
818 int pid;
819 struct target_waitstatus *status;
820 {
821 int old_timeout = timeout;
822 char buf[1024];
823 int resp_len;
824 struct cleanup *old_chain;
825
826 status->kind = TARGET_WAITKIND_EXITED;
827 status->value.integer = 0;
828
829 old_chain = make_cleanup (monitor_wait_cleanup, old_timeout);
830
831 #ifdef MAINTENANCE_CMDS
832 in_monitor_wait = 1;
833 timeout = watchdog > 0 ? watchdog : -1;
834 #else
835 timeout = -1; /* Don't time out -- user program is running. */
836 #endif
837
838 ofunc = (void (*)()) signal (SIGINT, monitor_interrupt);
839
840 do
841 {
842 resp_len = monitor_expect_prompt (buf, sizeof (buf));
843
844 if (resp_len <= 0)
845 fprintf_unfiltered (gdb_stderr, "monitor_wait: excessive response from monitor: %s.", buf);
846 }
847 while (resp_len < 0);
848
849 signal (SIGINT, ofunc);
850
851 timeout = old_timeout;
852
853 if (dump_reg_flag && current_monitor->dump_registers)
854 {
855 dump_reg_flag = 0;
856
857 monitor_printf (current_monitor->dump_registers);
858 resp_len = monitor_expect_prompt (buf, sizeof (buf));
859 }
860
861 if (current_monitor->register_pattern)
862 parse_register_dump (buf, resp_len);
863
864 status->kind = TARGET_WAITKIND_STOPPED;
865 status->value.sig = TARGET_SIGNAL_TRAP;
866
867 discard_cleanups (old_chain);
868
869 in_monitor_wait = 0;
870
871 return inferior_pid;
872 }
873
874 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
875 errno value. */
876
877 static void
878 monitor_fetch_register (regno)
879 int regno;
880 {
881 char *name;
882 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
883 char regbuf[MAX_REGISTER_RAW_SIZE * 2 + 1];
884 int i;
885
886 name = current_monitor->regnames[regno];
887
888 if (!name)
889 {
890 supply_register (regno, zerobuf);
891 return;
892 }
893
894 /* send the register examine command */
895
896 monitor_printf (current_monitor->getreg.cmd, name);
897
898 /* If RESP_DELIM is specified, we search for that as a leading
899 delimiter for the register value. Otherwise, we just start
900 searching from the start of the buf. */
901
902 if (current_monitor->getreg.resp_delim)
903 monitor_expect (current_monitor->getreg.resp_delim, NULL, 0);
904
905 /* Skip leading spaces and "0x" if MO_HEX_PREFIX flag is set */
906 if (current_monitor->flags & MO_HEX_PREFIX)
907 {
908 int c;
909 c = readchar (timeout);
910 while (c == ' ')
911 c = readchar (timeout);
912 if ((c == '0') && ((c = readchar (timeout)) == 'x'))
913 ;
914 else
915 error ("Bad value returned from monitor while fetching register %x.",
916 regno);
917 }
918
919 /* Read upto the maximum number of hex digits for this register, skipping
920 spaces, but stop reading if something else is seen. Some monitors
921 like to drop leading zeros. */
922
923 for (i = 0; i < REGISTER_RAW_SIZE (regno) * 2; i++)
924 {
925 int c;
926 c = readchar (timeout);
927 while (c == ' ')
928 c = readchar (timeout);
929
930 if (!isxdigit (c))
931 break;
932
933 regbuf[i] = c;
934 }
935
936 regbuf[i] = '\000'; /* terminate the number */
937
938 /* If TERM is present, we wait for that to show up. Also, (if TERM
939 is present), we will send TERM_CMD if that is present. In any
940 case, we collect all of the output into buf, and then wait for
941 the normal prompt. */
942
943 if (current_monitor->getreg.term)
944 {
945 monitor_expect (current_monitor->getreg.term, NULL, 0); /* get response */
946
947 if (current_monitor->getreg.term_cmd)
948 {
949 monitor_printf (current_monitor->getreg.term_cmd);
950 monitor_expect_prompt (NULL, 0);
951 }
952 }
953 else
954 monitor_expect_prompt (NULL, 0); /* get response */
955
956 monitor_supply_register (regno, regbuf);
957 }
958
959 /* Read the remote registers into the block regs. */
960
961 static void monitor_dump_regs ()
962 {
963 char buf[1024];
964 int resp_len;
965
966 if (current_monitor->dump_registers)
967 {
968 monitor_printf (current_monitor->dump_registers);
969 resp_len = monitor_expect_prompt (buf, sizeof (buf));
970 parse_register_dump (buf, resp_len);
971 }
972 else
973 abort(); /* Need some way to read registers */
974 }
975
976 static void
977 monitor_fetch_registers (regno)
978 int regno;
979 {
980 if (current_monitor->getreg.cmd)
981 {
982 if (regno >= 0)
983 {
984 monitor_fetch_register (regno);
985 return;
986 }
987
988 for (regno = 0; regno < NUM_REGS; regno++)
989 monitor_fetch_register (regno);
990 }
991 else {
992 monitor_dump_regs ();
993 }
994 }
995
996 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
997
998 static void
999 monitor_store_register (regno)
1000 int regno;
1001 {
1002 char *name;
1003 unsigned int val;
1004
1005 name = current_monitor->regnames[regno];
1006 if (!name)
1007 return;
1008
1009 val = read_register (regno);
1010
1011 /* send the register deposit command */
1012
1013 if (current_monitor->flags & MO_REGISTER_VALUE_FIRST)
1014 monitor_printf (current_monitor->setreg.cmd, val, name);
1015 else
1016 monitor_printf (current_monitor->setreg.cmd, name, val);
1017
1018 /* It's possible that there are actually some monitors out there that
1019 will prompt you when you set a register. In that case, you may
1020 need to add some code here to deal with TERM and TERM_CMD (see
1021 monitor_fetch_register to get an idea of what's needed...) */
1022
1023 monitor_expect_prompt (NULL, 0);
1024 }
1025
1026 /* Store the remote registers. */
1027
1028 static void
1029 monitor_store_registers (regno)
1030 int regno;
1031 {
1032 if (regno >= 0)
1033 {
1034 monitor_store_register (regno);
1035 return;
1036 }
1037
1038 for (regno = 0; regno < NUM_REGS; regno++)
1039 monitor_store_register (regno);
1040 }
1041
1042 /* Get ready to modify the registers array. On machines which store
1043 individual registers, this doesn't need to do anything. On machines
1044 which store all the registers in one fell swoop, this makes sure
1045 that registers contains all the registers from the program being
1046 debugged. */
1047
1048 static void
1049 monitor_prepare_to_store ()
1050 {
1051 /* Do nothing, since we can store individual regs */
1052 }
1053
1054 static void
1055 monitor_files_info (ops)
1056 struct target_ops *ops;
1057 {
1058 printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name, baud_rate);
1059 }
1060
1061 static int
1062 monitor_write_memory (memaddr, myaddr, len)
1063 CORE_ADDR memaddr;
1064 char *myaddr;
1065 int len;
1066 {
1067 unsigned int val;
1068 char *cmd;
1069 int i;
1070
1071 /* Use memory fill command for leading 0 bytes. */
1072
1073 if (current_monitor->fill)
1074 {
1075 for (i = 0; i < len; i++)
1076 if (myaddr[i] != 0)
1077 break;
1078
1079 if (i > 4) /* More than 4 zeros is worth doing */
1080 {
1081 if (current_monitor->flags & MO_FILL_USES_ADDR)
1082 monitor_printf (current_monitor->fill, memaddr, memaddr + i, 0);
1083 else
1084 monitor_printf (current_monitor->fill, memaddr, i, 0);
1085
1086 monitor_expect_prompt (NULL, 0);
1087
1088 return i;
1089 }
1090 }
1091
1092 #if 0
1093 /* Can't actually use long longs if VAL is an int (nice idea, though). */
1094 if ((memaddr & 0x7) == 0 && len >= 8 && current_monitor->setmem.cmdll)
1095 {
1096 len = 8;
1097 cmd = current_monitor->setmem.cmdll;
1098 }
1099 else
1100 #endif
1101 if ((memaddr & 0x3) == 0 && len >= 4 && current_monitor->setmem.cmdl)
1102 {
1103 len = 4;
1104 cmd = current_monitor->setmem.cmdl;
1105 }
1106 else if ((memaddr & 0x1) == 0 && len >= 2 && current_monitor->setmem.cmdw)
1107 {
1108 len = 2;
1109 cmd = current_monitor->setmem.cmdw;
1110 }
1111 else
1112 {
1113 len = 1;
1114 cmd = current_monitor->setmem.cmdb;
1115 }
1116
1117 val = extract_unsigned_integer (myaddr, len);
1118
1119 if (current_monitor->flags & MO_NO_ECHO_ON_SETMEM)
1120 monitor_printf_noecho (cmd, memaddr, val);
1121 else
1122 monitor_printf (cmd, memaddr, val);
1123
1124 monitor_expect_prompt (NULL, 0);
1125
1126 return len;
1127 }
1128
1129 /* This is an alternate form of monitor_read_memory which is used for monitors
1130 which can only read a single byte/word/etc. at a time. */
1131
1132 static int
1133 monitor_read_memory_single (memaddr, myaddr, len)
1134 CORE_ADDR memaddr;
1135 char *myaddr;
1136 int len;
1137 {
1138 unsigned int val;
1139 char membuf[sizeof(int) * 2 + 1];
1140 char *p;
1141 char *cmd;
1142 int i;
1143
1144 #if 0
1145 /* Can't actually use long longs (nice idea, though). In fact, the
1146 call to strtoul below will fail if it tries to convert a value
1147 that's too big to fit in a long. */
1148 if ((memaddr & 0x7) == 0 && len >= 8 && current_monitor->getmem.cmdll)
1149 {
1150 len = 8;
1151 cmd = current_monitor->getmem.cmdll;
1152 }
1153 else
1154 #endif
1155 if ((memaddr & 0x3) == 0 && len >= 4 && current_monitor->getmem.cmdl)
1156 {
1157 len = 4;
1158 cmd = current_monitor->getmem.cmdl;
1159 }
1160 else if ((memaddr & 0x1) == 0 && len >= 2 && current_monitor->getmem.cmdw)
1161 {
1162 len = 2;
1163 cmd = current_monitor->getmem.cmdw;
1164 }
1165 else
1166 {
1167 len = 1;
1168 cmd = current_monitor->getmem.cmdb;
1169 }
1170
1171 /* Send the examine command. */
1172
1173 monitor_printf (cmd, memaddr);
1174
1175 /* If RESP_DELIM is specified, we search for that as a leading delimiter for
1176 the register value. Otherwise, we just start searching from the start of
1177 the buf. */
1178
1179 if (current_monitor->getmem.resp_delim)
1180 monitor_expect_regexp (&getmem_resp_delim_pattern, NULL, 0);
1181
1182 /* Now, read the appropriate number of hex digits for this loc, skipping
1183 spaces. */
1184
1185 /* Skip leading spaces and "0x" if MO_HEX_PREFIX flag is set */
1186 if (current_monitor->flags & MO_HEX_PREFIX)
1187 {
1188 int c;
1189 c = readchar (timeout);
1190 while (c == ' ')
1191 c = readchar (timeout);
1192 if ((c == '0') && ((c = readchar (timeout)) == 'x'))
1193 ;
1194 else
1195 error ("monitor_read_memory_single (0x%x): bad response from monitor: %.*s%c.",
1196 memaddr, i, membuf, c);
1197 }
1198 for (i = 0; i < len * 2; i++)
1199 {
1200 int c;
1201
1202 while (1)
1203 {
1204 c = readchar (timeout);
1205 if (isxdigit (c))
1206 break;
1207 if (c == ' ')
1208 continue;
1209
1210 error ("monitor_read_memory_single (0x%x): bad response from monitor: %.*s%c.",
1211 memaddr, i, membuf, c);
1212 }
1213
1214 membuf[i] = c;
1215 }
1216
1217 membuf[i] = '\000'; /* terminate the number */
1218
1219 /* If TERM is present, we wait for that to show up. Also, (if TERM is
1220 present), we will send TERM_CMD if that is present. In any case, we collect
1221 all of the output into buf, and then wait for the normal prompt. */
1222
1223 if (current_monitor->getmem.term)
1224 {
1225 monitor_expect (current_monitor->getmem.term, NULL, 0); /* get response */
1226
1227 if (current_monitor->getmem.term_cmd)
1228 {
1229 monitor_printf (current_monitor->getmem.term_cmd);
1230 monitor_expect_prompt (NULL, 0);
1231 }
1232 }
1233 else
1234 monitor_expect_prompt (NULL, 0); /* get response */
1235
1236 p = membuf;
1237 val = strtoul (membuf, &p, 16);
1238
1239 if (val == 0 && membuf == p)
1240 error ("monitor_read_memory_single (0x%x): bad value from monitor: %s.",
1241 memaddr, membuf);
1242
1243 /* supply register stores in target byte order, so swap here */
1244
1245 store_unsigned_integer (myaddr, len, val);
1246
1247 return len;
1248 }
1249
1250 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's memory
1251 at MEMADDR. Returns length moved. Currently, we only do one byte at a
1252 time. */
1253
1254 static int
1255 monitor_read_memory (memaddr, myaddr, len)
1256 CORE_ADDR memaddr;
1257 char *myaddr;
1258 int len;
1259 {
1260 unsigned int val;
1261 unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
1262 char buf[512];
1263 char *p, *p1;
1264 char *name;
1265 int resp_len;
1266 int i;
1267
1268 if (current_monitor->flags & MO_GETMEM_READ_SINGLE)
1269 return monitor_read_memory_single (memaddr, myaddr, len);
1270
1271 len = min (len, 16);
1272
1273 /* See if xfer would cross a 16 byte boundary. If so, clip it. */
1274 if (((memaddr ^ (memaddr + len - 1)) & ~0xf) != 0)
1275 len = ((memaddr + len) & ~0xf) - memaddr;
1276
1277 /* send the memory examine command */
1278
1279 if (current_monitor->flags & MO_GETMEM_NEEDS_RANGE)
1280 monitor_printf (current_monitor->getmem.cmdb, memaddr, memaddr + len - 1);
1281 else
1282 monitor_printf (current_monitor->getmem.cmdb, memaddr, len);
1283
1284 /* If TERM is present, we wait for that to show up. Also, (if TERM is
1285 present), we will send TERM_CMD if that is present. In any case, we collect
1286 all of the output into buf, and then wait for the normal prompt. */
1287
1288 if (current_monitor->getmem.term)
1289 {
1290 resp_len = monitor_expect (current_monitor->getmem.term, buf, sizeof buf); /* get response */
1291
1292 if (resp_len <= 0)
1293 error ("monitor_read_memory (0x%x): excessive response from monitor: %.*s.",
1294 memaddr, resp_len, buf);
1295
1296 if (current_monitor->getmem.term_cmd)
1297 {
1298 SERIAL_WRITE (monitor_desc, current_monitor->getmem.term_cmd,
1299 strlen (current_monitor->getmem.term_cmd));
1300 monitor_expect_prompt (NULL, 0);
1301 }
1302 }
1303 else
1304 resp_len = monitor_expect_prompt (buf, sizeof buf); /* get response */
1305
1306 p = buf;
1307
1308 /* If RESP_DELIM is specified, we search for that as a leading delimiter for
1309 the values. Otherwise, we just start searching from the start of the buf.
1310 */
1311
1312 if (current_monitor->getmem.resp_delim)
1313 {
1314 int retval, tmp;
1315 struct re_registers resp_strings;
1316
1317 tmp = strlen (p);
1318 retval = re_search (&getmem_resp_delim_pattern, p, tmp, 0, tmp,
1319 &resp_strings);
1320
1321 if (retval < 0)
1322 error ("monitor_read_memory (0x%x): bad response from monitor: %.*s.",
1323 memaddr, resp_len, buf);
1324
1325 p += resp_strings.end[0];
1326 #if 0
1327 p = strstr (p, current_monitor->getmem.resp_delim);
1328 if (!p)
1329 error ("monitor_read_memory (0x%x): bad response from monitor: %.*s.",
1330 memaddr, resp_len, buf);
1331 p += strlen (current_monitor->getmem.resp_delim);
1332 #endif
1333 }
1334
1335 for (i = len; i > 0; i--)
1336 {
1337 /* Skip non-hex chars, but bomb on end of string and newlines */
1338
1339 while (1)
1340 {
1341 if (isxdigit (*p))
1342 break;
1343 if (*p == '\000' || *p == '\n' || *p == '\r')
1344 error ("monitor_read_memory (0x%x): badly terminated response from monitor: %.*s", memaddr, resp_len, buf);
1345 p++;
1346 }
1347
1348 val = strtoul (p, &p1, 16);
1349
1350 if (val == 0 && p == p1)
1351 error ("monitor_read_memory (0x%x): bad value from monitor: %.*s.", memaddr,
1352 resp_len, buf);
1353
1354 *myaddr++ = val;
1355
1356 if (i == 1)
1357 break;
1358
1359 p = p1;
1360 }
1361
1362 return len;
1363 }
1364
1365 static int
1366 monitor_xfer_memory (memaddr, myaddr, len, write, target)
1367 CORE_ADDR memaddr;
1368 char *myaddr;
1369 int len;
1370 int write;
1371 struct target_ops *target; /* ignored */
1372 {
1373 return dcache_xfer_memory (remote_dcache, memaddr, myaddr, len, write);
1374 }
1375
1376 static void
1377 monitor_kill ()
1378 {
1379 return; /* ignore attempts to kill target system */
1380 }
1381
1382 /* All we actually do is set the PC to the start address of exec_bfd, and start
1383 the program at that point. */
1384
1385 static void
1386 monitor_create_inferior (exec_file, args, env)
1387 char *exec_file;
1388 char *args;
1389 char **env;
1390 {
1391 if (args && (*args != '\000'))
1392 error ("Args are not supported by the monitor.");
1393
1394 first_time = 1;
1395 clear_proceed_status ();
1396 proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
1397 }
1398
1399 /* Clean up when a program exits.
1400 The program actually lives on in the remote processor's RAM, and may be
1401 run again without a download. Don't leave it full of breakpoint
1402 instructions. */
1403
1404 static void
1405 monitor_mourn_inferior ()
1406 {
1407 unpush_target (targ_ops);
1408 generic_mourn_inferior (); /* Do all the proper things now */
1409 }
1410
1411 #define NUM_MONITOR_BREAKPOINTS 8
1412
1413 static CORE_ADDR breakaddr[NUM_MONITOR_BREAKPOINTS] = {0};
1414
1415 /* Tell the monitor to add a breakpoint. */
1416
1417 static int
1418 monitor_insert_breakpoint (addr, shadow)
1419 CORE_ADDR addr;
1420 char *shadow;
1421 {
1422 int i;
1423 static unsigned char break_insn[] = BREAKPOINT;
1424
1425 for (i = 0; i < NUM_MONITOR_BREAKPOINTS; i++)
1426 {
1427 if (breakaddr[i] == 0)
1428 {
1429 breakaddr[i] = addr;
1430 monitor_read_memory (addr, shadow, sizeof (break_insn));
1431 monitor_printf (current_monitor->set_break, addr);
1432 monitor_expect_prompt (NULL, 0);
1433 return 0;
1434 }
1435 }
1436
1437 error ("Too many breakpoints (> %d) for monitor.", NUM_MONITOR_BREAKPOINTS);
1438 }
1439
1440 /* Tell the monitor to remove a breakpoint. */
1441
1442 static int
1443 monitor_remove_breakpoint (addr, shadow)
1444 CORE_ADDR addr;
1445 char *shadow;
1446 {
1447 int i;
1448
1449 for (i = 0; i < NUM_MONITOR_BREAKPOINTS; i++)
1450 {
1451 if (breakaddr[i] == addr)
1452 {
1453 breakaddr[i] = 0;
1454 /* some monitors remove breakpoints based on the address */
1455 if (current_monitor->flags & MO_CLR_BREAK_USES_ADDR)
1456 monitor_printf (current_monitor->clr_break, addr);
1457 else
1458 monitor_printf (current_monitor->clr_break, i);
1459 monitor_expect_prompt (NULL, 0);
1460 return 0;
1461 }
1462 }
1463 fprintf_unfiltered (stderr, "Can't find breakpoint associated with 0x%x\n", addr);
1464 return 1;
1465 }
1466
1467 /* monitor_wait_srec_ack -- wait for the target to send an acknowledgement for
1468 an S-record. Return non-zero if the ACK is received properly. */
1469
1470 static int
1471 monitor_wait_srec_ack ()
1472 {
1473 /* FIXME: eventually we'll want to be able to handle acknowledgements
1474 of something other than a '+' character. Right now this is only
1475 going to work for EST visionICE. */
1476 return readchar (timeout) == '+';
1477 }
1478
1479 /* monitor_load -- download a file. */
1480
1481 static void
1482 monitor_load (file, from_tty)
1483 char *file;
1484 int from_tty;
1485 {
1486 dcache_flush (remote_dcache);
1487
1488 if (current_monitor->load_routine)
1489 current_monitor->load_routine (monitor_desc, file, hashmark);
1490 else
1491 { /* The default is ascii S-records */
1492 monitor_printf (current_monitor->load);
1493 if (current_monitor->loadresp)
1494 monitor_expect (current_monitor->loadresp, NULL, 0);
1495
1496 /* FIXME Should add arg here for load_offset (already done for generic_load) */
1497 load_srec (monitor_desc, file, 32, SREC_ALL, hashmark,
1498 current_monitor->flags & MO_SREC_ACK ?
1499 monitor_wait_srec_ack : NULL);
1500
1501 monitor_expect_prompt (NULL, 0);
1502 }
1503
1504 /* Finally, make the PC point at the start address */
1505
1506 if (exec_bfd)
1507 write_pc (bfd_get_start_address (exec_bfd));
1508
1509 inferior_pid = 0; /* No process now */
1510
1511 /* This is necessary because many things were based on the PC at the time that
1512 we attached to the monitor, which is no longer valid now that we have loaded
1513 new code (and just changed the PC). Another way to do this might be to call
1514 normal_stop, except that the stack may not be valid, and things would get
1515 horribly confused... */
1516
1517 clear_symtab_users ();
1518 }
1519
1520 static void
1521 monitor_stop ()
1522 {
1523 if ((current_monitor->flags & MO_SEND_BREAK_ON_STOP) != 0)
1524 SERIAL_SEND_BREAK (monitor_desc);
1525 if (current_monitor->stop)
1526 monitor_printf_noecho (current_monitor->stop);
1527 }
1528
1529 /* Put a command string, in args, out to MONITOR. Output from MONITOR
1530 is placed on the users terminal until the prompt is seen. FIXME: We
1531 read the characters ourseleves here cause of a nasty echo. */
1532
1533 static void
1534 monitor_command (args, from_tty)
1535 char *args;
1536 int from_tty;
1537 {
1538 char *p;
1539 int resp_len;
1540 char buf[1000];
1541
1542 if (monitor_desc == NULL)
1543 error ("monitor target not open.");
1544
1545 p = current_monitor->prompt;
1546
1547 /* Send the command. Note that if no args were supplied, then we're
1548 just sending the monitor a newline, which is sometimes useful. */
1549
1550 monitor_printf ("%s\r", (args ? args : ""));
1551
1552 resp_len = monitor_expect_prompt (buf, sizeof buf);
1553
1554 fputs_unfiltered (buf, gdb_stdout); /* Output the response */
1555 }
1556
1557 /* Convert hex digit A to a number. */
1558
1559 static int
1560 from_hex (a)
1561 int a;
1562 {
1563 if (a >= '0' && a <= '9')
1564 return a - '0';
1565 if (a >= 'a' && a <= 'f')
1566 return a - 'a' + 10;
1567 if (a >= 'A' && a <= 'F')
1568 return a - 'A' + 10;
1569
1570 error ("Reply contains invalid hex digit 0x%x", a);
1571 }
1572
1573 static struct target_ops monitor_ops =
1574 {
1575 NULL, /* to_shortname */
1576 NULL, /* to_longname */
1577 NULL, /* to_doc */
1578 NULL, /* to_open */
1579 monitor_close, /* to_close */
1580 NULL, /* to_attach */
1581 monitor_detach, /* to_detach */
1582 monitor_resume, /* to_resume */
1583 monitor_wait, /* to_wait */
1584 monitor_fetch_registers, /* to_fetch_registers */
1585 monitor_store_registers, /* to_store_registers */
1586 monitor_prepare_to_store, /* to_prepare_to_store */
1587 monitor_xfer_memory, /* to_xfer_memory */
1588 monitor_files_info, /* to_files_info */
1589 monitor_insert_breakpoint, /* to_insert_breakpoint */
1590 monitor_remove_breakpoint, /* to_remove_breakpoint */
1591 0, /* to_terminal_init */
1592 0, /* to_terminal_inferior */
1593 0, /* to_terminal_ours_for_output */
1594 0, /* to_terminal_ours */
1595 0, /* to_terminal_info */
1596 monitor_kill, /* to_kill */
1597 monitor_load, /* to_load */
1598 0, /* to_lookup_symbol */
1599 monitor_create_inferior, /* to_create_inferior */
1600 monitor_mourn_inferior, /* to_mourn_inferior */
1601 0, /* to_can_run */
1602 0, /* to_notice_signals */
1603 0, /* to_thread_alive */
1604 monitor_stop, /* to_stop */
1605 process_stratum, /* to_stratum */
1606 0, /* to_next */
1607 1, /* to_has_all_memory */
1608 1, /* to_has_memory */
1609 1, /* to_has_stack */
1610 1, /* to_has_registers */
1611 1, /* to_has_execution */
1612 0, /* sections */
1613 0, /* sections_end */
1614 OPS_MAGIC /* to_magic */
1615 };
1616
1617 /* Init the target_ops structure pointed at by OPS */
1618
1619 void
1620 init_monitor_ops (ops)
1621 struct target_ops *ops;
1622 {
1623 memcpy (ops, &monitor_ops, sizeof monitor_ops);
1624 }
1625
1626 /* Define additional commands that are usually only used by monitors. */
1627
1628 void
1629 _initialize_remote_monitors ()
1630 {
1631 add_show_from_set (add_set_cmd ("hash", no_class, var_boolean,
1632 (char *)&hashmark,
1633 "Set display of activity while downloading a file.\n\
1634 When enabled, a hashmark \'#\' is displayed.",
1635 &setlist),
1636 &showlist);
1637
1638 add_com ("monitor", class_obscure, monitor_command,
1639 "Send a command to the debug monitor.");
1640 }