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>
47 /* define offsets to the pc instruction offsets in ptrace_user struct */
48 #define SXIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sxip - \
51 #define SNIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_snip - \
54 #define SFIP_OFFSET (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u
55 extern int have_symbol_file_p();
57 extern jmp_buf stack_jmp;
60 extern char registers[REGISTER_BYTES];
63 fetch_inferior_registers ()
66 register unsigned int regaddr;
67 char buf[MAX_REGISTER_RAW_SIZE];
73 offset = (char *) &u.pt_r0 - (char *) &u;
74 regaddr = offset; /* byte offset to r0;*/
76 /* offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; */
77 for (regno = 0; regno < NUM_REGS; regno++)
79 /*regaddr = register_addr (regno, offset);*/
82 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
84 *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0);
85 regaddr += sizeof (int);
87 supply_register (regno, buf);
89 /* now load up registers 36 - 38; special pc registers */
90 *(int *) &buf[0] = ptrace (3,inferior_pid,(char *)&u.pt_sigframe.dg_sigframe.sc_sxip - (char *)&u ,0);
91 supply_register (SXIP_REGNUM, buf);
92 *(int *) &buf[0] = ptrace (3, inferior_pid, (char *)&u.pt_sigframe.dg_sigframe.sc_snip - (char *)&u ,0);
93 supply_register (SNIP_REGNUM, buf);
94 *(int *) &buf[0] = ptrace (3, inferior_pid, (char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u ,0);
95 supply_register (SFIP_REGNUM, buf);
98 /* Store our register values back into the inferior.
99 If REGNO is -1, do this for all registers.
100 Otherwise, REGNO specifies which register (so we can save time). */
102 store_inferior_registers (regno)
105 register unsigned int regaddr;
113 unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
115 #endif /* defined (DGUX) */
118 unsigned int offset = (char *) &u.pt_r0 - (char *) &u;
120 #endif /* defined(BCS) */
121 /* offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; */
126 /* regaddr = register_addr (regno, offset); */
127 if (regno < PC_REGNUM)
129 regaddr = offset + regno * sizeof (int);
131 ptrace (6, inferior_pid, regaddr, read_register (regno));
134 sprintf (buf, "writing register number %d", regno);
135 perror_with_name (buf);
138 else if (regno == SXIP_REGNUM)
139 ptrace (6, inferior_pid, SXIP_OFFSET, read_register(regno));
140 else if (regno == SNIP_REGNUM)
141 ptrace (6, inferior_pid, SNIP_OFFSET, read_register(regno));
142 else if (regno == SFIP_REGNUM)
143 ptrace (6, inferior_pid, SFIP_OFFSET, read_register(regno));
144 else printf ("Bad register number for store_inferior routine\n");
147 for (regno = 0; regno < NUM_REGS - 3; regno++)
149 /* regaddr = register_addr (regno, offset); */
151 regaddr = offset + regno * sizeof (int);
152 ptrace (6, inferior_pid, regaddr, read_register (regno));
155 sprintf (buf, "writing register number %d", regno);
156 perror_with_name (buf);
159 ptrace (6,inferior_pid,SXIP_OFFSET,read_register(SXIP_REGNUM));
160 ptrace (6,inferior_pid,SNIP_OFFSET,read_register(SNIP_REGNUM));
161 ptrace (6,inferior_pid,SFIP_OFFSET,read_register(SFIP_REGNUM));
168 /* Core files are now a function of BFD. */
171 core_file_command (filename, from_tty)
176 extern char registers[];
178 /* Need symbol file and one with tdesc info for corefiles to work */
179 if (!have_symbol_file_p())
180 error ("Requires symbol-file and exec-file");
182 error ("Requires exec-file and symbol-file");
184 /* Discard all vestiges of any previous core file
185 and mark data and stack spaces as empty. */
197 stack_start = STACK_END_ADDR;
198 stack_end = STACK_END_ADDR;
200 /* Now, if a new core file was specified, open it and digest it. */
204 filename = tilde_expand (filename);
205 make_cleanup (free, filename);
207 if (have_inferior_p ())
208 error ("To look at a core file, you must kill the inferior with \"kill\".");
209 corechan = open (filename, O_RDONLY, 0);
211 perror_with_name (filename);
212 /* 4.2-style (and perhaps also sysV-style) core dump file. */
218 val = myread (corechan, &u, sizeof u);
220 perror_with_name (filename);
221 data_start = u.pt_o_data_start;
223 data_end = data_start + u.pt_dsize;
224 stack_start = stack_end - u.pt_ssize;
225 data_offset = u.pt_dataptr;
226 stack_offset = data_offset + u.pt_dsize;
234 #endif /* defined (DGUX) */
238 reg_offset = (int) u.pt_r0 - KERNEL_U_ADDR;
240 #endif /* defined(BCS) */
242 /* I don't know where to find this info.
243 So, for now, mark it as not available. */
244 /* N_SET_MAGIC (core_aouthdr, 0); */
245 bzero ((char *) &core_aouthdr, sizeof core_aouthdr);
247 /* Read the register values out of the core file and store
248 them where `read_register' will find them. */
253 for (regno = 0; regno < NUM_REGS; regno++)
255 char buf[MAX_REGISTER_RAW_SIZE];
257 val = lseek (corechan, register_addr (regno, reg_offset), 0);
259 perror_with_name (filename);
261 val = myread (corechan, buf, sizeof buf);
263 perror_with_name (filename);
264 supply_register (regno, buf);
268 if (filename[0] == '/')
269 corefile = savestring (filename, strlen (filename));
272 corefile = concat (current_directory, "/", filename);
275 current_context = init_dcontext();
276 set_current_frame ( create_new_frame(get_frame_base (read_pc()),
278 select_frame (get_current_frame (), 0);
282 printf ("No core file now.\n");
286 /* blockend is the address of the end of the user structure */
287 m88k_register_u_addr (blockend, regnum)
290 int ustart = blockend - sizeof (struct USER);
324 case 31: return (ustart + ((int) &u.pt_r0 - (int) &u) + sizeof(REGISTER_TYPE) * regnum);
325 case PSR_REGNUM: return (ustart + ((int) &u.pt_psr - (int) &u));
326 case FPSR_REGNUM: return (ustart + ((int) &u.pt_fpsr - (int) &u));
327 case FPCR_REGNUM: return (ustart + ((int) &u.pt_fpcr - (int) &u));
328 case SXIP_REGNUM: return (ustart + SXIP_OFFSET);
329 case SNIP_REGNUM: return (ustart + SNIP_OFFSET);
330 case SFIP_REGNUM: return (ustart + SFIP_OFFSET);
331 default: return (blockend + sizeof (REGISTER_TYPE) * regnum);