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.
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 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)
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.
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. */
31 #include <sys/types.h>
34 #include <sys/param.h>
37 #include <sys/ioctl.h>
38 /* #include <fcntl.h> Can we live without this? */
42 #include <machine/pcb.h>
44 #include "/usr/src/sys/hpux/hpux.h"
45 #define USRSTACK 0x68FF3000
47 #include <sys/user.h> /* After a.out.h */
52 #include <sys/ptrace.h>
64 /* File names of core file and executable file. */
66 extern char *corefile
;
67 extern char *execfile
;
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. */
76 /* Last modification time of executable file.
77 Also used in source.c to compare against mtime of a source file. */
79 extern int exec_mtime
;
81 /* Virtual addresses of bounds of the two areas of memory in the core file. */
83 extern CORE_ADDR data_start
;
84 extern CORE_ADDR data_end
;
85 extern CORE_ADDR stack_start
;
86 extern CORE_ADDR stack_end
;
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. */
91 extern CORE_ADDR text_start
;
92 extern CORE_ADDR text_end
;
94 extern CORE_ADDR exec_data_start
;
95 extern CORE_ADDR exec_data_end
;
97 /* Address in executable file of start of text area data. */
99 extern int text_offset
;
101 /* Address in executable file of start of data area data. */
103 extern int exec_data_offset
;
105 /* Address in core file of start of data area data. */
107 extern int data_offset
;
109 /* Address in core file of start of stack area data. */
111 extern int stack_offset
;
113 extern struct header file_hdr
;
114 extern struct som_exec_auxhdr exec_hdr
;
116 extern int (*core_file_hook
)();
120 extern int kernel_debugging
;
121 extern int kernel_core_file_hook();
125 core_file_command (filename
, from_tty
)
130 extern char registers
[];
135 /* Discard all vestiges of any previous core file
136 and mark data and stack spaces as empty. */
149 stack_start
= STACK_END_ADDR
;
150 stack_end
= STACK_END_ADDR
;
152 /* Now, if a new core file was specified, open it and digest it. */
156 filename
= tilde_expand (filename
);
157 make_cleanup (free
, filename
);
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);
163 perror_with_name (filename
);
166 fstat(corechan
, &stb
);
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();
182 /* HP PA-RISC style corefile. */
189 unsigned int reg_offset
;
191 val
= myread (corechan
, &u
, sizeof u
);
193 perror_with_name ("Not a core file: reading upage");
195 error ("Not a core file: could only read %d bytes", val
);
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
;
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
);
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. */
218 for (regno
= 0; regno
< NUM_REGS
; regno
++)
220 unsigned char buf
[MAX_REGISTER_RAW_SIZE
];
222 val
= lseek (corechan
, register_addr (regno
, reg_offset
), 0);
224 || (val
= myread (corechan
, buf
, sizeof buf
)) < 0)
226 char * buffer
= (char *) alloca (strlen (reg_names
[regno
])
228 strcpy (buffer
, "Reading register ");
229 strcat (buffer
, reg_names
[regno
]);
231 perror_with_name (buffer
);
233 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
235 supply_register (regno
, buf
);
239 if (filename
[0] == '/')
240 corefile
= savestring (filename
, strlen (filename
));
243 corefile
= concat (current_directory
, "/", filename
);
246 set_current_frame ( create_new_frame (read_register (FP_REGNUM
),
248 select_frame (get_current_frame (), 0);
252 printf ("No core file now.\n");