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 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This file is part of GDB.
10 This program 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 2 of the License, or
13 (at your option) any later version.
15 This program 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.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #include <sys/types.h>
32 #include <sys/param.h>
35 #include <sys/ioctl.h>
36 /* #include <fcntl.h> Can we live without this? */
40 #include <machine/pcb.h>
42 #include "/usr/src/sys/hpux/hpux.h"
43 #define USRSTACK 0x68FF3000
45 #include <sys/user.h> /* After a.out.h */
50 #include <sys/ptrace.h>
62 /* File names of core file and executable file. */
64 extern char *corefile
;
65 extern char *execfile
;
67 /* Descriptors on which core file and executable file are open.
68 Note that the execchan is closed when an inferior is created
69 and reopened if the inferior dies or is killed. */
74 /* Last modification time of executable file.
75 Also used in source.c to compare against mtime of a source file. */
77 extern int exec_mtime
;
79 /* Virtual addresses of bounds of the two areas of memory in the core file. */
81 extern CORE_ADDR data_start
;
82 extern CORE_ADDR data_end
;
83 extern CORE_ADDR stack_start
;
84 extern CORE_ADDR stack_end
;
86 /* Virtual addresses of bounds of two areas of memory in the exec file.
87 Note that the data area in the exec file is used only when there is no core file. */
89 extern CORE_ADDR text_start
;
90 extern CORE_ADDR text_end
;
92 extern CORE_ADDR exec_data_start
;
93 extern CORE_ADDR exec_data_end
;
95 /* Address in executable file of start of text area data. */
97 extern int text_offset
;
99 /* Address in executable file of start of data area data. */
101 extern int exec_data_offset
;
103 /* Address in core file of start of data area data. */
105 extern int data_offset
;
107 /* Address in core file of start of stack area data. */
109 extern int stack_offset
;
111 extern struct header file_hdr
;
112 extern struct som_exec_auxhdr exec_hdr
;
114 extern int (*core_file_hook
)();
118 extern int kernel_debugging
;
119 extern int kernel_core_file_hook();
123 core_file_command (filename
, from_tty
)
128 extern char registers
[];
133 /* Discard all vestiges of any previous core file
134 and mark data and stack spaces as empty. */
147 stack_start
= STACK_END_ADDR
;
148 stack_end
= STACK_END_ADDR
;
150 /* Now, if a new core file was specified, open it and digest it. */
154 filename
= tilde_expand (filename
);
155 make_cleanup (free
, filename
);
157 if (have_inferior_p ())
158 error ("To look at a core file, you must kill the inferior with \"kill\".");
159 corechan
= open (filename
, O_RDONLY
, 0);
161 perror_with_name (filename
);
164 fstat(corechan
, &stb
);
166 if (kernel_debugging
) {
167 setup_kernel_debugging();
168 core_file_hook
= kernel_core_file_hook
;
169 set_kernel_boundaries();
170 } else if ((stb
.st_mode
& S_IFMT
) == S_IFCHR
&&
171 stb
.st_rdev
== makedev(2, 1)) {
172 /* looking at /dev/kmem */
173 data_offset
= data_start
= KERNBASE
;
174 data_end
= ~0; /* XXX */
175 stack_end
= stack_start
= data_end
;
176 set_kernel_boundaries();
180 /* HP PA-RISC style corefile. */
187 unsigned int reg_offset
;
189 val
= myread (corechan
, &u
, sizeof u
);
191 perror_with_name ("Not a core file: reading upage");
193 error ("Not a core file: could only read %d bytes", val
);
195 /* We are depending on exec_file_command having been called
196 previously to set exec_data_start. Since the executable
197 and the core file share the same text segment, the address
198 of the data segment will be the same in both. */
199 data_start
= exec_data_start
;
201 data_end
= data_start
+ NBPG
* u
.u_dsize
;
202 stack_start
= USRSTACK
; /* from sys/param.h */
203 stack_end
= stack_start
+ NBPG
* u
.u_ssize
;
204 data_offset
= NBPG
* UPAGES
;
205 stack_offset
= NBPG
* (UPAGES
+ u
.u_dsize
);
207 /* Some machines put an absolute address in here and some put
208 the offset in the upage of the regs. */
209 reg_offset
= NBPG
* USIZE
;
210 /* Read the register values out of the core file and store
211 them where `read_register' will find them. */
216 for (regno
= 0; regno
< NUM_REGS
; regno
++)
218 unsigned char buf
[MAX_REGISTER_RAW_SIZE
];
220 val
= lseek (corechan
, register_addr (regno
, reg_offset
), 0);
222 || (val
= myread (corechan
, buf
, sizeof buf
)) < 0)
224 char * buffer
= (char *) alloca (strlen (reg_names
[regno
])
226 strcpy (buffer
, "Reading register ");
227 strcat (buffer
, reg_names
[regno
]);
229 perror_with_name (buffer
);
231 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
233 supply_register (regno
, buf
);
237 if (filename
[0] == '/')
238 corefile
= savestring (filename
, strlen (filename
));
241 corefile
= concat (current_directory
, "/", filename
);
244 set_current_frame ( create_new_frame (read_register (FP_REGNUM
),
246 select_frame (get_current_frame (), 0);
250 printf ("No core file now.\n");