import gdb-19990422 snapshot
[deliverable/binutils-gdb.git] / gdb / umax-xdep.c
1 /* umax host stuff.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23
24 #include <sys/param.h>
25 #include <sys/dir.h>
26 #include <signal.h>
27 #include <sys/ioctl.h>
28 #include <fcntl.h>
29
30 #include "gdbcore.h"
31 #include <sys/ptrace.h>
32 #define PTRACE_ATTACH PT_ATTACH
33 #define PTRACE_DETACH PT_FREEPROC
34
35 #include <sys/file.h>
36 #include "gdb_stat.h"
37
38 /* Work with core dump and executable files, for GDB.
39 This code would be in corefile.c if it weren't machine-dependent. */
40
41 void
42 core_file_command (filename, from_tty)
43 char *filename;
44 int from_tty;
45 {
46 int val;
47
48 /* Discard all vestiges of any previous core file
49 and mark data and stack spaces as empty. */
50
51 if (corefile)
52 free (corefile);
53 corefile = 0;
54
55 if (corechan >= 0)
56 close (corechan);
57 corechan = -1;
58
59 data_start = 0;
60 data_end = 0;
61 stack_start = STACK_END_ADDR;
62 stack_end = STACK_END_ADDR;
63
64 /* Now, if a new core file was specified, open it and digest it. */
65
66 if (filename)
67 {
68 filename = tilde_expand (filename);
69 make_cleanup (free, filename);
70
71 if (have_inferior_p ())
72 error ("To look at a core file, you must kill the program with \"kill\".");
73 corechan = open (filename, O_RDONLY, 0);
74 if (corechan < 0)
75 perror_with_name (filename);
76 /* 4.2-style (and perhaps also sysV-style) core dump file. */
77 {
78 struct ptrace_user u;
79 int reg_offset;
80
81 val = myread (corechan, &u, sizeof u);
82 if (val < 0)
83 perror_with_name (filename);
84 data_start = exec_data_start;
85
86 data_end = data_start + u.pt_dsize;
87 stack_start = stack_end - u.pt_ssize;
88 data_offset = sizeof u;
89 stack_offset = data_offset + u.pt_dsize;
90 reg_offset = 0;
91
92 memcpy (&core_aouthdr, &u.pt_aouthdr, sizeof (AOUTHDR));
93 printf_unfiltered ("Core file is from \"%s\".\n", u.pt_comm);
94 if (u.pt_signal > 0)
95 printf_unfiltered ("Program terminated with signal %d, %s.\n",
96 u.pt_signal, safe_strsignal (u.pt_signal));
97
98 /* Read the register values out of the core file and store
99 them where `read_register' will find them. */
100
101 {
102 register int regno;
103
104 for (regno = 0; regno < NUM_REGS; regno++)
105 {
106 char buf[MAX_REGISTER_RAW_SIZE];
107
108 val = lseek (corechan, register_addr (regno, reg_offset), 0);
109 if (val < 0)
110 perror_with_name (filename);
111
112 val = myread (corechan, buf, sizeof buf);
113 if (val < 0)
114 perror_with_name (filename);
115 supply_register (regno, buf);
116 }
117 }
118 }
119 if (filename[0] == '/')
120 corefile = savestring (filename, strlen (filename));
121 else
122 {
123 corefile = concat (current_directory, "/", filename, NULL);
124 }
125
126 flush_cached_frames ();
127 select_frame (get_current_frame (), 0);
128 validate_files ();
129 }
130 else if (from_tty)
131 printf_unfiltered ("No core file now.\n");
132 }
This page took 0.062131 seconds and 4 git commands to generate.