Emit 8 NULs for target section name instead of dumping core when the target
[deliverable/binutils-gdb.git] / gdb / ptx4-nat.c
1 /* Native-dependent code for ptx 4.0
2 Copyright 1988, 1989, 1991, 1992 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,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "inferior.h"
23 #include "gdbcore.h"
24 #include <sys/procfs.h>
25 #include <sys/ptrace.h>
26 #include <sys/param.h>
27 #include <fcntl.h>
28
29 /* Prototypes for supply_gregset etc. */
30 #include "gregset.h"
31
32 /* Given a pointer to a general register set in /proc format (gregset_t *),
33 unpack the register contents and supply them as gdb's idea of the current
34 register values. */
35
36 void
37 supply_gregset (gregset_t *gregsetp)
38 {
39 supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]);
40 supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]);
41 supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]);
42 supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]);
43 supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]);
44 supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]);
45 supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]);
46 supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]);
47 supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]);
48 supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]);
49 }
50
51 void
52 fill_gregset (gregset_t *gregsetp, int regno)
53 {
54 int regi;
55
56 for (regi = 0; regi < NUM_REGS; regi++)
57 {
58 if ((regno == -1) || (regno == regi))
59 {
60 (*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)];
61 }
62 }
63 }
64
65 /* Given a pointer to a floating point register set in /proc format
66 (fpregset_t *), unpack the register contents and supply them as gdb's
67 idea of the current floating point register values. */
68
69 void
70 supply_fpregset (fpregset_t *fpregsetp)
71 {
72 supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set);
73 supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs);
74 }
75
76 /* Given a pointer to a floating point register set in /proc format
77 (fpregset_t *), update the register specified by REGNO from gdb's idea
78 of the current floating point register set. If REGNO is -1, update
79 them all. */
80
81 void
82 fill_fpregset (fpregset_t *fpregsetp, int regno)
83 {
84 int regi;
85 char *to;
86 char *from;
87
88 /* FIXME: see m68k-tdep.c for an example, for the m68k. */
89 }
90
91 /*
92 * This doesn't quite do the same thing as the procfs.c version, but give
93 * it the same name so we don't have to put an ifdef in solib.c.
94 */
95 /* this could use elf_interpreter() from elfread.c */
96 int
97 proc_iterate_over_mappings (func)
98 int (*func) (int, CORE_ADDR);
99 {
100 vaddr_t curseg, memptr;
101 pt_vseg_t pv;
102 int rv, cmperr;
103 sec_ptr interp_sec;
104 char *interp_content;
105 int interp_fd, funcstat;
106 unsigned int size;
107 char buf1[NBPG], buf2[NBPG];
108
109 /*
110 * The following is really vile. We can get the name of the
111 * shared library from the exec_bfd, and we can get a list of
112 * each virtual memory segment, but there is no simple way to
113 * find the mapped segment from the shared library (ala
114 * procfs's PIOCOPENMEM). As a pretty nasty kludge, we
115 * compare the virtual memory segment to the contents of the
116 * .interp file. If they match, we assume that we've got the
117 * right one.
118 */
119
120 /*
121 * TODO: for attach, use XPT_OPENT to get the executable, in
122 * case we're attached without knowning the executable's
123 * filename.
124 */
125
126 #ifdef VERBOSE_DEBUG
127 printf ("proc_iter\n");
128 #endif
129 interp_sec = bfd_get_section_by_name (exec_bfd, ".interp");
130 if (!interp_sec)
131 {
132 return 0;
133 }
134
135 size = bfd_section_size (exec_bfd, interp_sec);
136 interp_content = alloca (size);
137 if (0 == bfd_get_section_contents (exec_bfd, interp_sec,
138 interp_content, (file_ptr) 0, size))
139 {
140 return 0;
141 }
142
143 #ifdef VERBOSE_DEBUG
144 printf ("proc_iter: \"%s\"\n", interp_content);
145 #endif
146 interp_fd = open (interp_content, O_RDONLY, 0);
147 if (-1 == interp_fd)
148 {
149 return 0;
150 }
151
152 curseg = 0;
153 while (1)
154 {
155 rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg);
156 #ifdef VERBOSE_DEBUG
157 printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno);
158 #endif
159 if (-1 == rv)
160 break;
161 if (0 == rv)
162 break;
163 #ifdef VERBOSE_DEBUG
164 printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n",
165 pv.pv_start, pv.pv_size, pv.pv_prot);
166 #endif
167 curseg = pv.pv_start + pv.pv_size;
168
169 rv = lseek (interp_fd, 0, SEEK_SET);
170 if (-1 == rv)
171 {
172 perror ("lseek");
173 close (interp_fd);
174 return 0;
175 }
176 for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size;
177 memptr += NBPG)
178 {
179 #ifdef VERBOSE_DEBUG
180 printf ("memptr 0x%x\n", memptr);
181 #endif
182 rv = read (interp_fd, buf1, NBPG);
183 if (-1 == rv)
184 {
185 perror ("read");
186 close (interp_fd);
187 return 0;
188 }
189 rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2,
190 memptr);
191 if (-1 == rv)
192 {
193 perror ("ptrace");
194 close (interp_fd);
195 return 0;
196 }
197 cmperr = memcmp (buf1, buf2, NBPG);
198 if (cmperr)
199 break;
200 }
201 if (0 == cmperr)
202 {
203 /* this is it */
204 funcstat = (*func) (interp_fd, pv.pv_start);
205 break;
206 }
207 }
208 close (interp_fd);
209 return 0;
210 }
This page took 0.034062 seconds and 4 git commands to generate.