HPPA merge.
[deliverable/binutils-gdb.git] / gdb / hppabsd-core.c
1 /* Machine-dependent code which would otherwise be in core.c
2 for GDB, the GNU debugger. This code is for the HP PA-RISC cpu.
3 Copyright (C) 1986, 1987, 1989, 1990, 1991 Free Software Foundation, Inc.
4
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
7
8 This file is part of GDB.
9
10 GDB is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 1, or (at your option)
13 any later version.
14
15 GDB is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GDB; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24 #include <stdio.h>
25 #include "defs.h"
26 #include "param.h"
27 #include "frame.h"
28 #include "inferior.h"
29
30 #ifdef USG
31 #include <sys/types.h>
32 #endif
33
34 #include <sys/param.h>
35 #include <sys/dir.h>
36 #include <signal.h>
37 #include <sys/ioctl.h>
38 /* #include <fcntl.h> Can we live without this? */
39
40 #ifndef hpux
41 #include <a.out.h>
42 #include <machine/pcb.h>
43 #include <sys/time.h>
44 #include "/usr/src/sys/hpux/hpux.h"
45 #define USRSTACK 0x68FF3000
46 #else
47 #include <sys/user.h> /* After a.out.h */
48 #endif
49
50 #include <sys/file.h>
51 #include <sys/stat.h>
52 #include <sys/ptrace.h>
53
54 #ifndef hpux
55 #undef USIZE
56 #undef UPAGES
57
58 #define USIZE 3
59 #define UPAGES 7
60 #endif
61
62 extern int errno;
63
64 /* File names of core file and executable file. */
65
66 extern char *corefile;
67 extern char *execfile;
68
69 /* Descriptors on which core file and executable file are open.
70 Note that the execchan is closed when an inferior is created
71 and reopened if the inferior dies or is killed. */
72
73 extern int corechan;
74 extern int execchan;
75
76 /* Last modification time of executable file.
77 Also used in source.c to compare against mtime of a source file. */
78
79 extern int exec_mtime;
80
81 /* Virtual addresses of bounds of the two areas of memory in the core file. */
82
83 extern CORE_ADDR data_start;
84 extern CORE_ADDR data_end;
85 extern CORE_ADDR stack_start;
86 extern CORE_ADDR stack_end;
87
88 /* Virtual addresses of bounds of two areas of memory in the exec file.
89 Note that the data area in the exec file is used only when there is no core file. */
90
91 extern CORE_ADDR text_start;
92 extern CORE_ADDR text_end;
93
94 extern CORE_ADDR exec_data_start;
95 extern CORE_ADDR exec_data_end;
96
97 /* Address in executable file of start of text area data. */
98
99 extern int text_offset;
100
101 /* Address in executable file of start of data area data. */
102
103 extern int exec_data_offset;
104
105 /* Address in core file of start of data area data. */
106
107 extern int data_offset;
108
109 /* Address in core file of start of stack area data. */
110
111 extern int stack_offset;
112
113 extern struct header file_hdr;
114 extern struct som_exec_auxhdr exec_hdr;
115
116 extern int (*core_file_hook)();
117
118 #ifdef KERNELDEBUG
119
120 extern int kernel_debugging;
121 extern int kernel_core_file_hook();
122
123 #endif
124
125 core_file_command (filename, from_tty)
126 char *filename;
127 int from_tty;
128 {
129 int val;
130 extern char registers[];
131 #ifdef KERNELDEBUG
132 struct stat stb;
133 #endif
134
135 /* Discard all vestiges of any previous core file
136 and mark data and stack spaces as empty. */
137
138 if (corefile)
139 free (corefile);
140 corefile = 0;
141 core_file_hook = 0;
142
143 if (corechan >= 0)
144 close (corechan);
145 corechan = -1;
146
147 data_start = 0;
148 data_end = 0;
149 stack_start = STACK_END_ADDR;
150 stack_end = STACK_END_ADDR;
151
152 /* Now, if a new core file was specified, open it and digest it. */
153
154 if (filename)
155 {
156 filename = tilde_expand (filename);
157 make_cleanup (free, filename);
158
159 if (have_inferior_p ())
160 error ("To look at a core file, you must kill the inferior with \"kill\".");
161 corechan = open (filename, O_RDONLY, 0);
162 if (corechan < 0)
163 perror_with_name (filename);
164
165 #ifdef KERNELDEBUG
166 fstat(corechan, &stb);
167
168 if (kernel_debugging) {
169 setup_kernel_debugging();
170 core_file_hook = kernel_core_file_hook;
171 set_kernel_boundaries();
172 } else if ((stb.st_mode & S_IFMT) == S_IFCHR &&
173 stb.st_rdev == makedev(2, 1)) {
174 /* looking at /dev/kmem */
175 data_offset = data_start = KERNBASE;
176 data_end = ~0; /* XXX */
177 stack_end = stack_start = data_end;
178 set_kernel_boundaries();
179 } else
180 #endif
181 {
182 /* HP PA-RISC style corefile. */
183 #ifndef hpux
184 struct hpuxuser u;
185 #else
186 struct user u;
187 #endif
188
189 unsigned int reg_offset;
190
191 val = myread (corechan, &u, sizeof u);
192 if (val < 0)
193 perror_with_name ("Not a core file: reading upage");
194 if (val != sizeof u)
195 error ("Not a core file: could only read %d bytes", val);
196
197 /* We are depending on exec_file_command having been called
198 previously to set exec_data_start. Since the executable
199 and the core file share the same text segment, the address
200 of the data segment will be the same in both. */
201 data_start = exec_data_start;
202
203 data_end = data_start + NBPG * u.u_dsize;
204 stack_start = USRSTACK; /* from sys/param.h */
205 stack_end = stack_start + NBPG * u.u_ssize;
206 data_offset = NBPG * UPAGES;
207 stack_offset = NBPG * (UPAGES + u.u_dsize);
208
209 /* Some machines put an absolute address in here and some put
210 the offset in the upage of the regs. */
211 reg_offset = NBPG * USIZE;
212 /* Read the register values out of the core file and store
213 them where `read_register' will find them. */
214
215 {
216 register int regno;
217
218 for (regno = 0; regno < NUM_REGS; regno++)
219 {
220 unsigned char buf[MAX_REGISTER_RAW_SIZE];
221
222 val = lseek (corechan, register_addr (regno, reg_offset), 0);
223 if (val < 0
224 || (val = myread (corechan, buf, sizeof buf)) < 0)
225 {
226 char * buffer = (char *) alloca (strlen (reg_names[regno])
227 + 30);
228 strcpy (buffer, "Reading register ");
229 strcat (buffer, reg_names[regno]);
230
231 perror_with_name (buffer);
232 }
233 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
234 buf[3] &= ~0x3;
235 supply_register (regno, buf);
236 }
237 }
238 }
239 if (filename[0] == '/')
240 corefile = savestring (filename, strlen (filename));
241 else
242 {
243 corefile = concat (current_directory, "/", filename);
244 }
245
246 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
247 read_pc ()));
248 select_frame (get_current_frame (), 0);
249 validate_files ();
250 }
251 else if (from_tty)
252 printf ("No core file now.\n");
253 }
254
This page took 0.043853 seconds and 4 git commands to generate.