gdb-3.4
[deliverable/binutils-gdb.git] / gdb / convex-dep.c
CommitLineData
4187119d 1/* Convex stuff for GDB.
2 Copyright (C) 1989 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6GDB is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GDB is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GDB; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
e91b87a3 19
20#include "defs.h"
21#include "param.h"
4187119d 22#include "command.h"
23#include "symtab.h"
24#include "value.h"
e91b87a3 25#include "frame.h"
26#include "inferior.h"
4187119d 27#include "wait.h"
e91b87a3 28
29#include <stdio.h>
4187119d 30#include <signal.h>
31#include <fcntl.h>
32#include <a.out.h>
33
e91b87a3 34#include <sys/param.h>
35#include <sys/dir.h>
e91b87a3 36#include <sys/user.h>
37#include <sys/ioctl.h>
4187119d 38#include <sys/pcntl.h>
39#include <sys/thread.h>
40#include <sys/proc.h>
e91b87a3 41#include <sys/file.h>
42#include <sys/stat.h>
4187119d 43#include <sys/mman.h>
e91b87a3 44
4187119d 45#include <convex/vmparam.h>
46#include <convex/filehdr.h>
47#include <convex/opthdr.h>
48#include <convex/scnhdr.h>
49#include <convex/core.h>
e91b87a3 50
4187119d 51/* Per-thread data, read from the inferior at each stop and written
52 back at each resume. */
e91b87a3 53
4187119d 54/* Number of active threads.
55 Tables are valid for thread numbers less than this. */
e91b87a3 56
4187119d 57static int n_threads;
e91b87a3 58
4187119d 59#define MAXTHREADS 8
60
61/* Thread state. The remaining data is valid only if this is PI_TALIVE. */
e91b87a3 62
4187119d 63static int thread_state[MAXTHREADS];
e91b87a3 64
4187119d 65/* Stop pc, signal, signal subcode */
e91b87a3 66
4187119d 67static int thread_pc[MAXTHREADS];
68static int thread_signal[MAXTHREADS];
69static int thread_sigcode[MAXTHREADS];
e91b87a3 70
4187119d 71/* Thread registers.
72 If thread is selected, the regs are in registers[] instead. */
e91b87a3 73
4187119d 74static char thread_regs[MAXTHREADS][REGISTER_BYTES];
e91b87a3 75
4187119d 76/* 1 if the top frame on the thread's stack was a context frame,
77 meaning that the kernel is up to something and we should not
78 touch the thread at all except to resume it. */
e91b87a3 79
4187119d 80static char thread_is_in_kernel[MAXTHREADS];
e91b87a3 81
4187119d 82/* The currently selected thread's number. */
83
84static int inferior_thread;
85
86/* Inferior process's file handle and a process control block
87 to feed args to ioctl with. */
88
89static int inferior_fd;
90static struct pcntl ps;
91
92/* SOFF file headers for exec or core file. */
93
94static FILEHDR filehdr;
95static OPTHDR opthdr;
96static SCNHDR scnhdr;
97
98/* Address maps constructed from section headers of exec and core files.
99 Defines process address -> file address translation. */
100
101struct pmap
e91b87a3 102{
4187119d 103 long mem_addr; /* process start address */
104 long mem_end; /* process end+1 address */
105 long file_addr; /* file start address */
106 long thread; /* -1 shared; 0,1,... thread-local */
107 long type; /* S_TEXT S_DATA S_BSS S_TBSS etc */
108 long which; /* used to sort map for info files */
109};
e91b87a3 110
4187119d 111static int n_exec, n_core;
112static struct pmap exec_map[100];
113static struct pmap core_map[100];
e91b87a3 114
4187119d 115/* Offsets in the core file of core_context and core_tcontext blocks. */
116
117static int context_offset;
118static int tcontext_offset[MAXTHREADS];
119
120/* Core file control blocks. */
121
122static struct core_context_v70 c;
123static struct core_tcontext_v70 tc;
124static struct user u;
125static thread_t th;
126static proc_t pr;
127
128/* The registers of the currently selected thread. */
129
130extern char registers[REGISTER_BYTES];
131
132/* Vector and communication registers from core dump or from inferior.
133 These are read on demand, ie, not normally valid. */
134
135static struct vecst vector_registers;
136static struct creg_ctx comm_registers;
137
138/* Flag, set on a vanilla CONT command and cleared when the inferior
139 is continued. */
140
141static int all_continue;
142
143/* Flag, set when the inferior is continued by a vanilla CONT command,
144 cleared if it is continued for any other purpose. */
145
146static int thread_switch_ok;
147
148/* Stack of signals recieved from threads but not yet delivered to gdb. */
149
150struct threadpid
e91b87a3 151{
4187119d 152 int pid;
153 int thread;
154 int signo;
155 int subsig;
156 int pc;
157};
e91b87a3 158
4187119d 159static struct threadpid signal_stack_bot[100];
160static struct threadpid *signal_stack = signal_stack_bot;
e91b87a3 161
4187119d 162/* How to detect empty stack -- bottom frame is all zero. */
e91b87a3 163
4187119d 164#define signal_stack_is_empty() (signal_stack->pid == 0)
e91b87a3 165
4187119d 166/* Mode controlled by SET PIPE command, controls the psw SEQ bit
167 which forces each instruction to complete before the next one starts. */
e91b87a3 168
4187119d 169static int sequential = 0;
e91b87a3 170
4187119d 171/* Mode controlled by the SET PARALLEL command. Values are:
172 0 concurrency limit 1 thread, dynamic scheduling
173 1 no concurrency limit, dynamic scheduling
174 2 no concurrency limit, fixed scheduling */
e91b87a3 175
4187119d 176static int parallel = 1;
e91b87a3 177
4187119d 178/* Mode controlled by SET BASE command, output radix for unformatted
179 integer typeout, as in argument lists, aggregates, and so on.
180 Zero means guess whether it's an address (hex) or not (decimal). */
181
182static int output_radix = 0;
183
184/* Signal subcode at last thread stop. */
e91b87a3 185
4187119d 186static int stop_sigcode;
187
188/* Hack, see wait() below. */
189
190static int exec_trap_timer;
191
192/* Chain containing all defined commands. */
193
194extern struct cmd_list_element *cmdlist;
195
196/* Chain containing all defined set subcommands */
197
198extern struct cmd_list_element *setlist;
e91b87a3 199
200/* Hook for `exec_file_command' command to call. */
201
202extern void (*exec_file_display_hook) ();
203
204/* File names of core file and executable file. */
205
206extern char *corefile;
207extern char *execfile;
208
209/* Descriptors on which core file and executable file are open.
210 Note that the execchan is closed when an inferior is created
211 and reopened if the inferior dies or is killed. */
212
213extern int corechan;
214extern int execchan;
215
216/* Last modification time of executable file.
217 Also used in source.c to compare against mtime of a source file. */
218
219extern int exec_mtime;
220
4187119d 221/* Virtual addresses of bounds of the two areas of memory in the core file.
222 NB: These variables are set to plausible but useless values on convex. */
223
e91b87a3 224
225extern CORE_ADDR data_start;
226extern CORE_ADDR data_end;
227extern CORE_ADDR stack_start;
228extern CORE_ADDR stack_end;
229
230/* Virtual addresses of bounds of two areas of memory in the exec file.
4187119d 231 NB: Only text_start and text_end have meaningful values on convex. */
e91b87a3 232
233extern CORE_ADDR text_start;
234extern CORE_ADDR text_end;
235
236extern CORE_ADDR exec_data_start;
237extern CORE_ADDR exec_data_end;
238
239/* Address in executable file of start of text area data. */
240
241extern int text_offset;
242
243/* Address in executable file of start of data area data. */
244
245extern int exec_data_offset;
246
247/* Address in core file of start of data area data. */
248
249extern int data_offset;
250
251/* Address in core file of start of stack area data. */
252
253extern int stack_offset;
254
e91b87a3 255/* a.out header saved in core file. */
256
4187119d 257extern struct exec core_aouthdr;
e91b87a3 258
259/* a.out header of exec file. */
260
4187119d 261extern struct exec exec_aouthdr;
262
263/* Routine to check for exec-core mismatch. */
e91b87a3 264
265extern void validate_files ();
e91b87a3 266
4187119d 267/* Nonzero if we are debugging an attached outside process
268 rather than an inferior. */
e91b87a3 269
4187119d 270extern int attach_flag;
e91b87a3 271
e91b87a3 272
e91b87a3 273
4187119d 274static struct type *vector_type ();
275static long *read_vector_register ();
276static long *read_vector_register_1 ();
277static void write_vector_register ();
278static REGISTER_TYPE read_comm_register ();
279static void write_comm_register ();
280static void convex_cont_command ();
281static void thread_continue ();
282static void select_thread ();
283static void scan_stack ();
284static void set_fixed_scheduling ();
285static char *subsig_name ();
286static void psw_info ();
287static sig_noop ();
288static ptr_cmp ();
e91b87a3 289
4187119d 290extern char *sys_siglist[];
291extern int errno;
292\f
293/* Execute ptrace. Convex V7 replaced ptrace with pattach.
294 Allow ptrace (0) as a no-op. */
e91b87a3 295
4187119d 296int
297call_ptrace (request, pid, procaddr, buf)
298 int request, pid, procaddr, buf;
299{
300 if (request == 0)
301 return;
302 error ("no ptrace");
303}
e91b87a3 304
4187119d 305/* Replacement for system execle routine.
306 Convert it to an equivalent exect, which pattach insists on. */
e91b87a3 307
4187119d 308execle (name, argv)
309 char *name, *argv;
310{
311 char ***envp = (char ***) &argv;
312 while (*envp++) ;
e91b87a3 313
4187119d 314 signal (SIGTRAP, sig_noop);
315 exect (name, &argv, *envp);
316}
e91b87a3 317
4187119d 318/* Stupid handler for stupid trace trap that otherwise causes
319 startup to stupidly hang. */
e91b87a3 320
4187119d 321static sig_noop ()
322{}
e91b87a3 323
4187119d 324/* Read registers from inferior into registers[] array.
325 For convex, they are already there, read in when the inferior stops. */
e91b87a3 326
4187119d 327void
328fetch_inferior_registers ()
329{
330}
e91b87a3 331
4187119d 332/* Store our register values back into the inferior.
333 For Convex, do this only once, right before resuming inferior. */
e91b87a3 334
4187119d 335store_inferior_registers (regno)
336 int regno;
337{
338}
e91b87a3 339
4187119d 340/* Copy LEN bytes from inferior's memory starting at MEMADDR
341 to debugger memory starting at MYADDR.
342 On failure (cannot read from inferior, usually because address is out
343 of bounds) returns the value of errno. */
e91b87a3 344
4187119d 345int
346read_inferior_memory (memaddr, myaddr, len)
347 CORE_ADDR memaddr;
348 char *myaddr;
349 int len;
350{
351 errno = 0;
352 while (len > 0)
353 {
354 /* little-known undocumented max request size */
355 int i = (len < 12288) ? len : 12288;
e91b87a3 356
4187119d 357 lseek (inferior_fd, memaddr, 0);
358 read (inferior_fd, myaddr, i);
e91b87a3 359
4187119d 360 memaddr += i;
361 myaddr += i;
362 len -= i;
e91b87a3 363 }
4187119d 364 if (errno)
365 bzero (myaddr, len);
366 return errno;
e91b87a3 367}
e91b87a3 368
4187119d 369/* Copy LEN bytes of data from debugger memory at MYADDR
370 to inferior's memory at MEMADDR.
371 Returns errno on failure (cannot write the inferior) */
e91b87a3 372
4187119d 373int
374write_inferior_memory (memaddr, myaddr, len)
375 CORE_ADDR memaddr;
376 char *myaddr;
377 int len;
378{
379 errno = 0;
380 lseek (inferior_fd, memaddr, 0);
381 write (inferior_fd, myaddr, len);
382 return errno;
383}
e91b87a3 384
4187119d 385/* Here from create_inferior when the inferior process has been created
386 and started up. We must do a pattach to grab it for debugging.
e91b87a3 387
4187119d 388 Also, intercept the CONT command by altering its dispatch address. */
e91b87a3 389
4187119d 390create_inferior_hook (pid)
391 int pid;
392{
393 static char cont[] = "cont";
394 static char cont1[] = "c";
395 char *linep = cont;
396 char *linep1 = cont1;
397 char **line = &linep;
398 char **line1 = &linep1;
399 struct cmd_list_element *c;
400
401 c = lookup_cmd (line, cmdlist, "", 0);
402 c->function = convex_cont_command;
403 c = lookup_cmd (line1, cmdlist, "", 0);
404 c->function = convex_cont_command;
405
406 inferior_fd = pattach (pid, O_EXCL);
407 if (inferior_fd < 0)
408 perror_with_name ("pattach");
409 inferior_thread = 0;
410 set_fixed_scheduling (pid, parallel == 2);
411}
e91b87a3 412
4187119d 413/* Attach process PID for debugging. */
e91b87a3 414
4187119d 415attach (pid)
416 int pid;
417{
418 int fd = pattach (pid, O_EXCL);
419 if (fd < 0)
420 perror_with_name ("pattach");
421 attach_flag = 1;
422 /* wait for strange kernel reverberations to go away */
423 sleep (1);
424
425 setpgrp (pid, pid);
426
427 inferior_fd = fd;
428 inferior_thread = 0;
429 return pid;
430}
e91b87a3 431
4187119d 432/* Stop debugging the process whose number is PID
433 and continue it with signal number SIGNAL.
434 SIGNAL = 0 means just continue it. */
e91b87a3 435
4187119d 436void
437detach (signal)
438 int signal;
439{
440 signal_stack = signal_stack_bot;
441 thread_continue (-1, 0, signal);
442 ioctl (inferior_fd, PIXDETACH, &ps);
443 close (inferior_fd);
444 inferior_fd = 0;
445 attach_flag = 0;
446}
e91b87a3 447
4187119d 448/* Kill off the inferior process. */
e91b87a3 449
4187119d 450kill_inferior ()
451{
452 if (remote_debugging)
453 return;
454 if (inferior_pid == 0)
455 return;
456 ioctl (inferior_fd, PIXTERMINATE, 0);
457 wait (0);
458 inferior_died ();
459}
460
461/* This is used when GDB is exiting. It gives less chance of error.*/
462
463kill_inferior_fast ()
464{
465 if (remote_debugging)
466 return;
467 if (inferior_pid == 0)
468 return;
469 ioctl (inferior_fd, PIXTERMINATE, 0);
470 wait (0);
471}
472
473/* Read vector register REG, and return a pointer to the value. */
474
475static long *
476read_vector_register (reg)
477 int reg;
478{
479 if (have_inferior_p ())
480 {
481 errno = 0;
482 ps.pi_buffer = (char *) &vector_registers;
483 ps.pi_nbytes = sizeof vector_registers;
484 ps.pi_offset = 0;
485 ps.pi_thread = inferior_thread;
486 ioctl (inferior_fd, PIXRDVREGS, &ps);
487 if (errno)
488 bzero (&vector_registers, sizeof vector_registers);
489 }
490 else if (corechan >= 0)
491 {
492 lseek (corechan, tcontext_offset[inferior_thread], 0);
493 if (myread (corechan, &tc, sizeof tc) < 0)
494 perror_with_name (corefile);
495 lseek (corechan, tc.core_thread_p, 0);
496 if (myread (corechan, &th, sizeof th) < 0)
497 perror_with_name (corefile);
498 lseek (corechan, tc.core_vregs_p, 0);
499 if (myread (corechan, &vector_registers, 16*128) < 0)
500 perror_with_name (corefile);
501 vector_registers.vm[0] = th.t_vect_ctx.vc_vm[0];
502 vector_registers.vm[1] = th.t_vect_ctx.vc_vm[1];
503 vector_registers.vls = th.t_vect_ctx.vc_vls;
504 }
505
506 return read_vector_register_1 (reg);
507}
508
509/* Return a pointer to vector register REG, which must already have been
510 fetched from the inferior or core file. */
511
512static long *
513read_vector_register_1 (reg)
514 int reg;
515{
516 switch (reg)
517 {
518 case VM_REGNUM:
519 return (long *) vector_registers.vm;
520 case VS_REGNUM:
521 return (long *) &vector_registers.vls;
522 case VL_REGNUM:
523 return 1 + (long *) &vector_registers.vls;
524 default:
525 return (long *) &vector_registers.vr[reg];
526 }
527}
528
529/* Write vector register REG, element ELEMENT, new value VAL.
530 NB: must use read-modify-write on the entire vector state,
531 since pattach does not do offsetted writes correctly. */
532
533static void
534write_vector_register (reg, element, val)
535 int reg, element;
536 REGISTER_TYPE val;
537{
538 if (have_inferior_p ())
539 {
540 errno = 0;
541 ps.pi_thread = inferior_thread;
542 ps.pi_offset = 0;
543 ps.pi_buffer = (char *) &vector_registers;
544 ps.pi_nbytes = sizeof vector_registers;
545
546 ioctl (inferior_fd, PIXRDVREGS, &ps);
547
548 switch (reg)
549 {
550 case VL_REGNUM:
551 vector_registers.vls =
552 (vector_registers.vls & 0xffffffff00000000LL)
553 + (unsigned long) val;
554 break;
555
556 case VS_REGNUM:
557 vector_registers.vls =
558 (val << 32) + (unsigned long) vector_registers.vls;
559 break;
560
561 default:
562 vector_registers.vr[reg].el[element] = val;
563 break;
564 }
565
566 ioctl (inferior_fd, PIXWRVREGS, &ps);
567
568 if (errno)
569 perror_with_name ("writing vector register");
570 }
571}
572
573/* Return the contents of communication register NUM. */
574
575static REGISTER_TYPE
576read_comm_register (num)
577 int num;
578{
579 if (have_inferior_p ())
580 {
581 ps.pi_buffer = (char *) &comm_registers;
582 ps.pi_nbytes = sizeof comm_registers;
583 ps.pi_offset = 0;
584 ps.pi_thread = inferior_thread;
585 ioctl (inferior_fd, PIXRDCREGS, &ps);
586 }
587 return comm_registers.crreg.r4[num];
588}
589
590/* Store a new value VAL into communication register NUM.
591 NB: Must use read-modify-write on the whole comm register set
592 since pattach does not do offsetted writes correctly. */
593
594static void
595write_comm_register (num, val)
596 int num;
597 REGISTER_TYPE val;
598{
599 if (have_inferior_p ())
600 {
601 ps.pi_buffer = (char *) &comm_registers;
602 ps.pi_nbytes = sizeof comm_registers;
603 ps.pi_offset = 0;
604 ps.pi_thread = inferior_thread;
605 ioctl (inferior_fd, PIXRDCREGS, &ps);
606 comm_registers.crreg.r4[num] = val;
607 ioctl (inferior_fd, PIXWRCREGS, &ps);
608 }
609}
610
611/* Resume execution of the inferior process.
612 If STEP is nonzero, single-step it.
613 If SIGNAL is nonzero, give it that signal. */
614
615void
616resume (step, signal)
617 int step;
618 int signal;
619{
620 errno = 0;
621 if (remote_debugging)
622 remote_resume (step, signal);
623 else
624 if (step || signal)
625 thread_continue (inferior_thread, step, signal);
626 else
627 thread_continue (-1, 0, 0);
628}
629
630/* Maybe resume some threads.
631 THREAD is which thread to resume, or -1 to resume them all.
632 STEP and SIGNAL are as in resume.
633
634 Global variable ALL_CONTINUE is set when we are here to do a
635 `cont' command; otherwise we may be doing `finish' or a call or
636 something else that will not tolerate an automatic thread switch.
637
638 If there are stopped threads waiting to deliver signals, and
639 ALL_CONTINUE, do not actually resume anything. gdb will do a wait
640 and see one of the stopped threads in the queue. */
641
642static void
643thread_continue (thread, step, signal)
644 int thread, step, signal;
645{
646 int n;
647
648 /* If we are to continue all threads, but not for the CONTINUE command,
649 pay no attention and continue only the selected thread. */
650
651 if (thread < 0 && ! all_continue)
652 thread = inferior_thread;
653
654 /* If we are not stepping, we have now executed the continue part
655 of a CONTINUE command. */
656
657 if (! step)
658 all_continue = 0;
659
660 /* Allow wait() to switch threads if this is an all-out continue. */
661
662 thread_switch_ok = thread < 0;
663
664 /* If there are threads queued up, don't resume. */
665
666 if (thread_switch_ok && ! signal_stack_is_empty ())
667 return;
668
669 /* OK, do it. */
670
671 for (n = 0; n < n_threads; n++)
672 if (thread_state[n] == PI_TALIVE)
673 {
674 select_thread (n);
675
676 if ((thread < 0 || n == thread) && ! thread_is_in_kernel[n])
677 {
678 /* Blam the trace bits in the stack's saved psws to match
679 the desired step mode. This is required so that
680 single-stepping a return doesn't restore a psw with a
681 clear trace bit and fly away, and conversely,
682 proceeding through a return in a routine that was
683 stepped into doesn't cause a phantom break by restoring
684 a psw with the trace bit set. */
685 scan_stack (PSW_T_BIT, step);
686 scan_stack (PSW_S_BIT, sequential);
687 }
688
689 ps.pi_buffer = registers;
690 ps.pi_nbytes = REGISTER_BYTES;
691 ps.pi_offset = 0;
692 ps.pi_thread = n;
693 if (! thread_is_in_kernel[n])
694 if (ioctl (inferior_fd, PIXWRREGS, &ps))
695 perror_with_name ("PIXWRREGS");
696
697 if (thread < 0 || n == thread)
698 {
699 ps.pi_pc = 1;
700 ps.pi_signo = signal;
701 if (ioctl (inferior_fd, step ? PIXSTEP : PIXCONTINUE, &ps) < 0)
702 perror_with_name ("PIXCONTINUE");
703 }
704 }
705
706 if (ioctl (inferior_fd, PIXRUN, &ps) < 0)
707 perror_with_name ("PIXRUN");
708}
709
710/* Replacement for system wait routine.
711
712 The system wait returns with one or more threads stopped by
713 signals. Put stopped threads on a stack and return them one by
714 one, so that it appears that wait returns one thread at a time.
715
716 Global variable THREAD_SWITCH_OK is set when gdb can tolerate wait
717 returning a new thread. If it is false, then only one thread is
718 running; we will do a real wait, the thread will do something, and
719 we will return that. */
720
721wait (w)
722 union wait *w;
723{
724 int pid;
725
726 if (!w)
727 return wait3 (0, 0, 0);
728
729 /* Do a real wait if we were told to, or if there are no queued threads. */
730
731 if (! thread_switch_ok || signal_stack_is_empty ())
732 {
733 int thread;
734
735 pid = wait3 (w, 0, 0);
736
737 if (!WIFSTOPPED (*w) || pid != inferior_pid)
738 return pid;
739
740 /* The inferior has done something and stopped. Read in all the
741 threads' registers, and queue up any signals that happened. */
742
743 if (ioctl (inferior_fd, PIXGETTHCOUNT, &ps) < 0)
744 perror_with_name ("PIXGETTHCOUNT");
745
746 n_threads = ps.pi_othdcnt;
747 for (thread = 0; thread < n_threads; thread++)
748 {
749 ps.pi_thread = thread;
750 if (ioctl (inferior_fd, PIXGETSUBCODE, &ps) < 0)
751 perror_with_name ("PIXGETSUBCODE");
752 thread_state[thread] = ps.pi_otstate;
753
754 if (ps.pi_otstate == PI_TALIVE)
755 {
756 select_thread (thread);
757 ps.pi_buffer = registers;
758 ps.pi_nbytes = REGISTER_BYTES;
759 ps.pi_offset = 0;
760 ps.pi_thread = thread;
761 if (ioctl (inferior_fd, PIXRDREGS, &ps) < 0)
762 perror_with_name ("PIXRDREGS");
763
764 thread_pc[thread] = read_pc ();
765 thread_signal[thread] = ps.pi_osigno;
766 thread_sigcode[thread] = ps.pi_osigcode;
767
768 /* If the thread's stack has a context frame
769 on top, something fucked is going on. I do not
770 know what, but do I know this: the only thing you
771 can do with such a thread is continue it. */
772
773 thread_is_in_kernel[thread] =
774 ((read_register (PS_REGNUM) >> 25) & 3) == 0;
775
776 /* Signals push an extended frame and then fault
777 with a ridiculous pc. Pop the frame. */
778
779 if (thread_pc[thread] > STACK_END_ADDR)
e91b87a3 780 {
4187119d 781 POP_FRAME;
782 if (is_break_pc (thread_pc[thread]))
783 thread_pc[thread] = read_pc () - 2;
784 else
785 thread_pc[thread] = read_pc ();
786 write_register (PC_REGNUM, thread_pc[thread]);
e91b87a3 787 }
4187119d 788
789 if (ps.pi_osigno || ps.pi_osigcode)
e91b87a3 790 {
4187119d 791 signal_stack++;
792 signal_stack->pid = pid;
793 signal_stack->thread = thread;
794 signal_stack->signo = thread_signal[thread];
795 signal_stack->subsig = thread_sigcode[thread];
796 signal_stack->pc = thread_pc[thread];
e91b87a3 797 }
4187119d 798
799 /* The following hackery is caused by a unix 7.1 feature:
800 the inferior's fixed scheduling mode is cleared when
801 it execs the shell (since the shell is not a parallel
802 program). So, note the 5.4 trap we get when
803 the shell does its exec, then catch the 5.0 trap
804 that occurs when the debuggee starts, and set fixed
805 scheduling mode properly. */
806
807 if (ps.pi_osigno == 5 && ps.pi_osigcode == 4)
808 exec_trap_timer = 1;
809 else
810 exec_trap_timer--;
811
812 if (ps.pi_osigno == 5 && exec_trap_timer == 0)
813 set_fixed_scheduling (pid, parallel == 2);
814 }
815 }
816
817 if (signal_stack_is_empty ())
818 error ("no active threads?!");
819 }
820
821 /* Select the thread that stopped, and return *w saying why. */
822
823 select_thread (signal_stack->thread);
824
825 stop_signal = signal_stack->signo;
826 stop_sigcode = signal_stack->subsig;
827
828 WSETSTOP (*w, signal_stack->signo);
829 w->w_thread = signal_stack->thread;
830 return (signal_stack--)->pid;
831}
832
833/* Select thread THREAD -- its registers, stack, per-thread memory.
834 This is the only routine that may assign to inferior_thread
835 or thread_regs[]. */
836
837static void
838select_thread (thread)
839 int thread;
840{
841 if (thread == inferior_thread)
842 return;
843
844 bcopy (registers, thread_regs[inferior_thread], REGISTER_BYTES);
845 ps.pi_thread = inferior_thread = thread;
846 if (have_inferior_p ())
847 ioctl (inferior_fd, PISETRWTID, &ps);
848 bcopy (thread_regs[thread], registers, REGISTER_BYTES);
849}
850
851/* Routine to set or clear a psw bit in the psw and also all psws
852 saved on the stack. Quits when we get to a frame in which the
853 saved psw is correct. */
854
855static void
856scan_stack (bit, val)
857 long bit, val;
858{
859 long ps = read_register (PS_REGNUM);
860 long fp;
861 if (val ? !(ps & bit) : (ps & bit))
862 {
863 ps ^= bit;
864 write_register (PS_REGNUM, ps);
865
866 fp = read_register (FP_REGNUM);
867 while (fp & 0x80000000)
868 {
869 ps = read_memory_integer (fp + 4, 4);
870 if (val ? (ps & bit) : !(ps & bit))
871 break;
872 ps ^= bit;
873 write_memory (fp + 4, &ps, 4);
874 fp = read_memory_integer (fp + 8, 4);
875 }
876 }
877}
878
879/* Set fixed scheduling (alliant mode) of process PID to ARG (0 or 1). */
880
881static void
882set_fixed_scheduling (pid, arg)
883 int arg;
884{
885 struct pattributes pattr;
886 getpattr (pid, &pattr);
887 pattr.pattr_pfixed = arg;
888 setpattr (pid, &pattr);
889}
890\f
891core_file_command (filename, from_tty)
892 char *filename;
893 int from_tty;
894{
895 int n;
896
897 /* Discard all vestiges of any previous core file
898 and mark data and stack spaces as empty. */
899
900 if (corefile)
901 free (corefile);
902 corefile = 0;
903
904 if (corechan >= 0)
905 close (corechan);
906 corechan = -1;
907
908 data_start = 0;
909 data_end = 0;
910 stack_start = STACK_END_ADDR;
911 stack_end = STACK_END_ADDR;
912 n_core = 0;
913
914 /* Now, if a new core file was specified, open it and digest it. */
915
916 if (filename)
917 {
918 filename = tilde_expand (filename);
919 make_cleanup (free, filename);
920
921 if (have_inferior_p ())
922 error ("To look at a core file, you must kill the inferior with \"kill\".");
923 corechan = open (filename, O_RDONLY, 0);
924 if (corechan < 0)
925 perror_with_name (filename);
926
927 if (myread (corechan, &filehdr, sizeof filehdr) < 0)
928 perror_with_name (filename);
929
930 if (!IS_CORE_SOFF_MAGIC (filehdr.h_magic))
931 error ("%s: not a core file.\n", filename);
932
933 if (myread (corechan, &opthdr, filehdr.h_opthdr) < 0)
934 perror_with_name (filename);
935
936 /* Read through the section headers.
937 For text, data, etc, record an entry in the core file map.
938 For context and tcontext, record the file address of
939 the context blocks. */
940
941 lseek (corechan, (long) filehdr.h_scnptr, 0);
942
943 n_threads = 0;
944 for (n = 0; n < filehdr.h_nscns; n++)
945 {
946 if (myread (corechan, &scnhdr, sizeof scnhdr) < 0)
947 perror_with_name (filename);
948 if ((scnhdr.s_flags & S_TYPMASK) >= S_TEXT
949 && (scnhdr.s_flags & S_TYPMASK) <= S_COMON)
950 {
951 core_map[n_core].mem_addr = scnhdr.s_vaddr;
952 core_map[n_core].mem_end = scnhdr.s_vaddr + scnhdr.s_size;
953 core_map[n_core].file_addr = scnhdr.s_scnptr;
954 core_map[n_core].type = scnhdr.s_flags & S_TYPMASK;
955 if (core_map[n_core].type != S_TBSS
956 && core_map[n_core].type != S_TDATA
957 && core_map[n_core].type != S_TTEXT)
958 core_map[n_core].thread = -1;
959 else if (n_core == 0
960 || core_map[n_core-1].mem_addr != scnhdr.s_vaddr)
961 core_map[n_core].thread = 0;
962 else
963 core_map[n_core].thread = core_map[n_core-1].thread + 1;
964 n_core++;
e91b87a3 965 }
4187119d 966 else if ((scnhdr.s_flags & S_TYPMASK) == S_CONTEXT)
967 context_offset = scnhdr.s_scnptr;
968 else if ((scnhdr.s_flags & S_TYPMASK) == S_TCONTEXT)
969 tcontext_offset[n_threads++] = scnhdr.s_scnptr;
e91b87a3 970 }
4187119d 971
972 /* Read the context block, struct user, struct proc,
973 and the comm regs. */
974
975 lseek (corechan, context_offset, 0);
976 if (myread (corechan, &c, sizeof c) < 0)
977 perror_with_name (filename);
978 lseek (corechan, c.core_user_p, 0);
979 if (myread (corechan, &u, sizeof u) < 0)
980 perror_with_name (filename);
981 lseek (corechan, c.core_proc_p, 0);
982 if (myread (corechan, &pr, sizeof pr) < 0)
983 perror_with_name (filename);
984 comm_registers = pr.p_creg;
985
986 /* Core file apparently is really there. Make it really exist
987 for xfer_core_file so we can do read_memory on it. */
988
989 if (filename[0] == '/')
990 corefile = savestring (filename, strlen (filename));
e91b87a3 991 else
4187119d 992 corefile = concat (current_directory, "/", filename);
993
994 printf_filtered ("Program %s ", u.u_comm);
995
996 /* Read the thread registers and fill in the thread_xxx[] data. */
997
998 for (n = 0; n < n_threads; n++)
999 {
1000 select_thread (n);
1001
1002 lseek (corechan, tcontext_offset[n], 0);
1003 if (myread (corechan, &tc, sizeof tc) < 0)
1004 perror_with_name (corefile);
1005 lseek (corechan, tc.core_thread_p, 0);
1006 if (myread (corechan, &th, sizeof th) < 0)
1007 perror_with_name (corefile);
1008
1009 lseek (corechan, tc.core_syscall_context_p, 0);
1010 if (myread (corechan, registers, REGISTER_BYTES) < 0)
1011 perror_with_name (corefile);
1012
1013 thread_signal[n] = th.t_cursig;
1014 thread_sigcode[n] = th.t_code;
1015 thread_state[n] = th.t_state;
1016 thread_pc[n] = read_pc ();
1017
1018 if (thread_pc[n] > STACK_END_ADDR)
1019 {
1020 POP_FRAME;
1021 if (is_break_pc (thread_pc[n]))
1022 thread_pc[n] = read_pc () - 2;
1023 else
1024 thread_pc[n] = read_pc ();
1025 write_register (PC_REGNUM, thread_pc[n]);
1026 }
1027
1028 printf_filtered ("thread %d received signal %d, %s\n",
1029 n, thread_signal[n],
1030 thread_signal[n] < NSIG
1031 ? sys_siglist[thread_signal[n]]
1032 : "(undocumented)");
e91b87a3 1033 }
e91b87a3 1034
4187119d 1035 /* Select an interesting thread -- also-rans died with SIGKILL,
1036 so find one that didn't. */
1037
1038 for (n = 0; n < n_threads; n++)
1039 if (thread_signal[n] != 0 && thread_signal[n] != SIGKILL)
1040 {
1041 select_thread (n);
1042 stop_signal = thread_signal[n];
1043 stop_sigcode = thread_sigcode[n];
1044 break;
1045 }
1046
1047 core_aouthdr.a_magic = 0;
1048
1049 flush_cached_frames ();
1050 set_current_frame (create_new_frame (read_register (FP_REGNUM),
1051 read_pc ()));
1052 select_frame (get_current_frame (), 0);
e91b87a3 1053 validate_files ();
4187119d 1054
1055 print_sel_frame (1);
e91b87a3 1056 }
1057 else if (from_tty)
4187119d 1058 printf_filtered ("No core file now.\n");
1059}
1060
1061exec_file_command (filename, from_tty)
1062 char *filename;
1063 int from_tty;
1064{
1065 int val;
1066 int n;
1067 struct stat st_exec;
1068
1069 /* Eliminate all traces of old exec file.
1070 Mark text segment as empty. */
1071
1072 if (execfile)
1073 free (execfile);
1074 execfile = 0;
1075 data_start = 0;
1076 data_end = 0;
1077 text_start = 0;
1078 text_end = 0;
1079 exec_data_start = 0;
1080 exec_data_end = 0;
1081 if (execchan >= 0)
1082 close (execchan);
1083 execchan = -1;
1084
1085 n_exec = 0;
1086
1087 /* Now open and digest the file the user requested, if any. */
1088
1089 if (filename)
1090 {
1091 filename = tilde_expand (filename);
1092 make_cleanup (free, filename);
1093
1094 execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
1095 &execfile);
1096 if (execchan < 0)
1097 perror_with_name (filename);
1098
1099 if (myread (execchan, &filehdr, sizeof filehdr) < 0)
1100 perror_with_name (filename);
1101
1102 if (! IS_SOFF_MAGIC (filehdr.h_magic))
1103 error ("%s: not an executable file.", filename);
1104
1105 if (myread (execchan, &opthdr, filehdr.h_opthdr) <= 0)
1106 perror_with_name (filename);
1107
1108 /* Read through the section headers.
1109 For text, data, etc, record an entry in the exec file map.
1110 Record text_start and text_end. */
1111
1112 lseek (execchan, (long) filehdr.h_scnptr, 0);
1113
1114 for (n = 0; n < filehdr.h_nscns; n++)
1115 {
1116 if (myread (execchan, &scnhdr, sizeof scnhdr) < 0)
1117 perror_with_name (filename);
1118
1119 if ((scnhdr.s_flags & S_TYPMASK) >= S_TEXT
1120 && (scnhdr.s_flags & S_TYPMASK) <= S_COMON)
1121 {
1122 exec_map[n_exec].mem_addr = scnhdr.s_vaddr;
1123 exec_map[n_exec].mem_end = scnhdr.s_vaddr + scnhdr.s_size;
1124 exec_map[n_exec].file_addr = scnhdr.s_scnptr;
1125 exec_map[n_exec].type = scnhdr.s_flags & S_TYPMASK;
1126 n_exec++;
1127
1128 if ((scnhdr.s_flags & S_TYPMASK) == S_TEXT)
1129 {
1130 text_start = scnhdr.s_vaddr;
1131 text_end = scnhdr.s_vaddr + scnhdr.s_size;
1132 }
1133 }
1134 }
1135
1136 fstat (execchan, &st_exec);
1137 exec_mtime = st_exec.st_mtime;
1138
1139 validate_files ();
1140 }
1141 else if (from_tty)
1142 printf_filtered ("No exec file now.\n");
e91b87a3 1143
1144 /* Tell display code (if any) about the changed file name. */
1145 if (exec_file_display_hook)
1146 (*exec_file_display_hook) (filename);
1147}
1148
4187119d 1149/* Read data from SOFF exec or core file.
1150 Return 0 on success, 1 if address could not be read. */
1151
1152int
1153xfer_core_file (memaddr, myaddr, len)
1154 CORE_ADDR memaddr;
1155 char *myaddr;
1156 int len;
1157{
1158 register int i;
1159 register int n;
1160 register int val;
1161 int xferchan;
1162 char **xferfile;
1163 int fileptr;
1164 int returnval = 0;
1165
1166 while (len > 0)
1167 {
1168 xferfile = 0;
1169 xferchan = 0;
1170
1171 /* Determine which file the next bunch of addresses reside in,
1172 and where in the file. Set the file's read/write pointer
1173 to point at the proper place for the desired address
1174 and set xferfile and xferchan for the correct file.
1175 If desired address is nonexistent, leave them zero.
1176 i is set to the number of bytes that can be handled
1177 along with the next address. */
1178
1179 i = len;
1180
1181 for (n = 0; n < n_core; n++)
1182 {
1183 if (memaddr >= core_map[n].mem_addr && memaddr < core_map[n].mem_end
1184 && (core_map[n].thread == -1
1185 || core_map[n].thread == inferior_thread))
1186 {
1187 i = min (len, core_map[n].mem_end - memaddr);
1188 fileptr = core_map[n].file_addr + memaddr - core_map[n].mem_addr;
1189 if (core_map[n].file_addr)
1190 {
1191 xferfile = &corefile;
1192 xferchan = corechan;
1193 }
1194 break;
1195 }
1196 else if (core_map[n].mem_addr >= memaddr
1197 && core_map[n].mem_addr < memaddr + i)
1198 i = core_map[n].mem_addr - memaddr;
1199 }
1200
1201 if (!xferfile)
1202 for (n = 0; n < n_exec; n++)
1203 {
1204 if (memaddr >= exec_map[n].mem_addr
1205 && memaddr < exec_map[n].mem_end)
1206 {
1207 i = min (len, exec_map[n].mem_end - memaddr);
1208 fileptr = exec_map[n].file_addr + memaddr
1209 - exec_map[n].mem_addr;
1210 if (exec_map[n].file_addr)
1211 {
1212 xferfile = &execfile;
1213 xferchan = execchan;
1214 }
1215 break;
1216 }
1217 else if (exec_map[n].mem_addr >= memaddr
1218 && exec_map[n].mem_addr < memaddr + i)
1219 i = exec_map[n].mem_addr - memaddr;
1220 }
1221
1222 /* Now we know which file to use.
1223 Set up its pointer and transfer the data. */
1224 if (xferfile)
1225 {
1226 if (*xferfile == 0)
1227 if (xferfile == &execfile)
1228 error ("No program file to examine.");
1229 else
1230 error ("No core dump file or running program to examine.");
1231 val = lseek (xferchan, fileptr, 0);
1232 if (val < 0)
1233 perror_with_name (*xferfile);
1234 val = myread (xferchan, myaddr, i);
1235 if (val < 0)
1236 perror_with_name (*xferfile);
1237 }
1238 /* If this address is for nonexistent memory,
1239 read zeros if reading, or do nothing if writing. */
1240 else
1241 {
1242 bzero (myaddr, i);
1243 returnval = 1;
1244 }
1245
1246 memaddr += i;
1247 myaddr += i;
1248 len -= i;
1249 }
1250 return returnval;
1251}
1252
1253
1254/* Here from info files command to print an address map. */
1255
1256print_maps ()
1257{
1258 struct pmap ptrs[200];
1259 int n;
1260
1261 /* ID strings for core and executable file sections */
1262
1263 static char *idstr[] =
1264 {
1265 "0", "text", "data", "tdata", "bss", "tbss",
1266 "common", "ttext", "ctx", "tctx", "10", "11", "12",
1267 };
1268
1269 for (n = 0; n < n_core; n++)
1270 {
1271 core_map[n].which = 0;
1272 ptrs[n] = core_map[n];
1273 }
1274 for (n = 0; n < n_exec; n++)
1275 {
1276 exec_map[n].which = 1;
1277 ptrs[n_core+n] = exec_map[n];
1278 }
1279
1280 qsort (ptrs, n_core + n_exec, sizeof *ptrs, ptr_cmp);
1281
1282 for (n = 0; n < n_core + n_exec; n++)
1283 {
1284 struct pmap *p = &ptrs[n];
1285 if (n > 0)
1286 {
1287 if (p->mem_addr < ptrs[n-1].mem_end)
1288 p->mem_addr = ptrs[n-1].mem_end;
1289 if (p->mem_addr >= p->mem_end)
1290 continue;
1291 }
1292 printf_filtered ("%08x .. %08x %-6s %s\n",
1293 p->mem_addr, p->mem_end, idstr[p->type],
1294 p->which ? execfile : corefile);
1295 }
1296}
1297
1298/* Compare routine to put file sections in order.
1299 Sort into increasing order on address, and put core file sections
1300 before exec file sections if both files contain the same addresses. */
1301
1302static ptr_cmp (a, b)
1303 struct pmap *a, *b;
1304{
1305 if (a->mem_addr != b->mem_addr) return a->mem_addr - b->mem_addr;
1306 return a->which - b->which;
1307}
1308\f
1309/* Trapped internal variables are used to handle special registers.
1310 A trapped i.v. calls a hook here every time it is dereferenced,
1311 to provide a new value for the variable, and it calls a hook here
1312 when a new value is assigned, to do something with the value.
1313
1314 The vector registers are $vl, $vs, $vm, $vN, $VN (N in 0..7).
1315 The communication registers are $cN, $CN (N in 0..63).
1316 They not handled as regular registers because it's expensive to
1317 read them, and their size varies, and they have too many names. */
1318
1319
1320/* Return 1 if NAME is a trapped internal variable, else 0. */
1321
1322int
1323is_trapped_internalvar (name)
1324 char *name;
1325{
1326 if ((name[0] == 'c' || name[0] == 'C')
1327 && name[1] >= '0' && name[1] <= '9'
1328 && (name[2] == '\0'
1329 || (name[2] >= '0' && name[2] <= '9'
1330 && name[3] == '\0' && name[1] != '0'))
1331 && atoi (&name[1]) < 64) return 1;
1332
1333 if ((name[0] == 'v' || name[0] == 'V')
1334 && (((name[1] & -8) == '0' && name[2] == '\0')
1335 || !strcmp (name, "vl")
1336 || !strcmp (name, "vs")
1337 || !strcmp (name, "vm")))
1338 return 1;
1339 else return 0;
1340}
1341
1342/* Return the value of trapped internal variable VAR */
1343
1344value
1345value_of_trapped_internalvar (var)
1346 struct internalvar *var;
1347{
1348 char *name = var->name;
1349 value val;
1350 struct type *type;
1351 long len = *read_vector_register (VL_REGNUM);
1352 if (len <= 0 || len > 128) len = 128;
1353
1354 if (!strcmp (name, "vl"))
1355 {
1356 val = value_from_long (builtin_type_int,
1357 (LONGEST) *read_vector_register_1 (VL_REGNUM));
1358 }
1359 else if (!strcmp (name, "vs"))
1360 {
1361 val = value_from_long (builtin_type_int,
1362 (LONGEST) *read_vector_register_1 (VS_REGNUM));
1363 }
1364 else if (!strcmp (name, "vm"))
1365 {
1366 long vm[4];
1367 long i, *p;
1368 bcopy (read_vector_register_1 (VM_REGNUM), vm, sizeof vm);
1369 type = vector_type (builtin_type_int, len);
1370 val = allocate_value (type);
1371 p = (long *) VALUE_CONTENTS (val);
1372 for (i = 0; i < len; i++)
1373 *p++ = !! (vm[3 - (i >> 5)] & (1 << (i & 037)));
1374 }
1375 else if (name[0] == 'V')
1376 {
1377 type = vector_type (builtin_type_long_long, len);
1378 val = allocate_value (type);
1379 bcopy (read_vector_register_1 (name[1] - '0'),
1380 VALUE_CONTENTS (val), TYPE_LENGTH (type));
1381 }
1382 else if (name[0] == 'v')
1383 {
1384 long *p1, *p2;
1385 type = vector_type (builtin_type_long, len);
1386 val = allocate_value (type);
1387 p1 = read_vector_register_1 (name[1] - '0');
1388 p2 = (long *) VALUE_CONTENTS (val);
1389 while (--len >= 0) {p1++; *p2++ = *p1++;}
1390 }
1391
1392 else if (name[0] == 'c')
1393 val = value_from_long (builtin_type_int,
1394 read_comm_register (atoi (&name[1])));
1395 else if (name[0] == 'C')
1396 val = value_from_long (builtin_type_long_long,
1397 read_comm_register (atoi (&name[1])));
1398
1399 VALUE_LVAL (val) = lval_internalvar;
1400 VALUE_INTERNALVAR (val) = var;
1401 return val;
1402}
1403
1404/* Construct the type for a vector register's value --
1405 array[LENGTH] of ELEMENT_TYPE. */
1406
1407static struct type *
1408vector_type (element_type, length)
1409 struct type *element_type;
1410 long length;
1411{
1412 struct type *type = (struct type *) xmalloc (sizeof (struct type));
1413 bzero (type, sizeof type);
1414 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1415 TYPE_TARGET_TYPE (type) = element_type;
1416 TYPE_LENGTH (type) = length * TYPE_LENGTH (TYPE_TARGET_TYPE (type));
1417 return type;
1418}
1419
1420/* Handle a new value assigned to a trapped internal variable */
1421
1422void
1423set_trapped_internalvar (var, val, bitpos, bitsize, offset)
1424 struct internalvar *var;
1425 value val;
1426 int bitpos, bitsize, offset;
1427{
1428 char *name = var->name;
1429 long long newval = value_as_long (val);
1430
1431 if (!strcmp (name, "vl"))
1432 write_vector_register (VL_REGNUM, 0, newval);
1433 else if (!strcmp (name, "vs"))
1434 write_vector_register (VS_REGNUM, 0, newval);
1435 else if (name[0] == 'c' || name[0] == 'C')
1436 write_comm_register (atoi (&name[1]), newval);
1437 else if (!strcmp (name, "vm"))
1438 error ("can't assign to $vm");
1439 else
1440 {
1441 offset /= bitsize / 8;
1442 write_vector_register (name[1] - '0', offset, newval);
1443 }
1444}
1445
1446/* Print an integer value when no format was specified. gdb normally
1447 prints these values in decimal, but the the leading 0x80000000 of
1448 pointers produces intolerable 10-digit negative numbers.
1449 If it looks like an address, print it in hex instead. */
1450
1451decout (stream, type, val)
1452 FILE *stream;
1453 struct type *type;
1454 LONGEST val;
1455{
1456 long lv = val;
1457
1458 switch (output_radix)
1459 {
1460 case 0:
1461 if ((lv == val || (unsigned) lv == val)
1462 && ((lv & 0xf0000000) == 0x80000000
1463 || ((lv & 0xf0000000) == 0xf0000000 && lv < STACK_END_ADDR)))
1464 {
1465 fprintf_filtered (stream, "%#x", lv);
1466 return;
1467 }
1468
1469 case 10:
1470 fprintf_filtered (stream, TYPE_UNSIGNED (type) ? "%llu" : "%lld", val);
1471 return;
1472
1473 case 8:
1474 if (TYPE_LENGTH (type) <= sizeof lv)
1475 fprintf_filtered (stream, "%#o", lv);
1476 else
1477 fprintf_filtered (stream, "%#llo", val);
1478 return;
1479
1480 case 16:
1481 if (TYPE_LENGTH (type) <= sizeof lv)
1482 fprintf_filtered (stream, "%#x", lv);
1483 else
1484 fprintf_filtered (stream, "%#llx", val);
1485 return;
1486 }
1487}
1488
1489/* Change the default output radix to 10 or 16, or set it to 0 (heuristic).
1490 This command is mostly obsolete now that the print command allows
1491 formats to apply to aggregates, but is still handy occasionally. */
1492
1493static void
1494set_base_command (arg)
1495 char *arg;
1496{
1497 int new_radix;
1498
1499 if (!arg)
1500 output_radix = 0;
1501 else
1502 {
1503 new_radix = atoi (arg);
1504 if (new_radix != 10 && new_radix != 16 && new_radix != 8)
1505 error ("base must be 8, 10 or 16, or null");
1506 else output_radix = new_radix;
1507 }
1508}
1509
1510/* Turn pipelining on or off in the inferior. */
1511
1512static void
1513set_pipelining_command (arg)
1514 char *arg;
1515{
1516 if (!arg)
1517 {
1518 sequential = !sequential;
1519 printf_filtered ("%s\n", sequential ? "off" : "on");
1520 }
1521 else if (!strcmp (arg, "on"))
1522 sequential = 0;
1523 else if (!strcmp (arg, "off"))
1524 sequential = 1;
1525 else error ("valid args are `on', to allow instructions to overlap, or\n\
1526`off', to prevent it and thereby pinpoint exceptions.");
1527}
1528
1529/* Enable, disable, or force parallel execution in the inferior. */
1530
1531static void
1532set_parallel_command (arg)
1533 char *arg;
1534{
1535 struct rlimit rl;
1536 int prevparallel = parallel;
1537
1538 if (!strncmp (arg, "fixed", strlen (arg)))
1539 parallel = 2;
1540 else if (!strcmp (arg, "on"))
1541 parallel = 1;
1542 else if (!strcmp (arg, "off"))
1543 parallel = 0;
1544 else error ("valid args are `on', to allow multiple threads, or\n\
1545`fixed', to force multiple threads, or\n\
1546`off', to run with one thread only.");
1547
1548 if ((prevparallel == 0) != (parallel == 0) && inferior_pid)
1549 printf_filtered ("will take effect at next run.\n");
1550
1551 getrlimit (RLIMIT_CONCUR, &rl);
1552 rl.rlim_cur = parallel ? rl.rlim_max : 1;
1553 setrlimit (RLIMIT_CONCUR, &rl);
1554
1555 if (inferior_pid)
1556 set_fixed_scheduling (inferior_pid, parallel == 2);
1557}
1558
1559/* Add a new name for an existing command. */
1560
1561static void
1562alias_command (arg)
1563 char *arg;
1564{
1565 static char *aliaserr = "usage is `alias NEW OLD', no args allowed";
1566 char *newname = arg;
1567 struct cmd_list_element *new, *old;
1568
1569 if (!arg)
1570 error_no_arg ("newname oldname");
1571
1572 new = lookup_cmd (&arg, cmdlist, "", -1);
1573 if (new && !strncmp (newname, new->name, strlen (new->name)))
1574 {
1575 newname = new->name;
1576 if (!(*arg == '-'
1577 || (*arg >= 'a' && *arg <= 'z')
1578 || (*arg >= 'A' && *arg <= 'Z')
1579 || (*arg >= '0' && *arg <= '9')))
1580 error (aliaserr);
1581 }
1582 else
1583 {
1584 arg = newname;
1585 while (*arg == '-'
1586 || (*arg >= 'a' && *arg <= 'z')
1587 || (*arg >= 'A' && *arg <= 'Z')
1588 || (*arg >= '0' && *arg <= '9'))
1589 arg++;
1590 if (*arg != ' ' && *arg != '\t')
1591 error (aliaserr);
1592 *arg = '\0';
1593 arg++;
1594 }
1595
1596 old = lookup_cmd (&arg, cmdlist, "", 0);
1597
1598 if (*arg != '\0')
1599 error (aliaserr);
1600
1601 if (new && !strncmp (newname, new->name, strlen (new->name)))
1602 {
1603 char *tem;
1604 if (new->class == (int) class_user || new->class == (int) class_alias)
1605 tem = "Redefine command \"%s\"? ";
1606 else
1607 tem = "Really redefine built-in command \"%s\"? ";
1608 if (!query (tem, new->name))
1609 error ("Command \"%s\" not redefined.", new->name);
1610 }
1611
1612 add_com (newname, class_alias, old->function, old->doc);
1613}
1614
1615
1616
1617/* Print the current thread number, and any threads with signals in the
1618 queue. */
1619
1620thread_info ()
1621{
1622 struct threadpid *p;
1623
1624 if (have_inferior_p ())
1625 {
1626 ps.pi_buffer = (char *) &comm_registers;
1627 ps.pi_nbytes = sizeof comm_registers;
1628 ps.pi_offset = 0;
1629 ps.pi_thread = inferior_thread;
1630 ioctl (inferior_fd, PIXRDCREGS, &ps);
1631 }
1632
1633 printf_filtered ("Current thread %d stopped with signal %d.%d (%s).\n",
1634 inferior_thread, stop_signal, stop_sigcode,
1635 subsig_name (stop_signal, stop_sigcode));
1636
1637 for (p = signal_stack; p->pid; p--)
1638 printf_filtered ("Thread %d stopped with signal %d.%d (%s).\n",
1639 p->thread, p->signo, p->subsig,
1640 subsig_name (p->signo, p->subsig));
1641
1642 if (iscrlbit (comm_registers.crctl.lbits.cc, 64+13))
1643 printf_filtered ("New thread start pc %#x\n",
1644 (long) (comm_registers.crreg.pcpsw >> 32));
1645}
1646
1647/* Return string describing a signal.subcode number */
1648
1649static char *
1650subsig_name (signo, subcode)
1651 int signo, subcode;
1652{
1653 static char *subsig4[] = {
1654 "error exit", "privileged instruction", "unknown",
1655 "unknown", "undefined opcode",
1656 0};
1657 static char *subsig5[] = {0,
1658 "breakpoint", "single step", "fork trap", "exec trap", "pfork trap",
1659 "join trap", "idle trap", "last thread", "wfork trap",
1660 "process breakpoint", "trap instruction",
1661 0};
1662 static char *subsig8[] = {0,
1663 "int overflow", "int divide check", "float overflow",
1664 "float divide check", "float underflow", "reserved operand",
1665 "sqrt error", "exp error", "ln error", "sin error", "cos error",
1666 0};
1667 static char *subsig10[] = {0,
1668 "invalid inward ring address", "invalid outward ring call",
1669 "invalid inward ring return", "invalid syscall gate",
1670 "invalid rtn frame length", "invalid comm reg address",
1671 "invalid trap gate",
1672 0};
1673 static char *subsig11[] = {0,
1674 "read access denied", "write access denied", "execute access denied",
1675 "segment descriptor fault", "page table fault", "data reference fault",
1676 "i/o access denied", "levt pte invalid",
1677 0};
1678
1679 static char **subsig_list[] =
1680 {0, 0, 0, 0, subsig4, subsig5, 0, 0, subsig8, 0, subsig10, subsig11, 0};
1681
1682 int i;
1683 char *p = signo < NSIG ? sys_siglist[signo] : "unknown";
1684
1685 if (signo >= (sizeof subsig_list / sizeof *subsig_list)
1686 || !subsig_list[signo])
1687 return p;
1688 for (i = 1; subsig_list[signo][i]; i++)
1689 if (i == subcode)
1690 return subsig_list[signo][subcode];
1691 return p;
1692}
1693
1694
1695/* Print a compact display of thread status, essentially x/i $pc
1696 for all active threads. */
1697
1698static void
1699threadstat ()
1700{
1701 int t;
1702
1703 for (t = 0; t < n_threads; t++)
1704 if (thread_state[t] == PI_TALIVE)
1705 {
1706 printf_filtered ("%d%c %08x%c %d.%d ", t,
1707 (t == inferior_thread ? '*' : ' '), thread_pc[t],
1708 (thread_is_in_kernel[t] ? '#' : ' '),
1709 thread_signal[t], thread_sigcode[t]);
1710 print_insn (thread_pc[t], stdout);
1711 printf_filtered ("\n");
1712 }
1713}
1714
1715/* Change the current thread to ARG. */
1716
1717set_thread_command (arg)
1718 char *arg;
1719{
1720 int thread;
1721
1722 if (!arg)
1723 {
1724 threadstat ();
1725 return;
1726 }
1727
1728 thread = parse_and_eval_address (arg);
1729
1730 if (thread < 0 || thread > n_threads || thread_state[thread] != PI_TALIVE)
1731 error ("no such thread.");
1732
1733 select_thread (thread);
1734
1735 stop_pc = read_pc ();
1736 flush_cached_frames ();
1737 set_current_frame (create_new_frame (read_register (FP_REGNUM),
1738 read_pc ()));
1739 select_frame (get_current_frame (), 0);
1740 print_sel_frame (1);
1741}
1742
1743/* Here on CONT command; gdb's dispatch address is changed to come here.
1744 Set global variable ALL_CONTINUE to tell resume() that it should
1745 start up all threads, and that a thread switch will not blow gdb's
1746 mind. */
1747
1748static void
1749convex_cont_command (proc_count_exp, from_tty)
1750 char *proc_count_exp;
1751 int from_tty;
1752{
1753 all_continue = 1;
1754 cont_command (proc_count_exp, from_tty);
1755}
1756
1757/* Here on 1CONT command. Resume only the current thread. */
1758
1759one_cont_command (proc_count_exp, from_tty)
1760 char *proc_count_exp;
1761 int from_tty;
1762{
1763 cont_command (proc_count_exp, from_tty);
1764}
1765
1766/* Print the contents and lock bits of all communication registers,
1767 or just register ARG if ARG is a communication register,
1768 or the 3-word resource structure in memory at address ARG. */
1769
1770comm_registers_info (arg)
1771 char *arg;
1772{
1773 int i, regnum;
1774
1775 if (arg)
1776 {
1777 if (sscanf (arg, "0x%x", &regnum) == 1)
1778 {
1779 if (regnum > 0)
1780 regnum &= ~0x8000;
1781 }
1782 else if (sscanf (arg, "%d", &regnum) == 1)
1783 ;
1784 else if (sscanf (arg, "$c%d", &regnum) == 1)
1785 ;
1786 else if (sscanf (arg, "$C%d", &regnum) == 1)
1787 ;
1788 else
1789 regnum = parse_and_eval_address (arg);
1790
1791 if (regnum >= 64)
1792 error ("%s: invalid register name.", arg);
1793
1794 /* if we got a (user) address, examine the resource struct there */
1795
1796 if (regnum < 0)
1797 {
1798 static int buf[3];
1799 read_memory (regnum, buf, sizeof buf);
1800 printf_filtered ("%08x %08x%08x%s\n", regnum, buf[1], buf[2],
1801 buf[0] & 0xff ? " locked" : "");
1802 return;
1803 }
1804 }
1805
1806 ps.pi_buffer = (char *) &comm_registers;
1807 ps.pi_nbytes = sizeof comm_registers;
1808 ps.pi_offset = 0;
1809 ps.pi_thread = inferior_thread;
1810 ioctl (inferior_fd, PIXRDCREGS, &ps);
1811
1812 for (i = 0; i < 64; i++)
1813 if (!arg || i == regnum)
1814 printf_filtered ("%2d 0x8%03x %016llx%s\n", i, i,
1815 comm_registers.crreg.r4[i],
1816 (iscrlbit (comm_registers.crctl.lbits.cc, i)
1817 ? " locked" : ""));
1818}
1819
1820/* Print the psw */
1821
1822static void
1823psw_info (arg)
1824 char *arg;
1825{
1826 struct pswbit
1827 {
1828 int bit;
1829 int pos;
1830 char *text;
1831 };
1832
1833 static struct pswbit pswbit[] =
1834 {
1835 { 0x80000000, -1, "A carry" },
1836 { 0x40000000, -1, "A integer overflow" },
1837 { 0x20000000, -1, "A zero divide" },
1838 { 0x10000000, -1, "Integer overflow enable" },
1839 { 0x08000000, -1, "Trace" },
1840 { 0x06000000, 25, "Frame length" },
1841 { 0x01000000, -1, "Sequential" },
1842 { 0x00800000, -1, "S carry" },
1843 { 0x00400000, -1, "S integer overflow" },
1844 { 0x00200000, -1, "S zero divide" },
1845 { 0x00100000, -1, "Zero divide enable" },
1846 { 0x00080000, -1, "Floating underflow" },
1847 { 0x00040000, -1, "Floating overflow" },
1848 { 0x00020000, -1, "Floating reserved operand" },
1849 { 0x00010000, -1, "Floating zero divide" },
1850 { 0x00008000, -1, "Floating error enable" },
1851 { 0x00004000, -1, "Floating underflow enable" },
1852 { 0x00002000, -1, "IEEE" },
1853 { 0x00001000, -1, "Sequential stores" },
1854 { 0x00000800, -1, "Intrinsic error" },
1855 { 0x00000400, -1, "Intrinsic error enable" },
1856 { 0x00000200, -1, "Trace thread creates" },
1857 { 0x00000100, -1, "Thread init trap" },
1858 { 0x000000e0, 5, "Reserved" },
1859 { 0x0000001f, 0, "Intrinsic error code" },
1860 {0, 0, 0},
1861 };
1862
1863 long psw;
1864
1865 struct pswbit *p;
1866
1867 if (arg)
1868 psw = parse_and_eval_address (arg);
1869 else
1870 psw = read_register (PS_REGNUM);
1871
1872 for (p = pswbit; p->bit; p++)
1873 {
1874 if (p->pos < 0)
1875 printf_filtered ("%08x %s %s\n", p->bit,
1876 (psw & p->bit) ? "yes" : "no ", p->text);
1877 else
1878 printf_filtered ("%08x %3d %s\n", p->bit,
1879 (psw & p->bit) >> p->pos, p->text);
1880 }
1881}
1882\f
1883_initialize_convex_dep ()
1884{
1885 add_com ("alias", class_support, alias_command,
1886 "Add a new name for an existing command.");
1887
1888 add_cmd ("base", class_vars, set_base_command,
1889 "Change the integer output radix to 8, 10 or 16\n\
1890or use just `set base' with no args to return to the ad-hoc default,\n\
1891which is 16 for integers that look like addresses, 10 otherwise.",
1892 &setlist);
1893
1894 add_cmd ("pipeline", class_run, set_pipelining_command,
1895 "Enable or disable overlapped execution of instructions.\n\
1896With `set pipe off', exceptions are reported with\n\
1897$pc pointing at the instruction after the faulting one.\n\
1898The default is `set pipe on', which runs faster.",
1899 &setlist);
1900
1901 add_cmd ("parallel", class_run, set_parallel_command,
1902 "Enable or disable multi-threaded execution of parallel code.\n\
1903`set parallel off' means run the program on a single CPU.\n\
1904`set parallel fixed' means run the program with all CPUs assigned to it.\n\
1905`set parallel on' means run the program on any CPUs that are available.",
1906 &setlist);
1907
1908 add_com ("1cont", class_run, one_cont_command,
1909 "Continue the program, activating only the current thread.\n\
1910Args are the same as the `cont' command.");
1911
1912 add_com ("thread", class_run, set_thread_command,
1913 "Change the current thread, the one under scrutiny and control.\n\
1914With no arg, show the active threads, the current one marked with *.");
1915
1916 add_info ("threads", thread_info,
1917 "List status of active threads.");
1918
1919 add_info ("comm-registers", comm_registers_info,
1920 "List communication registers and their contents.\n\
1921A communication register name as argument means describe only that register.\n\
1922An address as argument means describe the resource structure at that address.\n\
1923`Locked' means that the register has been sent to but not yet received from.");
1924
1925 add_info ("psw", psw_info,
1926 "Display $ps, the processor status word, bit by bit.\n\
1927An argument means display that value's interpretation as a psw.");
1928
1929 add_cmd ("convex", no_class, 0, "Convex-specific commands.\n\
193032-bit registers $pc $ps $sp $ap $fp $a1-5 $s0-7 $v0-7 $vl $vs $vm $c0-63\n\
193164-bit registers $S0-7 $V0-7 $C0-63\n\
1932\n\
1933info threads display info on stopped threads waiting to signal\n\
1934thread display list of active threads\n\
1935thread N select thread N (its registers, stack, memory, etc.)\n\
1936step, next, etc step selected thread only\n\
19371cont continue selected thread only\n\
1938cont continue all threads\n\
1939info comm-registers display contents of comm register(s) or a resource struct\n\
1940info psw display processor status word $ps\n\
1941set base N change integer radix used by `print' without a format\n\
1942set pipeline off exceptions are precise, $pc points after the faulting insn\n\
1943set pipeline on normal mode, $pc is somewhere ahead of faulting insn\n\
1944set parallel off program runs on a single CPU\n\
1945set parallel fixed all CPUs are assigned to the program\n\
1946set parallel on normal mode, parallel execution on random available CPUs\n\
1947",
1948 &cmdlist);
1949
1950}
1951
This page took 0.102228 seconds and 4 git commands to generate.