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