1 /* Low level interface to ptrace, for GDB when running under m68k SVR2 Unix
3 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include <sys/types.h>
31 #include <sys/param.h>
34 #include <sys/ioctl.h>
45 #include <sys/user.h> /* After a.out.h */
49 /* Work with core dump and executable files, for GDB.
50 This code would be in core.c if it weren't machine-dependent. */
53 core_file_command (filename, from_tty)
58 extern char registers[];
60 /* Discard all vestiges of any previous core file
61 and mark data and stack spaces as empty. */
73 stack_start = STACK_END_ADDR;
74 stack_end = STACK_END_ADDR;
76 /* Now, if a new core file was specified, open it and digest it. */
80 filename = tilde_expand (filename);
81 make_cleanup (free, filename);
83 if (have_inferior_p ())
84 error ("To look at a core file, you must kill the inferior with \"kill\".");
85 corechan = open (filename, O_RDONLY, 0);
87 perror_with_name (filename);
88 /* 4.2-style (and perhaps also sysV-style) core dump file. */
92 unsigned int reg_offset;
94 val = myread (corechan, &u, sizeof u);
96 perror_with_name ("Not a core file: reading upage");
98 error ("Not a core file: could only read %d bytes", val);
99 data_start = exec_data_start;
104 #if !defined (UPAGES)
108 data_end = data_start + NBPG * u.u_dsize;
109 stack_start = stack_end - NBPG * u.u_ssize;
110 data_offset = NBPG * UPAGES + exec_data_start % NBPG /* Not sure about this //jkp */;
111 stack_offset = NBPG * (UPAGES + u.u_dsize);
113 /* Some machines put an absolute address in here and some put
114 the offset in the upage of the regs. */
115 reg_offset = (int) u.u_state;
116 if (reg_offset > NBPG * UPAGES)
117 reg_offset -= KERNEL_U_ADDR;
119 bcopy (&u.u_exdata, &core_aouthdr, sizeof (AOUTHDR));
120 printf ("Core file is from \"%s\".\n", u.u_comm);
122 /* I don't know where to find this info.
123 So, for now, mark it as not available. */
124 N_SET_MAGIC (core_aouthdr, 0);
126 /* Read the register values out of the core file and store
127 them where `read_register' will find them. */
132 for (regno = 0; regno < NUM_REGS; regno++)
134 char buf[MAX_REGISTER_RAW_SIZE];
136 val = lseek (corechan, register_addr (regno, reg_offset), 0);
138 || (val = myread (corechan, buf, sizeof buf)) < 0)
140 char * buffer = (char *) alloca (strlen (reg_names[regno])
142 strcpy (buffer, "Reading register ");
143 strcat (buffer, reg_names[regno]);
145 perror_with_name (buffer);
148 supply_register (regno, buf);
152 if (filename[0] == '/')
153 corefile = savestring (filename, strlen (filename));
156 corefile = concat (current_directory, "/", filename, NULL);
159 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
161 select_frame (get_current_frame (), 0);
165 printf ("No core file now.\n");