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