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. */
26 #include <sys/param.h>
29 #include <sys/ioctl.h>
33 #include <sys/ptrace.h>
34 #define PTRACE_ATTACH PT_ATTACH
35 #define PTRACE_DETACH PT_FREEPROC
40 /* Work with core dump and executable files, for GDB.
41 This code would be in core.c if it weren't machine-dependent. */
44 core_file_command (filename, from_tty)
49 extern char registers[];
51 /* Discard all vestiges of any previous core file
52 and mark data and stack spaces as empty. */
64 stack_start = STACK_END_ADDR;
65 stack_end = STACK_END_ADDR;
67 /* Now, if a new core file was specified, open it and digest it. */
71 filename = tilde_expand (filename);
72 make_cleanup (free, filename);
74 if (have_inferior_p ())
75 error ("To look at a core file, you must kill the inferior with \"kill\".");
76 corechan = open (filename, O_RDONLY, 0);
78 perror_with_name (filename);
79 /* 4.2-style (and perhaps also sysV-style) core dump file. */
84 val = myread (corechan, &u, sizeof u);
86 perror_with_name (filename);
87 data_start = exec_data_start;
89 data_end = data_start + u.pt_dsize;
90 stack_start = stack_end - u.pt_ssize;
91 data_offset = sizeof u;
92 stack_offset = data_offset + u.pt_dsize;
95 bcopy (&u.pt_aouthdr, &core_aouthdr, sizeof (AOUTHDR));
96 printf ("Core file is from \"%s\".\n", u.pt_comm);
98 printf ("Program terminated with signal %d, %s.\n",
101 ? sys_siglist[u.pt_signal]
104 /* Read the register values out of the core file and store
105 them where `read_register' will find them. */
110 for (regno = 0; regno < NUM_REGS; regno++)
112 char buf[MAX_REGISTER_RAW_SIZE];
114 val = lseek (corechan, register_addr (regno, reg_offset), 0);
116 perror_with_name (filename);
118 val = myread (corechan, buf, sizeof buf);
120 perror_with_name (filename);
121 supply_register (regno, buf);
125 if (filename[0] == '/')
126 corefile = savestring (filename, strlen (filename));
129 corefile = concat (current_directory, "/", filename);
132 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
134 select_frame (get_current_frame (), 0);
138 printf ("No core file now.\n");