gdb-3.5
[deliverable/binutils-gdb.git] / gdb / convex-dep.c
CommitLineData
4187119d 1/* Convex stuff for GDB.
7a67dd45 2 Copyright (C) 1990 Free Software Foundation, Inc.
4187119d 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
7a67dd45 20#include <stdio.h>
e91b87a3 21#include "defs.h"
22#include "param.h"
4187119d 23#include "command.h"
24#include "symtab.h"
25#include "value.h"
e91b87a3 26#include "frame.h"
27#include "inferior.h"
4187119d 28#include "wait.h"
e91b87a3 29
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. */
e91b87a3 223
224extern CORE_ADDR data_start;
225extern CORE_ADDR data_end;
226extern CORE_ADDR stack_start;
227extern CORE_ADDR stack_end;
228
229/* Virtual addresses of bounds of two areas of memory in the exec file.
4187119d 230 NB: Only text_start and text_end have meaningful values on convex. */
e91b87a3 231
232extern CORE_ADDR text_start;
233extern CORE_ADDR text_end;
234
235extern CORE_ADDR exec_data_start;
236extern CORE_ADDR exec_data_end;
237
238/* Address in executable file of start of text area data. */
239
240extern int text_offset;
241
242/* Address in executable file of start of data area data. */
243
244extern int exec_data_offset;
245
246/* Address in core file of start of data area data. */
247
248extern int data_offset;
249
250/* Address in core file of start of stack area data. */
251
252extern int stack_offset;
253
e91b87a3 254/* a.out header saved in core file. */
255
4187119d 256extern struct exec core_aouthdr;
e91b87a3 257
258/* a.out header of exec file. */
259
4187119d 260extern struct exec exec_aouthdr;
261
262/* Routine to check for exec-core mismatch. */
e91b87a3 263
264extern void validate_files ();
e91b87a3 265
4187119d 266/* Nonzero if we are debugging an attached outside process
267 rather than an inferior. */
e91b87a3 268
4187119d 269extern int attach_flag;
e91b87a3 270
e91b87a3 271
e91b87a3 272
4187119d 273static struct type *vector_type ();
274static long *read_vector_register ();
275static long *read_vector_register_1 ();
276static void write_vector_register ();
277static REGISTER_TYPE read_comm_register ();
278static void write_comm_register ();
279static void convex_cont_command ();
280static void thread_continue ();
281static void select_thread ();
282static void scan_stack ();
283static void set_fixed_scheduling ();
284static char *subsig_name ();
285static void psw_info ();
286static sig_noop ();
287static ptr_cmp ();
e91b87a3 288
4187119d 289extern char *sys_siglist[];
290extern int errno;
291\f
292/* Execute ptrace. Convex V7 replaced ptrace with pattach.
293 Allow ptrace (0) as a no-op. */
e91b87a3 294
4187119d 295int
296call_ptrace (request, pid, procaddr, buf)
297 int request, pid, procaddr, buf;
298{
299 if (request == 0)
300 return;
301 error ("no ptrace");
302}
e91b87a3 303
4187119d 304/* Replacement for system execle routine.
305 Convert it to an equivalent exect, which pattach insists on. */
e91b87a3 306
4187119d 307execle (name, argv)
308 char *name, *argv;
309{
310 char ***envp = (char ***) &argv;
311 while (*envp++) ;
e91b87a3 312
4187119d 313 signal (SIGTRAP, sig_noop);
314 exect (name, &argv, *envp);
315}
e91b87a3 316
4187119d 317/* Stupid handler for stupid trace trap that otherwise causes
318 startup to stupidly hang. */
e91b87a3 319
4187119d 320static sig_noop ()
321{}
e91b87a3 322
4187119d 323/* Read registers from inferior into registers[] array.
324 For convex, they are already there, read in when the inferior stops. */
e91b87a3 325
4187119d 326void
327fetch_inferior_registers ()
328{
329}
e91b87a3 330
4187119d 331/* Store our register values back into the inferior.
332 For Convex, do this only once, right before resuming inferior. */
e91b87a3 333
4187119d 334store_inferior_registers (regno)
335 int regno;
336{
337}
e91b87a3 338
4187119d 339/* Copy LEN bytes from inferior's memory starting at MEMADDR
340 to debugger memory starting at MYADDR.
341 On failure (cannot read from inferior, usually because address is out
342 of bounds) returns the value of errno. */
e91b87a3 343
4187119d 344int
345read_inferior_memory (memaddr, myaddr, len)
346 CORE_ADDR memaddr;
347 char *myaddr;
348 int len;
349{
350 errno = 0;
351 while (len > 0)
352 {
353 /* little-known undocumented max request size */
354 int i = (len < 12288) ? len : 12288;
e91b87a3 355
4187119d 356 lseek (inferior_fd, memaddr, 0);
357 read (inferior_fd, myaddr, i);
e91b87a3 358
4187119d 359 memaddr += i;
360 myaddr += i;
361 len -= i;
e91b87a3 362 }
4187119d 363 if (errno)
364 bzero (myaddr, len);
365 return errno;
e91b87a3 366}
e91b87a3 367
4187119d 368/* Copy LEN bytes of data from debugger memory at MYADDR
369 to inferior's memory at MEMADDR.
370 Returns errno on failure (cannot write the inferior) */
e91b87a3 371
4187119d 372int
373write_inferior_memory (memaddr, myaddr, len)
374 CORE_ADDR memaddr;
375 char *myaddr;
376 int len;
377{
378 errno = 0;
379 lseek (inferior_fd, memaddr, 0);
380 write (inferior_fd, myaddr, len);
381 return errno;
382}
e91b87a3 383
4187119d 384/* Here from create_inferior when the inferior process has been created
385 and started up. We must do a pattach to grab it for debugging.
e91b87a3 386
4187119d 387 Also, intercept the CONT command by altering its dispatch address. */
e91b87a3 388
4187119d 389create_inferior_hook (pid)
390 int pid;
391{
392 static char cont[] = "cont";
393 static char cont1[] = "c";
394 char *linep = cont;
395 char *linep1 = cont1;
396 char **line = &linep;
397 char **line1 = &linep1;
398 struct cmd_list_element *c;
399
400 c = lookup_cmd (line, cmdlist, "", 0);
401 c->function = convex_cont_command;
402 c = lookup_cmd (line1, cmdlist, "", 0);
403 c->function = convex_cont_command;
404
405 inferior_fd = pattach (pid, O_EXCL);
406 if (inferior_fd < 0)
407 perror_with_name ("pattach");
408 inferior_thread = 0;
409 set_fixed_scheduling (pid, parallel == 2);
410}
e91b87a3 411
4187119d 412/* Attach process PID for debugging. */
e91b87a3 413
4187119d 414attach (pid)
415 int pid;
416{
417 int fd = pattach (pid, O_EXCL);
418 if (fd < 0)
419 perror_with_name ("pattach");
420 attach_flag = 1;
421 /* wait for strange kernel reverberations to go away */
422 sleep (1);
423
424 setpgrp (pid, pid);
425
426 inferior_fd = fd;
427 inferior_thread = 0;
428 return pid;
429}
e91b87a3 430
4187119d 431/* Stop debugging the process whose number is PID
432 and continue it with signal number SIGNAL.
433 SIGNAL = 0 means just continue it. */
e91b87a3 434
4187119d 435void
436detach (signal)
437 int signal;
438{
439 signal_stack = signal_stack_bot;
440 thread_continue (-1, 0, signal);
441 ioctl (inferior_fd, PIXDETACH, &ps);
442 close (inferior_fd);
443 inferior_fd = 0;
444 attach_flag = 0;
445}
e91b87a3 446
4187119d 447/* Kill off the inferior process. */
e91b87a3 448
4187119d 449kill_inferior ()
450{
451 if (remote_debugging)
452 return;
453 if (inferior_pid == 0)
454 return;
455 ioctl (inferior_fd, PIXTERMINATE, 0);
456 wait (0);
457 inferior_died ();
458}
459
460/* This is used when GDB is exiting. It gives less chance of error.*/
461
462kill_inferior_fast ()
463{
464 if (remote_debugging)
465 return;
466 if (inferior_pid == 0)
467 return;
468 ioctl (inferior_fd, PIXTERMINATE, 0);
469 wait (0);
470}
471
472/* Read vector register REG, and return a pointer to the value. */
473
474static long *
475read_vector_register (reg)
476 int reg;
477{
478 if (have_inferior_p ())
479 {
480 errno = 0;
481 ps.pi_buffer = (char *) &vector_registers;
482 ps.pi_nbytes = sizeof vector_registers;
483 ps.pi_offset = 0;
484 ps.pi_thread = inferior_thread;
485 ioctl (inferior_fd, PIXRDVREGS, &ps);
486 if (errno)
487 bzero (&vector_registers, sizeof vector_registers);
488 }
489 else if (corechan >= 0)
490 {
491 lseek (corechan, tcontext_offset[inferior_thread], 0);
492 if (myread (corechan, &tc, sizeof tc) < 0)
493 perror_with_name (corefile);
494 lseek (corechan, tc.core_thread_p, 0);
495 if (myread (corechan, &th, sizeof th) < 0)
496 perror_with_name (corefile);
497 lseek (corechan, tc.core_vregs_p, 0);
498 if (myread (corechan, &vector_registers, 16*128) < 0)
499 perror_with_name (corefile);
500 vector_registers.vm[0] = th.t_vect_ctx.vc_vm[0];
501 vector_registers.vm[1] = th.t_vect_ctx.vc_vm[1];
502 vector_registers.vls = th.t_vect_ctx.vc_vls;
503 }
504
505 return read_vector_register_1 (reg);
506}
507
508/* Return a pointer to vector register REG, which must already have been
509 fetched from the inferior or core file. */
510
511static long *
512read_vector_register_1 (reg)
513 int reg;
514{
515 switch (reg)
516 {
517 case VM_REGNUM:
518 return (long *) vector_registers.vm;
519 case VS_REGNUM:
520 return (long *) &vector_registers.vls;
521 case VL_REGNUM:
522 return 1 + (long *) &vector_registers.vls;
523 default:
524 return (long *) &vector_registers.vr[reg];
525 }
526}
527
528/* Write vector register REG, element ELEMENT, new value VAL.
529 NB: must use read-modify-write on the entire vector state,
530 since pattach does not do offsetted writes correctly. */
531
532static void
533write_vector_register (reg, element, val)
534 int reg, element;
535 REGISTER_TYPE val;
536{
537 if (have_inferior_p ())
538 {
539 errno = 0;
540 ps.pi_thread = inferior_thread;
541 ps.pi_offset = 0;
542 ps.pi_buffer = (char *) &vector_registers;
543 ps.pi_nbytes = sizeof vector_registers;
544
545 ioctl (inferior_fd, PIXRDVREGS, &ps);
546
547 switch (reg)
548 {
549 case VL_REGNUM:
550 vector_registers.vls =
551 (vector_registers.vls & 0xffffffff00000000LL)
552 + (unsigned long) val;
553 break;
554
555 case VS_REGNUM:
556 vector_registers.vls =
557 (val << 32) + (unsigned long) vector_registers.vls;
558 break;
559
560 default:
561 vector_registers.vr[reg].el[element] = val;
562 break;
563 }
564
565 ioctl (inferior_fd, PIXWRVREGS, &ps);
566
567 if (errno)
568 perror_with_name ("writing vector register");
569 }
570}
571
572/* Return the contents of communication register NUM. */
573
574static REGISTER_TYPE
575read_comm_register (num)
576 int num;
577{
578 if (have_inferior_p ())
579 {
580 ps.pi_buffer = (char *) &comm_registers;
581 ps.pi_nbytes = sizeof comm_registers;
582 ps.pi_offset = 0;
583 ps.pi_thread = inferior_thread;
584 ioctl (inferior_fd, PIXRDCREGS, &ps);
585 }
586 return comm_registers.crreg.r4[num];
587}
588
589/* Store a new value VAL into communication register NUM.
590 NB: Must use read-modify-write on the whole comm register set
591 since pattach does not do offsetted writes correctly. */
592
593static void
594write_comm_register (num, val)
595 int num;
596 REGISTER_TYPE val;
597{
598 if (have_inferior_p ())
599 {
600 ps.pi_buffer = (char *) &comm_registers;
601 ps.pi_nbytes = sizeof comm_registers;
602 ps.pi_offset = 0;
603 ps.pi_thread = inferior_thread;
604 ioctl (inferior_fd, PIXRDCREGS, &ps);
605 comm_registers.crreg.r4[num] = val;
606 ioctl (inferior_fd, PIXWRCREGS, &ps);
607 }
608}
609
610/* Resume execution of the inferior process.
611 If STEP is nonzero, single-step it.
612 If SIGNAL is nonzero, give it that signal. */
613
614void
615resume (step, signal)
616 int step;
617 int signal;
618{
619 errno = 0;
620 if (remote_debugging)
621 remote_resume (step, signal);
622 else
623 if (step || signal)
624 thread_continue (inferior_thread, step, signal);
625 else
626 thread_continue (-1, 0, 0);
627}
628
629/* Maybe resume some threads.
630 THREAD is which thread to resume, or -1 to resume them all.
631 STEP and SIGNAL are as in resume.
632
633 Global variable ALL_CONTINUE is set when we are here to do a
634 `cont' command; otherwise we may be doing `finish' or a call or
635 something else that will not tolerate an automatic thread switch.
636
637 If there are stopped threads waiting to deliver signals, and
638 ALL_CONTINUE, do not actually resume anything. gdb will do a wait
639 and see one of the stopped threads in the queue. */
640
641static void
642thread_continue (thread, step, signal)
643 int thread, step, signal;
644{
645 int n;
646
647 /* If we are to continue all threads, but not for the CONTINUE command,
648 pay no attention and continue only the selected thread. */
649
650 if (thread < 0 && ! all_continue)
651 thread = inferior_thread;
652
653 /* If we are not stepping, we have now executed the continue part
654 of a CONTINUE command. */
655
656 if (! step)
657 all_continue = 0;
658
659 /* Allow wait() to switch threads if this is an all-out continue. */
660
661 thread_switch_ok = thread < 0;
662
663 /* If there are threads queued up, don't resume. */
664
665 if (thread_switch_ok && ! signal_stack_is_empty ())
666 return;
667
668 /* OK, do it. */
669
670 for (n = 0; n < n_threads; n++)
671 if (thread_state[n] == PI_TALIVE)
672 {
673 select_thread (n);
674
675 if ((thread < 0 || n == thread) && ! thread_is_in_kernel[n])
676 {
677 /* Blam the trace bits in the stack's saved psws to match
678 the desired step mode. This is required so that
679 single-stepping a return doesn't restore a psw with a
680 clear trace bit and fly away, and conversely,
681 proceeding through a return in a routine that was
682 stepped into doesn't cause a phantom break by restoring
683 a psw with the trace bit set. */
684 scan_stack (PSW_T_BIT, step);
685 scan_stack (PSW_S_BIT, sequential);
686 }
687
688 ps.pi_buffer = registers;
689 ps.pi_nbytes = REGISTER_BYTES;
690 ps.pi_offset = 0;
691 ps.pi_thread = n;
692 if (! thread_is_in_kernel[n])
693 if (ioctl (inferior_fd, PIXWRREGS, &ps))
694 perror_with_name ("PIXWRREGS");
695
696 if (thread < 0 || n == thread)
697 {
698 ps.pi_pc = 1;
699 ps.pi_signo = signal;
700 if (ioctl (inferior_fd, step ? PIXSTEP : PIXCONTINUE, &ps) < 0)
701 perror_with_name ("PIXCONTINUE");
702 }
703 }
704
705 if (ioctl (inferior_fd, PIXRUN, &ps) < 0)
706 perror_with_name ("PIXRUN");
707}
708
709/* Replacement for system wait routine.
710
711 The system wait returns with one or more threads stopped by
712 signals. Put stopped threads on a stack and return them one by
713 one, so that it appears that wait returns one thread at a time.
714
715 Global variable THREAD_SWITCH_OK is set when gdb can tolerate wait
716 returning a new thread. If it is false, then only one thread is
717 running; we will do a real wait, the thread will do something, and
718 we will return that. */
719
7a67dd45 720pid_t
4187119d 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 {
7a67dd45 1777 if (sscanf (arg, "0x%x", &regnum) == 1
1778 || sscanf (argc, "%d", &regnum) == 1)
4187119d 1779 {
1780 if (regnum > 0)
1781 regnum &= ~0x8000;
1782 }
4187119d 1783 else if (sscanf (arg, "$c%d", &regnum) == 1)
1784 ;
1785 else if (sscanf (arg, "$C%d", &regnum) == 1)
1786 ;
1787 else
1788 regnum = parse_and_eval_address (arg);
1789
1790 if (regnum >= 64)
1791 error ("%s: invalid register name.", arg);
1792
1793 /* if we got a (user) address, examine the resource struct there */
1794
1795 if (regnum < 0)
1796 {
1797 static int buf[3];
1798 read_memory (regnum, buf, sizeof buf);
1799 printf_filtered ("%08x %08x%08x%s\n", regnum, buf[1], buf[2],
1800 buf[0] & 0xff ? " locked" : "");
1801 return;
1802 }
1803 }
1804
1805 ps.pi_buffer = (char *) &comm_registers;
1806 ps.pi_nbytes = sizeof comm_registers;
1807 ps.pi_offset = 0;
1808 ps.pi_thread = inferior_thread;
1809 ioctl (inferior_fd, PIXRDCREGS, &ps);
1810
1811 for (i = 0; i < 64; i++)
1812 if (!arg || i == regnum)
1813 printf_filtered ("%2d 0x8%03x %016llx%s\n", i, i,
1814 comm_registers.crreg.r4[i],
1815 (iscrlbit (comm_registers.crctl.lbits.cc, i)
1816 ? " locked" : ""));
1817}
1818
1819/* Print the psw */
1820
1821static void
1822psw_info (arg)
1823 char *arg;
1824{
1825 struct pswbit
1826 {
1827 int bit;
1828 int pos;
1829 char *text;
1830 };
1831
1832 static struct pswbit pswbit[] =
1833 {
1834 { 0x80000000, -1, "A carry" },
1835 { 0x40000000, -1, "A integer overflow" },
1836 { 0x20000000, -1, "A zero divide" },
1837 { 0x10000000, -1, "Integer overflow enable" },
1838 { 0x08000000, -1, "Trace" },
1839 { 0x06000000, 25, "Frame length" },
1840 { 0x01000000, -1, "Sequential" },
1841 { 0x00800000, -1, "S carry" },
1842 { 0x00400000, -1, "S integer overflow" },
1843 { 0x00200000, -1, "S zero divide" },
1844 { 0x00100000, -1, "Zero divide enable" },
1845 { 0x00080000, -1, "Floating underflow" },
1846 { 0x00040000, -1, "Floating overflow" },
1847 { 0x00020000, -1, "Floating reserved operand" },
1848 { 0x00010000, -1, "Floating zero divide" },
1849 { 0x00008000, -1, "Floating error enable" },
1850 { 0x00004000, -1, "Floating underflow enable" },
1851 { 0x00002000, -1, "IEEE" },
1852 { 0x00001000, -1, "Sequential stores" },
1853 { 0x00000800, -1, "Intrinsic error" },
1854 { 0x00000400, -1, "Intrinsic error enable" },
1855 { 0x00000200, -1, "Trace thread creates" },
1856 { 0x00000100, -1, "Thread init trap" },
1857 { 0x000000e0, 5, "Reserved" },
1858 { 0x0000001f, 0, "Intrinsic error code" },
1859 {0, 0, 0},
1860 };
1861
1862 long psw;
4187119d 1863 struct pswbit *p;
1864
1865 if (arg)
1866 psw = parse_and_eval_address (arg);
1867 else
1868 psw = read_register (PS_REGNUM);
1869
1870 for (p = pswbit; p->bit; p++)
1871 {
1872 if (p->pos < 0)
1873 printf_filtered ("%08x %s %s\n", p->bit,
1874 (psw & p->bit) ? "yes" : "no ", p->text);
1875 else
1876 printf_filtered ("%08x %3d %s\n", p->bit,
1877 (psw & p->bit) >> p->pos, p->text);
1878 }
1879}
1880\f
1881_initialize_convex_dep ()
1882{
1883 add_com ("alias", class_support, alias_command,
1884 "Add a new name for an existing command.");
1885
1886 add_cmd ("base", class_vars, set_base_command,
1887 "Change the integer output radix to 8, 10 or 16\n\
1888or use just `set base' with no args to return to the ad-hoc default,\n\
1889which is 16 for integers that look like addresses, 10 otherwise.",
1890 &setlist);
1891
1892 add_cmd ("pipeline", class_run, set_pipelining_command,
1893 "Enable or disable overlapped execution of instructions.\n\
1894With `set pipe off', exceptions are reported with\n\
1895$pc pointing at the instruction after the faulting one.\n\
1896The default is `set pipe on', which runs faster.",
1897 &setlist);
1898
1899 add_cmd ("parallel", class_run, set_parallel_command,
1900 "Enable or disable multi-threaded execution of parallel code.\n\
1901`set parallel off' means run the program on a single CPU.\n\
1902`set parallel fixed' means run the program with all CPUs assigned to it.\n\
1903`set parallel on' means run the program on any CPUs that are available.",
1904 &setlist);
1905
1906 add_com ("1cont", class_run, one_cont_command,
1907 "Continue the program, activating only the current thread.\n\
1908Args are the same as the `cont' command.");
1909
1910 add_com ("thread", class_run, set_thread_command,
1911 "Change the current thread, the one under scrutiny and control.\n\
1912With no arg, show the active threads, the current one marked with *.");
1913
1914 add_info ("threads", thread_info,
1915 "List status of active threads.");
1916
1917 add_info ("comm-registers", comm_registers_info,
1918 "List communication registers and their contents.\n\
1919A communication register name as argument means describe only that register.\n\
1920An address as argument means describe the resource structure at that address.\n\
1921`Locked' means that the register has been sent to but not yet received from.");
1922
1923 add_info ("psw", psw_info,
1924 "Display $ps, the processor status word, bit by bit.\n\
1925An argument means display that value's interpretation as a psw.");
1926
1927 add_cmd ("convex", no_class, 0, "Convex-specific commands.\n\
192832-bit registers $pc $ps $sp $ap $fp $a1-5 $s0-7 $v0-7 $vl $vs $vm $c0-63\n\
192964-bit registers $S0-7 $V0-7 $C0-63\n\
1930\n\
1931info threads display info on stopped threads waiting to signal\n\
1932thread display list of active threads\n\
1933thread N select thread N (its registers, stack, memory, etc.)\n\
1934step, next, etc step selected thread only\n\
19351cont continue selected thread only\n\
1936cont continue all threads\n\
1937info comm-registers display contents of comm register(s) or a resource struct\n\
1938info psw display processor status word $ps\n\
1939set base N change integer radix used by `print' without a format\n\
1940set pipeline off exceptions are precise, $pc points after the faulting insn\n\
1941set pipeline on normal mode, $pc is somewhere ahead of faulting insn\n\
1942set parallel off program runs on a single CPU\n\
1943set parallel fixed all CPUs are assigned to the program\n\
1944set parallel on normal mode, parallel execution on random available CPUs\n\
1945",
1946 &cmdlist);
1947
1948}
This page took 0.102311 seconds and 4 git commands to generate.