Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Low level interface to ptrace, for GDB when running under m68k SVR2 Unix |
2 | on Altos 3068. Report bugs to Jyrki Kuoppala <jkp@cs.hut.fi> | |
3 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | ||
25 | #ifdef USG | |
26 | #include <sys/types.h> | |
27 | #endif | |
28 | ||
29 | #include <sys/param.h> | |
30 | #include <sys/dir.h> | |
31 | #include <signal.h> | |
32 | #include <sys/ioctl.h> | |
33 | #include <fcntl.h> | |
34 | #ifdef USG | |
35 | #include <sys/page.h> | |
36 | #ifdef ALTOS | |
37 | #include <sys/net.h> | |
38 | #include <errno.h> | |
39 | #endif | |
40 | #endif | |
41 | ||
42 | #include "gdbcore.h" | |
43 | #include <sys/user.h> /* After a.out.h */ | |
44 | #include <sys/file.h> | |
45 | #include "gdb_stat.h" | |
46 | ||
47 | \f | |
48 | /* Work with core dump and executable files, for GDB. | |
49 | This code would be in corefile.c if it weren't machine-dependent. */ | |
50 | ||
51 | void | |
52 | core_file_command (filename, from_tty) | |
53 | char *filename; | |
54 | int from_tty; | |
55 | { | |
56 | int val; | |
c906108c SS |
57 | |
58 | /* Discard all vestiges of any previous core file | |
59 | and mark data and stack spaces as empty. */ | |
60 | ||
61 | if (corefile) | |
62 | free (corefile); | |
63 | corefile = 0; | |
64 | ||
65 | if (corechan >= 0) | |
66 | close (corechan); | |
67 | corechan = -1; | |
68 | ||
69 | data_start = 0; | |
70 | data_end = 0; | |
71 | stack_start = STACK_END_ADDR; | |
72 | stack_end = STACK_END_ADDR; | |
73 | ||
74 | /* Now, if a new core file was specified, open it and digest it. */ | |
75 | ||
76 | if (filename) | |
77 | { | |
78 | filename = tilde_expand (filename); | |
79 | make_cleanup (free, filename); | |
80 | ||
81 | if (have_inferior_p ()) | |
82 | error ("To look at a core file, you must kill the program with \"kill\"."); | |
83 | corechan = open (filename, O_RDONLY, 0); | |
84 | if (corechan < 0) | |
85 | perror_with_name (filename); | |
86 | /* 4.2-style (and perhaps also sysV-style) core dump file. */ | |
87 | { | |
88 | struct user u; | |
89 | ||
90 | unsigned int reg_offset; | |
91 | ||
92 | val = myread (corechan, &u, sizeof u); | |
93 | if (val < 0) | |
94 | perror_with_name ("Not a core file: reading upage"); | |
95 | if (val != sizeof u) | |
96 | error ("Not a core file: could only read %d bytes", val); | |
97 | data_start = exec_data_start; | |
98 | ||
99 | #if !defined (NBPG) | |
100 | #define NBPG NBPP | |
101 | #endif | |
102 | #if !defined (UPAGES) | |
103 | #define UPAGES USIZE | |
104 | #endif | |
105 | ||
106 | data_end = data_start + NBPG * u.u_dsize; | |
107 | stack_start = stack_end - NBPG * u.u_ssize; | |
108 | data_offset = NBPG * UPAGES + exec_data_start % NBPG /* Not sure about this //jkp */; | |
109 | stack_offset = NBPG * (UPAGES + u.u_dsize); | |
110 | ||
111 | /* Some machines put an absolute address in here and some put | |
112 | the offset in the upage of the regs. */ | |
113 | reg_offset = (int) u.u_state; | |
114 | if (reg_offset > NBPG * UPAGES) | |
115 | reg_offset -= KERNEL_U_ADDR; | |
116 | ||
117 | memcpy (&core_aouthdr, &u.u_exdata, sizeof (AOUTHDR)); | |
118 | printf_unfiltered ("Core file is from \"%s\".\n", u.u_comm); | |
119 | ||
120 | /* I don't know where to find this info. | |
121 | So, for now, mark it as not available. */ | |
122 | N_SET_MAGIC (core_aouthdr, 0); | |
123 | ||
124 | /* Read the register values out of the core file and store | |
125 | them where `read_register' will find them. */ | |
126 | ||
127 | { | |
128 | register int regno; | |
129 | ||
130 | for (regno = 0; regno < NUM_REGS; regno++) | |
131 | { | |
132 | char buf[MAX_REGISTER_RAW_SIZE]; | |
133 | ||
134 | val = lseek (corechan, register_addr (regno, reg_offset), 0); | |
135 | if (val < 0 | |
136 | || (val = myread (corechan, buf, sizeof buf)) < 0) | |
137 | { | |
138 | char * buffer = (char *) alloca (strlen (REGISTER_NAME (regno)) | |
139 | + 30); | |
140 | strcpy (buffer, "Reading register "); | |
141 | strcat (buffer, REGISTER_NAME (regno)); | |
142 | ||
143 | perror_with_name (buffer); | |
144 | } | |
145 | ||
146 | supply_register (regno, buf); | |
147 | } | |
148 | } | |
149 | } | |
150 | if (filename[0] == '/') | |
151 | corefile = savestring (filename, strlen (filename)); | |
152 | else | |
153 | { | |
154 | corefile = concat (current_directory, "/", filename, NULL); | |
155 | } | |
156 | ||
157 | flush_cached_frames (); | |
158 | select_frame (get_current_frame (), 0); | |
159 | validate_files (); | |
160 | } | |
161 | else if (from_tty) | |
162 | printf_unfiltered ("No core file now.\n"); | |
163 | } |