1 /* Convex stuff for GDB.
2 Copyright (C) 1990 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 #include <sys/param.h>
37 #include <sys/ioctl.h>
38 #include <sys/pcntl.h>
39 #include <sys/thread.h>
47 exec_file_command (filename, from_tty)
55 /* Eliminate all traces of old exec file.
56 Mark text segment as empty. */
73 /* Now open and digest the file the user requested, if any. */
77 filename = tilde_expand (filename);
78 make_cleanup (free, filename);
80 execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
83 perror_with_name (filename);
85 if (myread (execchan, &filehdr, sizeof filehdr) < 0)
86 perror_with_name (filename);
88 if (! IS_SOFF_MAGIC (filehdr.h_magic))
89 error ("%s: not an executable file.", filename);
91 if (myread (execchan, &opthdr, filehdr.h_opthdr) <= 0)
92 perror_with_name (filename);
94 /* Read through the section headers.
95 For text, data, etc, record an entry in the exec file map.
96 Record text_start and text_end. */
98 lseek (execchan, (long) filehdr.h_scnptr, 0);
100 for (n = 0; n < filehdr.h_nscns; n++)
102 if (myread (execchan, &scnhdr, sizeof scnhdr) < 0)
103 perror_with_name (filename);
105 if ((scnhdr.s_flags & S_TYPMASK) >= S_TEXT
106 && (scnhdr.s_flags & S_TYPMASK) <= S_COMON)
108 exec_map[n_exec].mem_addr = scnhdr.s_vaddr;
109 exec_map[n_exec].mem_end = scnhdr.s_vaddr + scnhdr.s_size;
110 exec_map[n_exec].file_addr = scnhdr.s_scnptr;
111 exec_map[n_exec].type = scnhdr.s_flags & S_TYPMASK;
114 if ((scnhdr.s_flags & S_TYPMASK) == S_TEXT)
116 text_start = scnhdr.s_vaddr;
117 text_end = scnhdr.s_vaddr + scnhdr.s_size;
122 fstat (execchan, &st_exec);
123 exec_mtime = st_exec.st_mtime;
128 printf_filtered ("No exec file now.\n");
130 /* Tell display code (if any) about the changed file name. */
131 if (exec_file_display_hook)
132 (*exec_file_display_hook) (filename);
135 /* Read data from SOFF exec or core file.
136 Return 0 on success, EIO if address out of bounds. */
139 xfer_core_file (memaddr, myaddr, len)
157 /* Determine which file the next bunch of addresses reside in,
158 and where in the file. Set the file's read/write pointer
159 to point at the proper place for the desired address
160 and set xferfile and xferchan for the correct file.
161 If desired address is nonexistent, leave them zero.
162 i is set to the number of bytes that can be handled
163 along with the next address. */
167 for (n = 0; n < n_core; n++)
169 if (memaddr >= core_map[n].mem_addr && memaddr < core_map[n].mem_end
170 && (core_map[n].thread == -1
171 || core_map[n].thread == inferior_thread))
173 i = min (len, core_map[n].mem_end - memaddr);
174 fileptr = core_map[n].file_addr + memaddr - core_map[n].mem_addr;
175 if (core_map[n].file_addr)
177 xferfile = &corefile;
182 else if (core_map[n].mem_addr >= memaddr
183 && core_map[n].mem_addr < memaddr + i)
184 i = core_map[n].mem_addr - memaddr;
188 for (n = 0; n < n_exec; n++)
190 if (memaddr >= exec_map[n].mem_addr
191 && memaddr < exec_map[n].mem_end)
193 i = min (len, exec_map[n].mem_end - memaddr);
194 fileptr = exec_map[n].file_addr + memaddr
195 - exec_map[n].mem_addr;
196 if (exec_map[n].file_addr)
198 xferfile = &execfile;
203 else if (exec_map[n].mem_addr >= memaddr
204 && exec_map[n].mem_addr < memaddr + i)
205 i = exec_map[n].mem_addr - memaddr;
208 /* Now we know which file to use.
209 Set up its pointer and transfer the data. */
213 if (xferfile == &execfile)
214 error ("No program file to examine.");
216 error ("No core dump file or running program to examine.");
217 val = lseek (xferchan, fileptr, 0);
219 perror_with_name (*xferfile);
220 val = myread (xferchan, myaddr, i);
222 perror_with_name (*xferfile);
224 /* If this address is for nonexistent memory,
225 read zeros if reading, or do nothing if writing. */
240 /* Here from info files command to print an address map. */
244 struct pmap ptrs[200];
247 /* ID strings for core and executable file sections */
249 static char *idstr[] =
251 "0", "text", "data", "tdata", "bss", "tbss",
252 "common", "ttext", "ctx", "tctx", "10", "11", "12",
255 for (n = 0; n < n_core; n++)
257 core_map[n].which = 0;
258 ptrs[n] = core_map[n];
260 for (n = 0; n < n_exec; n++)
262 exec_map[n].which = 1;
263 ptrs[n_core+n] = exec_map[n];
266 qsort (ptrs, n_core + n_exec, sizeof *ptrs, ptr_cmp);
268 for (n = 0; n < n_core + n_exec; n++)
270 struct pmap *p = &ptrs[n];
273 if (p->mem_addr < ptrs[n-1].mem_end)
274 p->mem_addr = ptrs[n-1].mem_end;
275 if (p->mem_addr >= p->mem_end)
278 printf_filtered ("%08x .. %08x %-6s %s\n",
279 p->mem_addr, p->mem_end, idstr[p->type],
280 p->which ? execfile : corefile);
284 /* Compare routine to put file sections in order.
285 Sort into increasing order on address, and put core file sections
286 before exec file sections if both files contain the same addresses. */
288 static ptr_cmp (a, b)
291 if (a->mem_addr != b->mem_addr) return a->mem_addr - b->mem_addr;
292 return a->which - b->which;
295 /* Trapped internal variables are used to handle special registers.
296 A trapped i.v. calls a hook here every time it is dereferenced,
297 to provide a new value for the variable, and it calls a hook here
298 when a new value is assigned, to do something with the value.
300 The vector registers are $vl, $vs, $vm, $vN, $VN (N in 0..7).
301 The communication registers are $cN, $CN (N in 0..63).
302 They not handled as regular registers because it's expensive to
303 read them, and their size varies, and they have too many names. */
306 /* Return 1 if NAME is a trapped internal variable, else 0. */
309 is_trapped_internalvar (name)
312 if ((name[0] == 'c' || name[0] == 'C')
313 && name[1] >= '0' && name[1] <= '9'
315 || (name[2] >= '0' && name[2] <= '9'
316 && name[3] == '\0' && name[1] != '0'))
317 && atoi (&name[1]) < 64) return 1;
319 if ((name[0] == 'v' || name[0] == 'V')
320 && (((name[1] & -8) == '0' && name[2] == '\0')
321 || !strcmp (name, "vl")
322 || !strcmp (name, "vs")
323 || !strcmp (name, "vm")))
328 /* Return the value of trapped internal variable VAR */
331 value_of_trapped_internalvar (var)
332 struct internalvar *var;
334 char *name = var->name;
337 long len = *read_vector_register (VL_REGNUM);
338 if (len <= 0 || len > 128) len = 128;
340 if (!strcmp (name, "vl"))
342 val = value_from_long (builtin_type_int,
343 (LONGEST) *read_vector_register_1 (VL_REGNUM));
345 else if (!strcmp (name, "vs"))
347 val = value_from_long (builtin_type_int,
348 (LONGEST) *read_vector_register_1 (VS_REGNUM));
350 else if (!strcmp (name, "vm"))
354 bcopy (read_vector_register_1 (VM_REGNUM), vm, sizeof vm);
355 type = vector_type (builtin_type_int, len);
356 val = allocate_value (type);
357 p = (long *) VALUE_CONTENTS (val);
358 for (i = 0; i < len; i++)
359 *p++ = !! (vm[3 - (i >> 5)] & (1 << (i & 037)));
361 else if (name[0] == 'V')
363 type = vector_type (builtin_type_long_long, len);
364 val = allocate_value (type);
365 bcopy (read_vector_register_1 (name[1] - '0'),
366 VALUE_CONTENTS (val), TYPE_LENGTH (type));
368 else if (name[0] == 'v')
371 type = vector_type (builtin_type_long, len);
372 val = allocate_value (type);
373 p1 = read_vector_register_1 (name[1] - '0');
374 p2 = (long *) VALUE_CONTENTS (val);
375 while (--len >= 0) {p1++; *p2++ = *p1++;}
378 else if (name[0] == 'c')
379 val = value_from_long (builtin_type_int,
380 read_comm_register (atoi (&name[1])));
381 else if (name[0] == 'C')
382 val = value_from_long (builtin_type_long_long,
383 read_comm_register (atoi (&name[1])));
385 VALUE_LVAL (val) = lval_internalvar;
386 VALUE_INTERNALVAR (val) = var;
390 /* Construct the type for a vector register's value --
391 array[LENGTH] of ELEMENT_TYPE. */
394 vector_type (element_type, length)
395 struct type *element_type;
398 struct type *type = (struct type *) xmalloc (sizeof (struct type));
399 bzero (type, sizeof type);
400 TYPE_CODE (type) = TYPE_CODE_ARRAY;
401 TYPE_TARGET_TYPE (type) = element_type;
402 TYPE_LENGTH (type) = length * TYPE_LENGTH (TYPE_TARGET_TYPE (type));
406 /* Handle a new value assigned to a trapped internal variable */
409 set_trapped_internalvar (var, val, bitpos, bitsize, offset)
410 struct internalvar *var;
412 int bitpos, bitsize, offset;
414 char *name = var->name;
415 long long newval = value_as_long (val);
417 if (!strcmp (name, "vl"))
418 write_vector_register (VL_REGNUM, 0, newval);
419 else if (!strcmp (name, "vs"))
420 write_vector_register (VS_REGNUM, 0, newval);
421 else if (name[0] == 'c' || name[0] == 'C')
422 write_comm_register (atoi (&name[1]), newval);
423 else if (!strcmp (name, "vm"))
424 error ("can't assign to $vm");
427 offset /= bitsize / 8;
428 write_vector_register (name[1] - '0', offset, newval);
432 /* Print an integer value when no format was specified. gdb normally
433 prints these values in decimal, but the the leading 0x80000000 of
434 pointers produces intolerable 10-digit negative numbers.
435 If it looks like an address, print it in hex instead. */
437 decout (stream, type, val)
444 switch (output_radix)
447 if ((lv == val || (unsigned) lv == val)
448 && ((lv & 0xf0000000) == 0x80000000
449 || ((lv & 0xf0000000) == 0xf0000000 && lv < STACK_END_ADDR)))
451 fprintf_filtered (stream, "%#x", lv);
456 fprintf_filtered (stream, TYPE_UNSIGNED (type) ? "%llu" : "%lld", val);
460 if (TYPE_LENGTH (type) <= sizeof lv)
461 fprintf_filtered (stream, "%#o", lv);
463 fprintf_filtered (stream, "%#llo", val);
467 if (TYPE_LENGTH (type) <= sizeof lv)
468 fprintf_filtered (stream, "%#x", lv);
470 fprintf_filtered (stream, "%#llx", val);
475 /* Change the default output radix to 10 or 16, or set it to 0 (heuristic).
476 This command is mostly obsolete now that the print command allows
477 formats to apply to aggregates, but is still handy occasionally. */
480 set_base_command (arg)
489 new_radix = atoi (arg);
490 if (new_radix != 10 && new_radix != 16 && new_radix != 8)
491 error ("base must be 8, 10 or 16, or null");
492 else output_radix = new_radix;
496 /* Turn pipelining on or off in the inferior. */
499 set_pipelining_command (arg)
504 sequential = !sequential;
505 printf_filtered ("%s\n", sequential ? "off" : "on");
507 else if (!strcmp (arg, "on"))
509 else if (!strcmp (arg, "off"))
511 else error ("valid args are `on', to allow instructions to overlap, or\n\
512 `off', to prevent it and thereby pinpoint exceptions.");
515 /* Enable, disable, or force parallel execution in the inferior. */
518 set_parallel_command (arg)
522 int prevparallel = parallel;
524 if (!strncmp (arg, "fixed", strlen (arg)))
526 else if (!strcmp (arg, "on"))
528 else if (!strcmp (arg, "off"))
530 else error ("valid args are `on', to allow multiple threads, or\n\
531 `fixed', to force multiple threads, or\n\
532 `off', to run with one thread only.");
534 if ((prevparallel == 0) != (parallel == 0) && inferior_pid)
535 printf_filtered ("will take effect at next run.\n");
537 getrlimit (RLIMIT_CONCUR, &rl);
538 rl.rlim_cur = parallel ? rl.rlim_max : 1;
539 setrlimit (RLIMIT_CONCUR, &rl);
542 set_fixed_scheduling (inferior_pid, parallel == 2);
545 /* Add a new name for an existing command. */
551 static char *aliaserr = "usage is `alias NEW OLD', no args allowed";
553 struct cmd_list_element *new, *old;
556 error_no_arg ("newname oldname");
558 new = lookup_cmd (&arg, cmdlist, "", -1);
559 if (new && !strncmp (newname, new->name, strlen (new->name)))
563 || (*arg >= 'a' && *arg <= 'z')
564 || (*arg >= 'A' && *arg <= 'Z')
565 || (*arg >= '0' && *arg <= '9')))
572 || (*arg >= 'a' && *arg <= 'z')
573 || (*arg >= 'A' && *arg <= 'Z')
574 || (*arg >= '0' && *arg <= '9'))
576 if (*arg != ' ' && *arg != '\t')
582 old = lookup_cmd (&arg, cmdlist, "", 0);
587 if (new && !strncmp (newname, new->name, strlen (new->name)))
590 if (new->class == (int) class_user || new->class == (int) class_alias)
591 tem = "Redefine command \"%s\"? ";
593 tem = "Really redefine built-in command \"%s\"? ";
594 if (!query (tem, new->name))
595 error ("Command \"%s\" not redefined.", new->name);
598 add_com (newname, class_alias, old->function, old->doc);
603 /* Print the current thread number, and any threads with signals in the
610 if (have_inferior_p ())
612 ps.pi_buffer = (char *) &comm_registers;
613 ps.pi_nbytes = sizeof comm_registers;
615 ps.pi_thread = inferior_thread;
616 ioctl (inferior_fd, PIXRDCREGS, &ps);
619 printf_filtered ("Current thread %d stopped with signal %d.%d (%s).\n",
620 inferior_thread, stop_signal, stop_sigcode,
621 subsig_name (stop_signal, stop_sigcode));
623 for (p = signal_stack; p->pid; p--)
624 printf_filtered ("Thread %d stopped with signal %d.%d (%s).\n",
625 p->thread, p->signo, p->subsig,
626 subsig_name (p->signo, p->subsig));
628 if (iscrlbit (comm_registers.crctl.lbits.cc, 64+13))
629 printf_filtered ("New thread start pc %#x\n",
630 (long) (comm_registers.crreg.pcpsw >> 32));
633 /* Return string describing a signal.subcode number */
636 subsig_name (signo, subcode)
639 static char *subsig4[] = {
640 "error exit", "privileged instruction", "unknown",
641 "unknown", "undefined opcode",
643 static char *subsig5[] = {0,
644 "breakpoint", "single step", "fork trap", "exec trap", "pfork trap",
645 "join trap", "idle trap", "last thread", "wfork trap",
646 "process breakpoint", "trap instruction",
648 static char *subsig8[] = {0,
649 "int overflow", "int divide check", "float overflow",
650 "float divide check", "float underflow", "reserved operand",
651 "sqrt error", "exp error", "ln error", "sin error", "cos error",
653 static char *subsig10[] = {0,
654 "invalid inward ring address", "invalid outward ring call",
655 "invalid inward ring return", "invalid syscall gate",
656 "invalid rtn frame length", "invalid comm reg address",
659 static char *subsig11[] = {0,
660 "read access denied", "write access denied", "execute access denied",
661 "segment descriptor fault", "page table fault", "data reference fault",
662 "i/o access denied", "levt pte invalid",
665 static char **subsig_list[] =
666 {0, 0, 0, 0, subsig4, subsig5, 0, 0, subsig8, 0, subsig10, subsig11, 0};
669 char *p = signo < NSIG ? sys_siglist[signo] : "unknown";
671 if (signo >= (sizeof subsig_list / sizeof *subsig_list)
672 || !subsig_list[signo])
674 for (i = 1; subsig_list[signo][i]; i++)
676 return subsig_list[signo][subcode];
681 /* Print a compact display of thread status, essentially x/i $pc
682 for all active threads. */
689 for (t = 0; t < n_threads; t++)
690 if (thread_state[t] == PI_TALIVE)
692 printf_filtered ("%d%c %08x%c %d.%d ", t,
693 (t == inferior_thread ? '*' : ' '), thread_pc[t],
694 (thread_is_in_kernel[t] ? '#' : ' '),
695 thread_signal[t], thread_sigcode[t]);
696 print_insn (thread_pc[t], stdout);
697 printf_filtered ("\n");
701 /* Change the current thread to ARG. */
703 set_thread_command (arg)
714 thread = parse_and_eval_address (arg);
716 if (thread < 0 || thread > n_threads || thread_state[thread] != PI_TALIVE)
717 error ("no such thread.");
719 select_thread (thread);
721 stop_pc = read_pc ();
722 flush_cached_frames ();
723 set_current_frame (create_new_frame (read_register (FP_REGNUM),
725 select_frame (get_current_frame (), 0);
729 /* Here on CONT command; gdb's dispatch address is changed to come here.
730 Set global variable ALL_CONTINUE to tell resume() that it should
731 start up all threads, and that a thread switch will not blow gdb's
735 convex_cont_command (proc_count_exp, from_tty)
736 char *proc_count_exp;
740 cont_command (proc_count_exp, from_tty);
743 /* Here on 1CONT command. Resume only the current thread. */
745 one_cont_command (proc_count_exp, from_tty)
746 char *proc_count_exp;
749 cont_command (proc_count_exp, from_tty);
752 /* Print the contents and lock bits of all communication registers,
753 or just register ARG if ARG is a communication register,
754 or the 3-word resource structure in memory at address ARG. */
756 comm_registers_info (arg)
763 if (sscanf (arg, "0x%x", ®num) == 1
764 || sscanf (arg, "%d", ®num) == 1)
769 else if (sscanf (arg, "$c%d", ®num) == 1)
771 else if (sscanf (arg, "$C%d", ®num) == 1)
774 regnum = parse_and_eval_address (arg);
777 error ("%s: invalid register name.", arg);
779 /* if we got a (user) address, examine the resource struct there */
784 read_memory (regnum, buf, sizeof buf);
785 printf_filtered ("%08x %08x%08x%s\n", regnum, buf[1], buf[2],
786 buf[0] & 0xff ? " locked" : "");
791 ps.pi_buffer = (char *) &comm_registers;
792 ps.pi_nbytes = sizeof comm_registers;
794 ps.pi_thread = inferior_thread;
795 ioctl (inferior_fd, PIXRDCREGS, &ps);
797 for (i = 0; i < 64; i++)
798 if (!arg || i == regnum)
799 printf_filtered ("%2d 0x8%03x %016llx%s\n", i, i,
800 comm_registers.crreg.r4[i],
801 (iscrlbit (comm_registers.crctl.lbits.cc, i)
818 static struct pswbit pswbit[] =
820 { 0x80000000, -1, "A carry" },
821 { 0x40000000, -1, "A integer overflow" },
822 { 0x20000000, -1, "A zero divide" },
823 { 0x10000000, -1, "Integer overflow enable" },
824 { 0x08000000, -1, "Trace" },
825 { 0x06000000, 25, "Frame length" },
826 { 0x01000000, -1, "Sequential" },
827 { 0x00800000, -1, "S carry" },
828 { 0x00400000, -1, "S integer overflow" },
829 { 0x00200000, -1, "S zero divide" },
830 { 0x00100000, -1, "Zero divide enable" },
831 { 0x00080000, -1, "Floating underflow" },
832 { 0x00040000, -1, "Floating overflow" },
833 { 0x00020000, -1, "Floating reserved operand" },
834 { 0x00010000, -1, "Floating zero divide" },
835 { 0x00008000, -1, "Floating error enable" },
836 { 0x00004000, -1, "Floating underflow enable" },
837 { 0x00002000, -1, "IEEE" },
838 { 0x00001000, -1, "Sequential stores" },
839 { 0x00000800, -1, "Intrinsic error" },
840 { 0x00000400, -1, "Intrinsic error enable" },
841 { 0x00000200, -1, "Trace thread creates" },
842 { 0x00000100, -1, "Thread init trap" },
843 { 0x000000e0, 5, "Reserved" },
844 { 0x0000001f, 0, "Intrinsic error code" },
852 psw = parse_and_eval_address (arg);
854 psw = read_register (PS_REGNUM);
856 for (p = pswbit; p->bit; p++)
859 printf_filtered ("%08x %s %s\n", p->bit,
860 (psw & p->bit) ? "yes" : "no ", p->text);
862 printf_filtered ("%08x %3d %s\n", p->bit,
863 (psw & p->bit) >> p->pos, p->text);
867 _initialize_convex_dep ()
869 add_com ("alias", class_support, alias_command,
870 "Add a new name for an existing command.");
872 add_cmd ("base", class_vars, set_base_command,
873 "Change the integer output radix to 8, 10 or 16\n\
874 or use just `set base' with no args to return to the ad-hoc default,\n\
875 which is 16 for integers that look like addresses, 10 otherwise.",
878 add_cmd ("pipeline", class_run, set_pipelining_command,
879 "Enable or disable overlapped execution of instructions.\n\
880 With `set pipe off', exceptions are reported with\n\
881 $pc pointing at the instruction after the faulting one.\n\
882 The default is `set pipe on', which runs faster.",
885 add_cmd ("parallel", class_run, set_parallel_command,
886 "Enable or disable multi-threaded execution of parallel code.\n\
887 `set parallel off' means run the program on a single CPU.\n\
888 `set parallel fixed' means run the program with all CPUs assigned to it.\n\
889 `set parallel on' means run the program on any CPUs that are available.",
892 add_com ("1cont", class_run, one_cont_command,
893 "Continue the program, activating only the current thread.\n\
894 Args are the same as the `cont' command.");
896 add_com ("thread", class_run, set_thread_command,
897 "Change the current thread, the one under scrutiny and control.\n\
898 With no arg, show the active threads, the current one marked with *.");
900 add_info ("threads", thread_info,
901 "List status of active threads.");
903 add_info ("comm-registers", comm_registers_info,
904 "List communication registers and their contents.\n\
905 A communication register name as argument means describe only that register.\n\
906 An address as argument means describe the resource structure at that address.\n\
907 `Locked' means that the register has been sent to but not yet received from.");
909 add_info ("psw", psw_info,
910 "Display $ps, the processor status word, bit by bit.\n\
911 An argument means display that value's interpretation as a psw.");
913 add_cmd ("convex", no_class, 0, "Convex-specific commands.\n\
914 32-bit registers $pc $ps $sp $ap $fp $a1-5 $s0-7 $v0-7 $vl $vs $vm $c0-63\n\
915 64-bit registers $S0-7 $V0-7 $C0-63\n\
917 info threads display info on stopped threads waiting to signal\n\
918 thread display list of active threads\n\
919 thread N select thread N (its registers, stack, memory, etc.)\n\
920 step, next, etc step selected thread only\n\
921 1cont continue selected thread only\n\
922 cont continue all threads\n\
923 info comm-registers display contents of comm register(s) or a resource struct\n\
924 info psw display processor status word $ps\n\
925 set base N change integer radix used by `print' without a format\n\
926 set pipeline off exceptions are precise, $pc points after the faulting insn\n\
927 set pipeline on normal mode, $pc is somewhere ahead of faulting insn\n\
928 set parallel off program runs on a single CPU\n\
929 set parallel fixed all CPUs are assigned to the program\n\
930 set parallel on normal mode, parallel execution on random available CPUs\n\