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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include <sys/param.h>
28 #include <sys/ioctl.h>
32 #include <sys/ptrace.h>
33 #define PTRACE_ATTACH PT_ATTACH
34 #define PTRACE_DETACH PT_FREEPROC
39 /* Work with core dump and executable files, for GDB.
40 This code would be in corefile.c if it weren't machine-dependent. */
43 core_file_command (filename
, from_tty
)
49 /* Discard all vestiges of any previous core file
50 and mark data and stack spaces as empty. */
62 stack_start
= STACK_END_ADDR
;
63 stack_end
= STACK_END_ADDR
;
65 /* Now, if a new core file was specified, open it and digest it. */
69 filename
= tilde_expand (filename
);
70 make_cleanup (free
, filename
);
72 if (have_inferior_p ())
73 error ("To look at a core file, you must kill the program with \"kill\".");
74 corechan
= open (filename
, O_RDONLY
, 0);
76 perror_with_name (filename
);
77 /* 4.2-style (and perhaps also sysV-style) core dump file. */
82 val
= myread (corechan
, &u
, sizeof u
);
84 perror_with_name (filename
);
85 data_start
= exec_data_start
;
87 data_end
= data_start
+ u
.pt_dsize
;
88 stack_start
= stack_end
- u
.pt_ssize
;
89 data_offset
= sizeof u
;
90 stack_offset
= data_offset
+ u
.pt_dsize
;
93 memcpy (&core_aouthdr
, &u
.pt_aouthdr
, sizeof (AOUTHDR
));
94 printf_unfiltered ("Core file is from \"%s\".\n", u
.pt_comm
);
96 printf_unfiltered ("Program terminated with signal %d, %s.\n",
97 u
.pt_signal
, safe_strsignal (u
.pt_signal
));
99 /* Read the register values out of the core file and store
100 them where `read_register' will find them. */
105 for (regno
= 0; regno
< NUM_REGS
; regno
++)
107 char buf
[MAX_REGISTER_RAW_SIZE
];
109 val
= lseek (corechan
, register_addr (regno
, reg_offset
), 0);
111 perror_with_name (filename
);
113 val
= myread (corechan
, buf
, sizeof buf
);
115 perror_with_name (filename
);
116 supply_register (regno
, buf
);
120 if (filename
[0] == '/')
121 corefile
= savestring (filename
, strlen (filename
));
124 corefile
= concat (current_directory
, "/", filename
, NULL
);
127 flush_cached_frames ();
128 select_frame (get_current_frame (), 0);
132 printf_unfiltered ("No core file now.\n");