9f516a32d91e2a2d8fe1648ce72fb0d0ee324fea
[deliverable/binutils-gdb.git] / gdb / v850ice.c
1 /* ICE interface for the NEC V850 for GDB, the GNU debugger.
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
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,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "gdb_string.h"
24 #include "frame.h"
25 #include "symtab.h"
26 #include "inferior.h"
27 #include "breakpoint.h"
28 #include "symfile.h"
29 #include "target.h"
30 #include "objfiles.h"
31 #include "gdbcore.h"
32 #include "value.h"
33 #include "command.h"
34 #include "regcache.h"
35
36 #include <tcl.h>
37 #include <windows.h>
38 #include <winuser.h> /* for WM_USER */
39
40 extern unsigned long int strtoul (const char *nptr, char **endptr,
41 int base);
42
43 /* Local data definitions */
44 struct MessageIO
45 {
46 int size; /* length of input or output in bytes */
47 char *buf; /* buffer having the input/output information */
48 };
49
50 /* Prototypes for functions located in other files */
51 extern void break_command (char *, int);
52
53 extern int (*ui_loop_hook) (int);
54
55 /* Prototypes for local functions */
56 static int init_hidden_window (void);
57
58 static LRESULT CALLBACK v850ice_wndproc (HWND, UINT, WPARAM, LPARAM);
59
60 static void v850ice_files_info (struct target_ops *ignore);
61
62 static int v850ice_xfer_memory (CORE_ADDR memaddr, char *myaddr,
63 int len, int should_write,
64 struct target_ops *target);
65
66 static void v850ice_prepare_to_store (void);
67
68 static void v850ice_fetch_registers (int regno);
69
70 static void v850ice_resume (ptid_t ptid, int step,
71 enum target_signal siggnal);
72
73 static void v850ice_open (char *name, int from_tty);
74
75 static void v850ice_close (int quitting);
76
77 static void v850ice_stop (void);
78
79 static void v850ice_store_registers (int regno);
80
81 static void v850ice_mourn (void);
82
83 static ptid_t v850ice_wait (ptid_t ptid,
84 struct target_waitstatus *status);
85
86 static void v850ice_kill (void);
87
88 static void v850ice_detach (char *args, int from_tty);
89
90 static int v850ice_insert_breakpoint (CORE_ADDR, char *);
91
92 static int v850ice_remove_breakpoint (CORE_ADDR, char *);
93
94 static void v850ice_command (char *, int);
95
96 static int ice_disassemble (unsigned long, int, char *);
97
98 static int ice_lookup_addr (unsigned long *, char *, char *);
99
100 static int ice_lookup_symbol (unsigned long, char *);
101
102 static void ice_SimulateDisassemble (char *, int);
103
104 static void ice_SimulateAddrLookup (char *, int);
105
106 static void ice_Simulate_SymLookup (char *, int);
107
108 static void ice_fputs (const char *, struct ui_file *);
109
110 static int ice_file (char *);
111
112 static int ice_cont (char *);
113
114 static int ice_stepi (char *);
115
116 static int ice_nexti (char *);
117
118 static void togdb_force_update (void);
119
120 static void view_source (CORE_ADDR);
121
122 static void do_gdb (char *, char *, void (*func) (char *, int), int);
123
124
125 /* Globals */
126 static HWND hidden_hwnd; /* HWND for messages */
127
128 long (__stdcall * ExeAppReq) (char *, long, char *, struct MessageIO *);
129
130 long (__stdcall * RegisterClient) (HWND);
131
132 long (__stdcall * UnregisterClient) (void);
133
134 extern Tcl_Interp *gdbtk_interp;
135
136 /* Globals local to this file only */
137 static int ice_open = 0; /* Is ICE open? */
138
139 static char *v850_CB_Result; /* special char array for saving 'callback' results */
140
141 static int SimulateCallback; /* simulate a callback event */
142
143 #define MAX_BLOCK_SIZE 64*1024 /* Cannot transfer memory in blocks bigger
144 than this */
145 /* MDI/ICE Message IDs */
146 #define GSINGLESTEP 0x200 /* single-step target */
147 #define GRESUME 0x201 /* resume target */
148 #define GREADREG 0x202 /* read a register */
149 #define GWRITEREG 0x203 /* write a register */
150 #define GWRITEBLOCK 0x204 /* write a block of memory */
151 #define GREADBLOCK 0x205 /* read a block of memory */
152 #define GSETBREAK 0x206 /* set a breakpoint */
153 #define GREMOVEBREAK 0x207 /* remove a breakpoint */
154 #define GHALT 0x208 /* ??? */
155 #define GCHECKSTATUS 0x209 /* check status of ICE */
156 #define GMDIREPLY 0x210 /* Reply for previous query - NOT USED */
157 #define GDOWNLOAD 0x211 /* something for MDI */
158 #define GCOMMAND 0x212 /* execute command in ice */
159 #define GLOADFILENAME 0x213 /* retrieve load filename */
160 #define GWRITEMEM 0x214 /* write word, half-word, or byte */
161
162 /* GCHECKSTATUS return codes: */
163 #define ICE_Idle 0x00
164 #define ICE_Breakpoint 0x01 /* hit a breakpoint */
165 #define ICE_Stepped 0x02 /* have stepped */
166 #define ICE_Exception 0x03 /* have exception */
167 #define ICE_Halted 0x04 /* hit a user halt */
168 #define ICE_Exited 0x05 /* called exit */
169 #define ICE_Terminated 0x06 /* user terminated */
170 #define ICE_Running 0x07
171 #define ICE_Unknown 0x99
172
173 /* Windows messages */
174 #define WM_STATE_CHANGE WM_USER+101
175 #define WM_SYM_TO_ADDR WM_USER+102
176 #define WM_ADDR_TO_SYM WM_USER+103
177 #define WM_DISASSEMBLY WM_USER+104
178 #define WM_SOURCE WM_USER+105
179
180 /* STATE_CHANGE codes */
181 #define STATE_CHANGE_REGS 1 /* Register(s) changed */
182 #define STATE_CHANGE_LOAD 2 /* HW reset */
183 #define STATE_CHANGE_RESET 3 /* Load new file */
184 #define STATE_CHANGE_CONT 4 /* Run target */
185 #define STATE_CHANGE_STOP 5 /* Stop target */
186 #define STATE_CHANGE_STEPI 6 /* Stepi target */
187 #define STATE_CHANGE_NEXTI 7 /* Nexti target */
188
189 static struct target_ops v850ice_ops; /* Forward decl */
190
191 /* This function creates a hidden window */
192 static int
193 init_hidden_window (void)
194 {
195 WNDCLASS class;
196
197 if (hidden_hwnd != NULL)
198 return 1;
199
200 class.style = 0;
201 class.cbClsExtra = 0;
202 class.cbWndExtra = 0;
203 class.hInstance = GetModuleHandle (0);
204 class.hbrBackground = NULL;
205 class.lpszMenuName = NULL;
206 class.lpszClassName = "gdb_v850ice";
207 class.lpfnWndProc = v850ice_wndproc;
208 class.hIcon = NULL;
209 class.hCursor = NULL;
210
211 if (!RegisterClass (&class))
212 return 0;
213
214 hidden_hwnd = CreateWindow ("gdb_v850ice", "gdb_v850ice", WS_TILED,
215 0, 0, 0, 0, NULL, NULL, class.hInstance,
216 NULL);
217 if (hidden_hwnd == NULL)
218 {
219 char buf[200];
220 DWORD err;
221
222 err = GetLastError ();
223 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
224 0, buf, 200, NULL);
225 printf_unfiltered ("Could not create window: %s", buf);
226 return 0;
227 }
228
229 return 1;
230 }
231
232 /*
233 This function is installed as the message handler for the hidden window
234 which QBox will use to communicate with gdb. It recognize and acts
235 on the following messages:
236
237 WM_SYM_TO_ADDR \
238 WM_ADDR_TO_SYM | Not implemented at NEC's request
239 WM_DISASSEMBLY /
240 WM_STATE_CHANGE - tells us that a state change has occured in the ICE
241 */
242 static LRESULT CALLBACK
243 v850ice_wndproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
244 {
245 LRESULT result = FALSE;
246
247 switch (message)
248 {
249 case WM_SYM_TO_ADDR:
250 MessageBox (0, "Symbol resolution\nNot implemented", "GDB", MB_OK);
251 break;
252 case WM_ADDR_TO_SYM:
253 MessageBox (0, "Address resolution\nNot implemented", "GDB", MB_OK);
254 break;
255 case WM_SOURCE:
256 view_source ((CORE_ADDR) lParam);
257 break;
258 case WM_STATE_CHANGE:
259 switch (wParam)
260 {
261 case STATE_CHANGE_LOAD:
262 {
263 struct MessageIO iob;
264 char buf[128];
265
266 iob.buf = buf;
267 iob.size = 128;
268
269 /* Load in a new file... Need filename */
270 ExeAppReq ("GDB", GLOADFILENAME, NULL, &iob);
271 if (!catch_errors ((catch_errors_ftype *) ice_file, iob.buf, "", RETURN_MASK_ALL))
272 printf_unfiltered ("load errored\n");
273 }
274 break;
275 case STATE_CHANGE_RESET:
276 registers_changed ();
277 flush_cached_frames ();
278 togdb_force_update ();
279 result = TRUE;
280 break;
281 case STATE_CHANGE_REGS:
282 registers_changed ();
283 togdb_force_update ();
284 result = TRUE;
285 break;
286 case STATE_CHANGE_CONT:
287 if (!catch_errors ((catch_errors_ftype *) ice_cont, NULL, "", RETURN_MASK_ALL))
288 printf_unfiltered ("continue errored\n");
289 result = TRUE;
290 break;
291 case STATE_CHANGE_STEPI:
292 if (!catch_errors ((catch_errors_ftype *) ice_stepi, (int) lParam, "",
293 RETURN_MASK_ALL))
294 printf_unfiltered ("stepi errored\n");
295 result = TRUE;
296 break;
297 case STATE_CHANGE_NEXTI:
298 if (!catch_errors ((catch_errors_ftype *) ice_nexti, (int) lParam, "",
299 RETURN_MASK_ALL))
300 printf_unfiltered ("nexti errored\n");
301 result = TRUE;
302 break;
303 }
304 }
305
306 if (result == FALSE)
307 return DefWindowProc (hwnd, message, wParam, lParam);
308
309 return FALSE;
310 }
311
312 /* Code for opening a connection to the ICE. */
313
314 static void
315 v850ice_open (char *name, int from_tty)
316 {
317 HINSTANCE handle;
318
319 if (name)
320 error ("Too many arguments.");
321
322 target_preopen (from_tty);
323
324 unpush_target (&v850ice_ops);
325
326 if (from_tty)
327 puts_filtered ("V850ice debugging\n");
328
329 push_target (&v850ice_ops); /* Switch to using v850ice target now */
330
331 target_terminal_init ();
332
333 /* Initialize everything necessary to facilitate communication
334 between QBox, gdb, and the DLLs which control the ICE */
335 if (ExeAppReq == NULL)
336 {
337 handle = LoadLibrary ("necmsg.dll");
338 if (handle == NULL)
339 error ("Cannot load necmsg.dll");
340
341 ExeAppReq = (long (*) (char *, long, char *, struct MessageIO *))
342 GetProcAddress (handle, "ExeAppReq");
343 RegisterClient = (long (*) (HWND))
344 GetProcAddress (handle, "RegisterClient");
345 UnregisterClient = (long (*) (void))
346 GetProcAddress (handle, "UnregisterClient");
347
348 if (ExeAppReq == NULL || RegisterClient == NULL || UnregisterClient == NULL)
349 error ("Could not find requisite functions in necmsg.dll.");
350
351 if (!init_hidden_window ())
352 error ("could not initialize message handling");
353 }
354
355 /* Tell the DLL we are here */
356 RegisterClient (hidden_hwnd);
357
358 ice_open = 1;
359
360 /* Without this, some commands which require an active target (such as kill)
361 won't work. This variable serves (at least) double duty as both the pid
362 of the target process (if it has such), and as a flag indicating that a
363 target is active. These functions should be split out into seperate
364 variables, especially since GDB will someday have a notion of debugging
365 several processes. */
366 inferior_ptid = pid_to_ptid (42000);
367
368 start_remote ();
369 return;
370 }
371
372 /* Clean up connection to a remote debugger. */
373
374 static void
375 v850ice_close (int quitting)
376 {
377 if (ice_open)
378 {
379 UnregisterClient ();
380 ice_open = 0;
381 inferior_ptid = null_ptid;
382 }
383 }
384
385 /* Stop the process on the ice. */
386 static void
387 v850ice_stop (void)
388 {
389 /* This is silly, but it works... */
390 v850ice_command ("stop", 0);
391 }
392
393 static void
394 v850ice_detach (char *args, int from_tty)
395 {
396 if (args)
397 error ("Argument given to \"detach\" when remotely debugging.");
398
399 pop_target ();
400 if (from_tty)
401 puts_filtered ("Ending v850ice debugging.\n");
402 }
403
404 /* Tell the remote machine to resume. */
405
406 static void
407 v850ice_resume (ptid_t ptid, int step, enum target_signal siggnal)
408 {
409 long retval;
410 char buf[256];
411 struct MessageIO iob;
412
413 iob.size = 0;
414 iob.buf = buf;
415
416 if (step)
417 retval = ExeAppReq ("GDB", GSINGLESTEP, "step", &iob);
418 else
419 retval = ExeAppReq ("GDB", GRESUME, "run", &iob);
420
421 if (retval)
422 error ("ExeAppReq (step = %d) returned %d", step, retval);
423 }
424
425 /* Wait until the remote machine stops, then return,
426 storing status in STATUS just as `wait' would.
427 Returns "pid" (though it's not clear what, if anything, that
428 means in the case of this target). */
429
430 static ptid_t
431 v850ice_wait (ptid_t ptid, struct target_waitstatus *status)
432 {
433 long v850_status;
434 char buf[256];
435 struct MessageIO iob;
436 int done = 0;
437 int count = 0;
438
439 iob.size = 0;
440 iob.buf = buf;
441
442 do
443 {
444 if (count++ % 100000)
445 {
446 ui_loop_hook (0);
447 count = 0;
448 }
449
450 v850_status = ExeAppReq ("GDB", GCHECKSTATUS, NULL, &iob);
451
452 switch (v850_status)
453 {
454 case ICE_Idle:
455 case ICE_Breakpoint:
456 case ICE_Stepped:
457 case ICE_Halted:
458 status->kind = TARGET_WAITKIND_STOPPED;
459 status->value.sig = TARGET_SIGNAL_TRAP;
460 done = 1;
461 break;
462 case ICE_Exception:
463 status->kind = TARGET_WAITKIND_SIGNALLED;
464 status->value.sig = TARGET_SIGNAL_SEGV;
465 done = 1;
466 break;
467 case ICE_Exited:
468 status->kind = TARGET_WAITKIND_EXITED;
469 status->value.integer = 0;
470 done = 1;
471 break;
472 case ICE_Terminated:
473 status->kind = TARGET_WAITKIND_SIGNALLED;
474 status->value.sig = TARGET_SIGNAL_KILL;
475 done = 1;
476 break;
477 default:
478 break;
479 }
480 }
481 while (!done);
482
483 return inferior_ptid;
484 }
485
486 static int
487 convert_register (int regno, char *buf)
488 {
489 if (regno <= 31)
490 sprintf (buf, "r%d", regno);
491 else if (REGISTER_NAME (regno)[0] == 's'
492 && REGISTER_NAME (regno)[1] == 'r')
493 return 0;
494 else
495 sprintf (buf, "%s", REGISTER_NAME (regno));
496
497 return 1;
498 }
499
500 /* Read the remote registers into the block REGS. */
501 /* Note that the ICE returns register contents as ascii hex strings. We have
502 to convert that to an unsigned long, and then call store_unsigned_integer to
503 convert it to target byte-order if necessary. */
504
505 static void
506 v850ice_fetch_registers (int regno)
507 {
508 long retval;
509 char cmd[100];
510 char val[100];
511 struct MessageIO iob;
512 unsigned long regval;
513 char *p;
514
515 if (regno == -1)
516 {
517 for (regno = 0; regno < NUM_REGS; regno++)
518 v850ice_fetch_registers (regno);
519 return;
520 }
521
522 strcpy (cmd, "reg ");
523 if (!convert_register (regno, &cmd[4]))
524 return;
525
526 iob.size = sizeof val;
527 iob.buf = val;
528 retval = ExeAppReq ("GDB", GREADREG, cmd, &iob);
529 if (retval)
530 error ("1: ExeAppReq returned %d: cmd = %s", retval, cmd);
531
532 regval = strtoul (val, NULL, 16);
533 if (regval == 0 && p == val)
534 error ("v850ice_fetch_registers (%d): bad value from ICE: %s.",
535 regno, val);
536
537 store_unsigned_integer (val, DEPRECATED_REGISTER_RAW_SIZE (regno), regval);
538 supply_register (regno, val);
539 }
540
541 /* Store register REGNO, or all registers if REGNO == -1, from the contents
542 of REGISTERS. */
543
544 static void
545 v850ice_store_registers (int regno)
546 {
547 long retval;
548 char cmd[100];
549 unsigned long regval;
550 char buf[256];
551 struct MessageIO iob;
552 iob.size = 0;
553 iob.buf = buf;
554
555 if (regno == -1)
556 {
557 for (regno = 0; regno < NUM_REGS; regno++)
558 v850ice_store_registers (regno);
559 return;
560 }
561
562 regval = extract_unsigned_integer (&deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)],
563 DEPRECATED_REGISTER_RAW_SIZE (regno));
564 strcpy (cmd, "reg ");
565 if (!convert_register (regno, &cmd[4]))
566 return;
567 sprintf (cmd + strlen (cmd), "=0x%x", regval);
568
569 retval = ExeAppReq ("GDB", GWRITEREG, cmd, &iob);
570 if (retval)
571 error ("2: ExeAppReq returned %d: cmd = %s", retval, cmd);
572 }
573
574 /* Prepare to store registers. Nothing to do here, since the ICE can write one
575 register at a time. */
576
577 static void
578 v850ice_prepare_to_store (void)
579 {
580 }
581
582 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
583 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
584 nonzero. TARGET is unused. Returns length of data written or read;
585 0 for error.
586
587 We can only read/write MAX_BLOCK_SIZE bytes at a time, though, or the DLL
588 dies. */
589 static int
590 v850ice_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
591 int should_write, struct target_ops *target)
592 {
593 long retval;
594 char cmd[100];
595 struct MessageIO iob;
596 int sent;
597
598 if (should_write)
599 {
600 if (len == 4 || len == 2 || len == 1)
601 {
602 long value = 0;
603 char buf[256];
604 char c;
605
606 iob.size = 0;
607 iob.buf = buf;
608
609 sent = 0;
610 switch (len)
611 {
612 case 4:
613 c = 'w';
614 value |= (long) ((myaddr[3] << 24) & 0xff000000);
615 value |= (long) ((myaddr[2] << 16) & 0x00ff0000);
616 value |= (long) ((myaddr[1] << 8) & 0x0000ff00);
617 value |= (long) (myaddr[0] & 0x000000ff);
618 break;
619 case 2:
620 c = 'h';
621 value |= (long) ((myaddr[1] << 8) & 0xff00);
622 value |= (long) (myaddr[0] & 0x00ff);
623 break;
624 case 1:
625 c = 'b';
626 value |= (long) (myaddr[0] & 0xff);
627 break;
628 }
629
630 sprintf (cmd, "memory %c c 0x%x=0x%x", c, (int) memaddr, value);
631 retval = ExeAppReq ("GDB", GWRITEMEM, cmd, &iob);
632 if (retval == 0)
633 sent = len;
634 }
635 else
636 {
637 sent = 0;
638 do
639 {
640 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
641 iob.buf = myaddr;
642 sprintf (cmd, "memory b c 0x%x=0x00 l=%d", (int) memaddr, iob.size);
643 retval = ExeAppReq ("GDB", GWRITEBLOCK, cmd, &iob);
644 if (retval != 0)
645 break;
646 len -= iob.size;
647 memaddr += iob.size;
648 myaddr += iob.size;
649 sent += iob.size;
650 }
651 while (len > 0);
652 }
653 }
654 else
655 {
656 unsigned char *tmp;
657 unsigned char *t;
658 int i;
659
660 tmp = alloca (len + 100);
661 t = tmp;
662 memset (tmp + len, 0xff, 100);
663
664 sent = 0;
665 do
666 {
667 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
668 iob.buf = tmp;
669 sprintf (cmd, "memory b 0x%x l=%d", (int) memaddr, iob.size);
670 retval = ExeAppReq ("GDB", GREADBLOCK, cmd, &iob);
671 if (retval != 0)
672 break;
673 len -= iob.size;
674 memaddr += iob.size;
675 sent += iob.size;
676 tmp += iob.size;
677 }
678 while (len > 0);
679
680 if (retval == 0)
681 {
682 for (i = 0; i < 100; i++)
683 {
684 if (t[sent + i] != 0xff)
685 {
686 warning ("GREADBLOCK trashed bytes after transfer area.");
687 break;
688 }
689 }
690 memcpy (myaddr, t, sent);
691 }
692 }
693
694 if (retval != 0)
695 error ("3: ExeAppReq returned %d: cmd = %s", retval, cmd);
696
697 return sent;
698 }
699
700 static void
701 v850ice_files_info (struct target_ops *ignore)
702 {
703 puts_filtered ("Debugging a target via the NEC V850 ICE.\n");
704 }
705
706 static int
707 v850ice_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
708 {
709 long retval;
710 char cmd[100];
711 char buf[256];
712 struct MessageIO iob;
713
714 iob.size = 0;
715 iob.buf = buf;
716 sprintf (cmd, "%d, ", addr);
717
718 retval = ExeAppReq ("GDB", GSETBREAK, cmd, &iob);
719 if (retval)
720 error ("ExeAppReq (GSETBREAK) returned %d: cmd = %s", retval, cmd);
721
722 return 0;
723 }
724
725 static int
726 v850ice_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
727 {
728 long retval;
729 char cmd[100];
730 char buf[256];
731 struct MessageIO iob;
732
733 iob.size = 0;
734 iob.buf = buf;
735
736 sprintf (cmd, "%d, ", addr);
737
738 retval = ExeAppReq ("GDB", GREMOVEBREAK, cmd, &iob);
739 if (retval)
740 error ("ExeAppReq (GREMOVEBREAK) returned %d: cmd = %s", retval, cmd);
741
742 return 0;
743 }
744
745 static void
746 v850ice_kill (void)
747 {
748 target_mourn_inferior ();
749 inferior_ptid = null_ptid;
750 }
751
752 static void
753 v850ice_mourn (void)
754 {
755 }
756
757 static void
758 v850ice_load (char *filename, int from_tty)
759 {
760 struct MessageIO iob;
761 char buf[256];
762
763 iob.size = 0;
764 iob.buf = buf;
765 generic_load (filename, from_tty);
766 ExeAppReq ("GDB", GDOWNLOAD, filename, &iob);
767 }
768
769 static int
770 ice_file (char *arg)
771 {
772 char *s;
773
774 target_detach (NULL, 0);
775 pop_target ();
776
777 printf_unfiltered ("\n");
778
779 s = arg;
780 while (*s != '\0')
781 {
782 if (*s == '\\')
783 *s = '/';
784 s++;
785 }
786
787 /* Safegaurd against confusing the breakpoint routines... */
788 delete_command (NULL, 0);
789
790 /* Must supress from_tty, otherwise we could start asking if the
791 user really wants to load a new symbol table, etc... */
792 printf_unfiltered ("Reading symbols from %s...", arg);
793 exec_open (arg, 0);
794 symbol_file_add_main (arg, 0);
795 printf_unfiltered ("done\n");
796
797 /* exec_open will kill our target, so reinstall the ICE as
798 the target. */
799 v850ice_open (NULL, 0);
800
801 togdb_force_update ();
802 return 1;
803 }
804
805 static int
806 ice_cont (char *c)
807 {
808 printf_filtered ("continue (ice)\n");
809 ReplyMessage ((LRESULT) 1);
810
811 if (gdbtk_interp == NULL)
812 {
813 continue_command (NULL, 1);
814 }
815 else
816 Tcl_Eval (gdbtk_interp, "gdb_immediate continue");
817
818 return 1;
819 }
820
821 static void
822 do_gdb (char *cmd, char *str, void (*func) (char *, int), int count)
823 {
824 ReplyMessage ((LRESULT) 1);
825
826 while (count--)
827 {
828 printf_unfiltered (str);
829
830 if (gdbtk_interp == NULL)
831 {
832 func (NULL, 0);
833 }
834 else
835 Tcl_Eval (gdbtk_interp, cmd);
836 }
837 }
838
839
840 static int
841 ice_stepi (char *c)
842 {
843 int count = (int) c;
844
845 do_gdb ("gdb_immediate stepi", "stepi (ice)\n", stepi_command, count);
846 return 1;
847 }
848
849 static int
850 ice_nexti (char *c)
851 {
852 int count = (int) c;
853
854 do_gdb ("gdb_immediate nexti", "nexti (ice)\n", nexti_command, count);
855 return 1;
856 }
857
858 static void
859 v850ice_command (char *arg, int from_tty)
860 {
861 struct MessageIO iob;
862 char buf[256];
863
864 iob.buf = buf;
865 iob.size = 0;
866 ExeAppReq ("GDB", GCOMMAND, arg, &iob);
867 }
868
869 static void
870 togdb_force_update (void)
871 {
872 if (gdbtk_interp != NULL)
873 Tcl_Eval (gdbtk_interp, "gdbtk_update");
874 }
875
876 static void
877 view_source (CORE_ADDR addr)
878 {
879 char c[256];
880
881 if (gdbtk_interp != NULL)
882 {
883 sprintf (c, "catch {set src [lindex [ManagedWin::find SrcWin] 0]\n$src location BROWSE [gdb_loc *0x%x]}", addr);
884 Tcl_Eval (gdbtk_interp, c);
885 }
886 }
887
888 /* Define the target subroutine names */
889
890 static void
891 init_850ice_ops (void)
892 {
893 v850ice_ops.to_shortname = "ice";
894 v850ice_ops.to_longname = "NEC V850 ICE interface";
895 v850ice_ops.to_doc = "Debug a system controlled by a NEC 850 ICE.";
896 v850ice_ops.to_open = v850ice_open;
897 v850ice_ops.to_close = v850ice_close;
898 v850ice_ops.to_detach = v850ice_detach;
899 v850ice_ops.to_resume = v850ice_resume;
900 v850ice_ops.to_wait = v850ice_wait;
901 v850ice_ops.to_fetch_registers = v850ice_fetch_registers;
902 v850ice_ops.to_store_registers = v850ice_store_registers;
903 v850ice_ops.to_prepare_to_store = v850ice_prepare_to_store;
904 v850ice_ops.to_xfer_memory = v850ice_xfer_memory;
905 v850ice_ops.to_files_info = v850ice_files_info;
906 v850ice_ops.to_insert_breakpoint = v850ice_insert_breakpoint;
907 v850ice_ops.to_remove_breakpoint = v850ice_remove_breakpoint;
908 v850ice_ops.to_kill = v850ice_kill;
909 v850ice_ops.to_load = v850ice_load;
910 v850ice_ops.to_mourn_inferior = v850ice_mourn;
911 v850ice_ops.to_stop = v850ice_stop;
912 v850ice_ops.to_stratum = process_stratum;
913 v850ice_ops.to_has_all_memory = 1;
914 v850ice_ops.to_has_memory = 1;
915 v850ice_ops.to_has_stack = 1;
916 v850ice_ops.to_has_registers = 1;
917 v850ice_ops.to_has_execution = 1;
918 v850ice_ops.to_magic = OPS_MAGIC;
919 }
920
921 void
922 _initialize_v850ice (void)
923 {
924 init_850ice_ops ();
925 add_target (&v850ice_ops);
926
927 add_com ("ice", class_obscure, v850ice_command,
928 "Send command to ICE");
929 }
This page took 0.062723 seconds and 3 git commands to generate.