Avoid longjmp()-catching compilation errors in cross-ports.
[deliverable/binutils-gdb.git] / gdb / mips-nat.c
1 /* Low level DECstation interface to ptrace, for GDB when running native.
2 Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 #include "defs.h"
23 #include "inferior.h"
24 #include "gdbcore.h"
25 #include <sys/ptrace.h>
26 #include <setjmp.h> /* For JB_XXX. */
27
28 /* Size of elements in jmpbuf */
29
30 #define JB_ELEMENT_SIZE 4
31
32 /* Map gdb internal register number to ptrace ``address''.
33 These ``addresses'' are defined in DECstation <sys/ptrace.h> */
34
35 #define REGISTER_PTRACE_ADDR(regno) \
36 (regno < 32 ? GPR_BASE + regno \
37 : regno == PC_REGNUM ? PC \
38 : regno == CAUSE_REGNUM ? CAUSE \
39 : regno == HI_REGNUM ? MMHI \
40 : regno == LO_REGNUM ? MMLO \
41 : regno == FCRCS_REGNUM ? FPC_CSR \
42 : regno == FCRIR_REGNUM ? FPC_EIR \
43 : regno >= FP0_REGNUM ? FPR_BASE + (regno - FP0_REGNUM) \
44 : 0)
45
46 static const char zerobuf[MAX_REGISTER_RAW_SIZE];
47
48 /* Get all registers from the inferior */
49
50 void
51 fetch_inferior_registers (regno)
52 int regno;
53 {
54 register unsigned int regaddr;
55 char buf[MAX_REGISTER_RAW_SIZE];
56 register int i;
57
58 registers_fetched ();
59
60 for (regno = 1; regno < NUM_REGS; regno++)
61 {
62 regaddr = REGISTER_PTRACE_ADDR (regno);
63 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
64 {
65 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid,
66 (PTRACE_ARG3_TYPE) regaddr, 0);
67 regaddr += sizeof (int);
68 }
69 supply_register (regno, buf);
70 }
71
72 supply_register (ZERO_REGNUM, zerobuf);
73 /* Frame ptr reg must appear to be 0; it is faked by stack handling code. */
74 supply_register (FP_REGNUM, zerobuf);
75 }
76
77 /* Store our register values back into the inferior.
78 If REGNO is -1, do this for all registers.
79 Otherwise, REGNO specifies which register (so we can save time). */
80
81 void
82 store_inferior_registers (regno)
83 int regno;
84 {
85 register unsigned int regaddr;
86 char buf[80];
87
88 if (regno == 0)
89 return;
90
91 if (regno > 0)
92 {
93 regaddr = REGISTER_PTRACE_ADDR (regno);
94 errno = 0;
95 ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
96 read_register (regno));
97 if (errno != 0)
98 {
99 sprintf (buf, "writing register number %d", regno);
100 perror_with_name (buf);
101 }
102 }
103 else
104 {
105 for (regno = 0; regno < NUM_REGS; regno++)
106 {
107 if (regno == ZERO_REGNUM || regno == PS_REGNUM
108 || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
109 || regno == FCRIR_REGNUM || regno == FP_REGNUM
110 || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
111 continue;
112 regaddr = register_addr (regno, 1);
113 errno = 0;
114 ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
115 read_register (regno));
116 if (errno != 0)
117 {
118 sprintf (buf, "writing all regs, number %d", regno);
119 perror_with_name (buf);
120 }
121 }
122 }
123 }
124
125
126 /* Figure out where the longjmp will land.
127 We expect the first arg to be a pointer to the jmp_buf structure from which
128 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
129 This routine returns true on success. */
130
131 int
132 get_longjmp_target(pc)
133 CORE_ADDR *pc;
134 {
135 CORE_ADDR jb_addr;
136
137 jb_addr = read_register(A0_REGNUM);
138
139 if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc,
140 sizeof(CORE_ADDR)))
141 return 0;
142
143 SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
144
145 return 1;
146 }
This page took 0.032983 seconds and 5 git commands to generate.