1 /* Copyright (C) 1988, 1990 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include <sys/types.h>
29 #include <sys/param.h>
34 #ifndef USER /* added to support BCS ptrace_user */
36 #define USER ptrace_user
38 #include <sys/ioctl.h>
41 #ifdef COFF_ENCAPSULATE
42 #include "a.out.encap.h"
54 /* define offsets to the pc instruction offsets in ptrace_user struct */
55 #define SXIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sxip - \
58 #define SNIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_snip - \
61 #define SFIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u
62 extern int have_symbol_file_p();
64 extern jmp_buf stack_jmp;
67 extern char registers[REGISTER_BYTES];
70 fetch_inferior_registers ()
73 register unsigned int regaddr;
74 char buf[MAX_REGISTER_RAW_SIZE];
80 offset = (char *) &u.pt_r0 - (char *) &u;
81 regaddr = offset; /* byte offset to r0;*/
83 /* offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; */
84 for (regno = 0; regno < NUM_REGS; regno++)
86 /*regaddr = register_addr (regno, offset);*/
89 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
91 *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0);
92 regaddr += sizeof (int);
94 supply_register (regno, buf);
96 /* now load up registers 36 - 38; special pc registers */
97 *(int *) &buf[0] = ptrace (3,inferior_pid,(char *)&u.pt_sigframe.dg_sigframe.sc_sxip - (char *)&u ,0);
98 supply_register (SXIP_REGNUM, buf);
99 *(int *) &buf[0] = ptrace (3, inferior_pid, (char *)&u.pt_sigframe.dg_sigframe.sc_snip - (char *)&u ,0);
100 supply_register (SNIP_REGNUM, buf);
101 *(int *) &buf[0] = ptrace (3, inferior_pid, (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u ,0);
102 supply_register (SFIP_REGNUM, buf);
105 /* Store our register values back into the inferior.
106 If REGNO is -1, do this for all registers.
107 Otherwise, REGNO specifies which register (so we can save time). */
109 store_inferior_registers (regno)
112 register unsigned int regaddr;
120 unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
122 #endif /* defined (DGUX) */
125 unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
127 #endif /* defined(BCS) */
128 /* offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; */
133 /* regaddr = register_addr (regno, offset); */
134 if (regno < PC_REGNUM)
136 regaddr = offset + regno * sizeof (int);
138 ptrace (6, inferior_pid, regaddr, read_register (regno));
141 sprintf (buf, "writing register number %d", regno);
142 perror_with_name (buf);
145 else if (regno == SXIP_REGNUM)
146 ptrace (6, inferior_pid, SXIP_OFFSET, read_register(regno));
147 else if (regno == SNIP_REGNUM)
148 ptrace (6, inferior_pid, SNIP_OFFSET, read_register(regno));
149 else if (regno == SFIP_REGNUM)
150 ptrace (6, inferior_pid, SFIP_OFFSET, read_register(regno));
151 else printf ("Bad register number for store_inferior routine\n");
154 for (regno = 0; regno < NUM_REGS - 3; regno++)
156 /* regaddr = register_addr (regno, offset); */
158 regaddr = offset + regno * sizeof (int);
159 ptrace (6, inferior_pid, regaddr, read_register (regno));
162 sprintf (buf, "writing register number %d", regno);
163 perror_with_name (buf);
166 ptrace (6,inferior_pid,SXIP_OFFSET,read_register(SXIP_REGNUM));
167 ptrace (6,inferior_pid,SNIP_OFFSET,read_register(SNIP_REGNUM));
168 ptrace (6,inferior_pid,SFIP_OFFSET,read_register(SFIP_REGNUM));
175 /* Core files are now a function of BFD. */
178 core_file_command (filename, from_tty)
183 extern char registers[];
185 /* Need symbol file and one with tdesc info for corefiles to work */
186 if (!have_symbol_file_p())
187 error ("Requires symbol-file and exec-file");
189 error ("Requires exec-file and symbol-file");
191 /* Discard all vestiges of any previous core file
192 and mark data and stack spaces as empty. */
204 stack_start = STACK_END_ADDR;
205 stack_end = STACK_END_ADDR;
207 /* Now, if a new core file was specified, open it and digest it. */
211 filename = tilde_expand (filename);
212 make_cleanup (free, filename);
214 if (have_inferior_p ())
215 error ("To look at a core file, you must kill the inferior with \"kill\".");
216 corechan = open (filename, O_RDONLY, 0);
218 perror_with_name (filename);
219 /* 4.2-style (and perhaps also sysV-style) core dump file. */
225 val = myread (corechan, &u, sizeof u);
227 perror_with_name (filename);
228 data_start = u.pt_o_data_start;
230 data_end = data_start + u.pt_dsize;
231 stack_start = stack_end - u.pt_ssize;
232 data_offset = u.pt_dataptr;
233 stack_offset = data_offset + u.pt_dsize;
241 #endif /* defined (DGUX) */
245 reg_offset = (int) u.pt_r0 - KERNEL_U_ADDR;
247 #endif /* defined(BCS) */
249 /* I don't know where to find this info.
250 So, for now, mark it as not available. */
251 /* N_SET_MAGIC (core_aouthdr, 0); */
252 bzero ((char *) &core_aouthdr, sizeof core_aouthdr);
254 /* Read the register values out of the core file and store
255 them where `read_register' will find them. */
260 for (regno = 0; regno < NUM_REGS; regno++)
262 char buf[MAX_REGISTER_RAW_SIZE];
264 val = lseek (corechan, register_addr (regno, reg_offset), 0);
266 perror_with_name (filename);
268 val = myread (corechan, buf, sizeof buf);
270 perror_with_name (filename);
271 supply_register (regno, buf);
275 if (filename[0] == '/')
276 corefile = savestring (filename, strlen (filename));
279 corefile = concat (current_directory, "/", filename);
282 current_context = init_dcontext();
283 set_current_frame ( create_new_frame(get_frame_base (read_pc()),
285 select_frame (get_current_frame (), 0);
289 printf ("No core file now.\n");
293 /* blockend is the address of the end of the user structure */
294 m88k_register_u_addr (blockend, regnum)
297 int ustart = blockend - sizeof (struct USER);
331 case 31: return (ustart + ((int) &u.pt_r0 - (int) &u) + sizeof(REGISTER_TYPE) * regnum);
332 case PSR_REGNUM: return (ustart + ((int) &u.pt_psr - (int) &u));
333 case FPSR_REGNUM: return (ustart + ((int) &u.pt_fpsr - (int) &u));
334 case FPCR_REGNUM: return (ustart + ((int) &u.pt_fpcr - (int) &u));
335 case SXIP_REGNUM: return (ustart + SXIP_OFFSET);
336 case SNIP_REGNUM: return (ustart + SNIP_OFFSET);
337 case SFIP_REGNUM: return (ustart + SFIP_OFFSET);
338 default: return (blockend + sizeof (REGISTER_TYPE) * regnum);