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