1 /* Low level interface to ptrace, for GDB when running under Unix.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/param.h>
28 #include <sys/ioctl.h>
37 /* Work with core dump and executable files, for GDB.
38 This code would be in core.c if it weren't machine-dependent. */
41 core_file_command (filename, from_tty)
46 extern char registers[];
48 /* Discard all vestiges of any previous core file
49 and mark data and stack spaces as empty. */
61 stack_start = STACK_END_ADDR;
62 stack_end = STACK_END_ADDR;
64 /* Now, if a new core file was specified, open it and digest it. */
68 filename = tilde_expand (filename);
69 make_cleanup (free, filename);
71 if (have_inferior_p ())
72 error ("To look at a core file, you must kill the inferior with \"kill\".");
73 corechan = open (filename, O_RDONLY, 0);
75 perror_with_name (filename);
76 /* 4.2-style (and perhaps also sysV-style) core dump file. */
81 val = myread (corechan, &u, sizeof u);
83 perror_with_name (filename);
84 data_start = exec_data_start;
86 data_end = data_start + NBPG * u.u_dsize;
87 stack_start = stack_end - NBPG * u.u_ssize;
88 data_offset = NBPG * UPAGES;
89 stack_offset = NBPG * (UPAGES + u.u_dsize);
90 reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR;
92 /* I don't know where to find this info.
93 So, for now, mark it as not available. */
94 core_aouthdr.a_magic = 0;
96 /* Read the register values out of the core file and store
97 them where `read_register' will find them. */
102 for (regno = 0; regno < NUM_REGS; regno++)
104 char buf[MAX_REGISTER_RAW_SIZE];
106 val = lseek (corechan, register_addr (regno, reg_offset), 0);
108 perror_with_name (filename);
110 val = myread (corechan, buf, sizeof buf);
112 perror_with_name (filename);
113 supply_register (regno, buf);
117 if (filename[0] == '/')
118 corefile = savestring (filename, strlen (filename));
121 corefile = concat (current_directory, "/", filename, NULL);
124 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
126 select_frame (get_current_frame (), 0);
130 printf ("No core file now.\n");