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