Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* umax host stuff. |
2 | Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | ||
25 | #include <sys/param.h> | |
26 | #include <sys/dir.h> | |
27 | #include <signal.h> | |
28 | #include <sys/ioctl.h> | |
29 | #include <fcntl.h> | |
30 | ||
31 | #include "gdbcore.h" | |
32 | #include <sys/ptrace.h> | |
33 | #define PTRACE_ATTACH PT_ATTACH | |
34 | #define PTRACE_DETACH PT_FREEPROC | |
35 | ||
36 | #include <sys/file.h> | |
37 | #include "gdb_stat.h" | |
38 | ||
39 | /* Work with core dump and executable files, for GDB. | |
40 | This code would be in corefile.c if it weren't machine-dependent. */ | |
41 | ||
42 | void | |
fba45db2 | 43 | core_file_command (char *filename, int from_tty) |
c906108c SS |
44 | { |
45 | int val; | |
c906108c SS |
46 | |
47 | /* Discard all vestiges of any previous core file | |
48 | and mark data and stack spaces as empty. */ | |
49 | ||
50 | if (corefile) | |
b8c9b27d | 51 | xfree (corefile); |
c906108c SS |
52 | corefile = 0; |
53 | ||
54 | if (corechan >= 0) | |
55 | close (corechan); | |
56 | corechan = -1; | |
57 | ||
58 | data_start = 0; | |
59 | data_end = 0; | |
60 | stack_start = STACK_END_ADDR; | |
61 | stack_end = STACK_END_ADDR; | |
62 | ||
63 | /* Now, if a new core file was specified, open it and digest it. */ | |
64 | ||
65 | if (filename) | |
66 | { | |
67 | filename = tilde_expand (filename); | |
b8c9b27d | 68 | make_cleanup (xfree, filename); |
c5aa993b | 69 | |
c906108c SS |
70 | if (have_inferior_p ()) |
71 | error ("To look at a core file, you must kill the program with \"kill\"."); | |
72 | corechan = open (filename, O_RDONLY, 0); | |
73 | if (corechan < 0) | |
74 | perror_with_name (filename); | |
75 | /* 4.2-style (and perhaps also sysV-style) core dump file. */ | |
76 | { | |
77 | struct ptrace_user u; | |
78 | int reg_offset; | |
79 | ||
80 | val = myread (corechan, &u, sizeof u); | |
81 | if (val < 0) | |
82 | perror_with_name (filename); | |
83 | data_start = exec_data_start; | |
84 | ||
85 | data_end = data_start + u.pt_dsize; | |
86 | stack_start = stack_end - u.pt_ssize; | |
87 | data_offset = sizeof u; | |
88 | stack_offset = data_offset + u.pt_dsize; | |
89 | reg_offset = 0; | |
90 | ||
91 | memcpy (&core_aouthdr, &u.pt_aouthdr, sizeof (AOUTHDR)); | |
92 | printf_unfiltered ("Core file is from \"%s\".\n", u.pt_comm); | |
93 | if (u.pt_signal > 0) | |
94 | printf_unfiltered ("Program terminated with signal %d, %s.\n", | |
c5aa993b | 95 | u.pt_signal, safe_strsignal (u.pt_signal)); |
c906108c SS |
96 | |
97 | /* Read the register values out of the core file and store | |
98 | them where `read_register' will find them. */ | |
99 | ||
100 | { | |
101 | register int regno; | |
102 | ||
103 | for (regno = 0; regno < NUM_REGS; regno++) | |
104 | { | |
105 | char buf[MAX_REGISTER_RAW_SIZE]; | |
106 | ||
107 | val = lseek (corechan, register_addr (regno, reg_offset), 0); | |
108 | if (val < 0) | |
109 | perror_with_name (filename); | |
110 | ||
c5aa993b | 111 | val = myread (corechan, buf, sizeof buf); |
c906108c SS |
112 | if (val < 0) |
113 | perror_with_name (filename); | |
114 | supply_register (regno, buf); | |
115 | } | |
116 | } | |
117 | } | |
118 | if (filename[0] == '/') | |
119 | corefile = savestring (filename, strlen (filename)); | |
120 | else | |
121 | { | |
122 | corefile = concat (current_directory, "/", filename, NULL); | |
123 | } | |
124 | ||
125 | flush_cached_frames (); | |
126 | select_frame (get_current_frame (), 0); | |
127 | validate_files (); | |
128 | } | |
129 | else if (from_tty) | |
130 | printf_unfiltered ("No core file now.\n"); | |
131 | } |