Commit | Line | Data |
---|---|---|
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 | ||
c60c0f5f MS |
29 | /* Prototypes for supply_gregset etc. */ |
30 | #include "gregset.h" | |
31 | ||
c906108c | 32 | /* Given a pointer to a general register set in /proc format (gregset_t *), |
c5aa993b JM |
33 | unpack the register contents and supply them as gdb's idea of the current |
34 | register values. */ | |
c906108c SS |
35 | |
36 | void | |
37 | supply_gregset (gregsetp) | |
38 | gregset_t *gregsetp; | |
39 | { | |
c5aa993b JM |
40 | supply_register (EAX_REGNUM, (char *) &(*gregsetp)[EAX]); |
41 | supply_register (EDX_REGNUM, (char *) &(*gregsetp)[EDX]); | |
42 | supply_register (ECX_REGNUM, (char *) &(*gregsetp)[ECX]); | |
43 | supply_register (EBX_REGNUM, (char *) &(*gregsetp)[EBX]); | |
44 | supply_register (ESI_REGNUM, (char *) &(*gregsetp)[ESI]); | |
45 | supply_register (EDI_REGNUM, (char *) &(*gregsetp)[EDI]); | |
46 | supply_register (ESP_REGNUM, (char *) &(*gregsetp)[UESP]); | |
47 | supply_register (EBP_REGNUM, (char *) &(*gregsetp)[EBP]); | |
48 | supply_register (EIP_REGNUM, (char *) &(*gregsetp)[EIP]); | |
49 | supply_register (EFLAGS_REGNUM, (char *) &(*gregsetp)[EFL]); | |
c906108c SS |
50 | } |
51 | ||
52 | void | |
53 | fill_gregset (gregsetp, regno) | |
54 | gregset_t *gregsetp; | |
55 | int regno; | |
56 | { | |
57 | int regi; | |
c906108c | 58 | |
c5aa993b | 59 | for (regi = 0; regi < NUM_REGS; regi++) |
c906108c SS |
60 | { |
61 | if ((regno == -1) || (regno == regi)) | |
62 | { | |
c5aa993b | 63 | (*gregsetp)[regi] = *(greg_t *) & registers[REGISTER_BYTE (regi)]; |
c906108c SS |
64 | } |
65 | } | |
66 | } | |
67 | ||
c906108c | 68 | /* Given a pointer to a floating point register set in /proc format |
c5aa993b JM |
69 | (fpregset_t *), unpack the register contents and supply them as gdb's |
70 | idea of the current floating point register values. */ | |
c906108c | 71 | |
c5aa993b | 72 | void |
c906108c SS |
73 | supply_fpregset (fpregsetp) |
74 | fpregset_t *fpregsetp; | |
75 | { | |
c5aa993b JM |
76 | supply_fpu_registers ((struct fpusave *) &fpregsetp->fp_reg_set); |
77 | supply_fpa_registers ((struct fpasave *) &fpregsetp->f_wregs); | |
c906108c SS |
78 | } |
79 | ||
80 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
81 | (fpregset_t *), update the register specified by REGNO from gdb's idea |
82 | of the current floating point register set. If REGNO is -1, update | |
83 | them all. */ | |
c906108c SS |
84 | |
85 | void | |
86 | fill_fpregset (fpregsetp, regno) | |
87 | fpregset_t *fpregsetp; | |
88 | int regno; | |
89 | { | |
90 | int regi; | |
91 | char *to; | |
92 | char *from; | |
c906108c SS |
93 | |
94 | /* FIXME: see m68k-tdep.c for an example, for the m68k. */ | |
95 | } | |
96 | ||
c906108c SS |
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 */ | |
102 | int | |
c5aa993b JM |
103 | proc_iterate_over_mappings (func) |
104 | int (*func) PARAMS ((int, CORE_ADDR)); | |
c906108c | 105 | { |
c5aa993b JM |
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 | */ | |
c906108c SS |
131 | |
132 | #ifdef VERBOSE_DEBUG | |
c5aa993b | 133 | printf ("proc_iter\n"); |
c906108c | 134 | #endif |
c5aa993b JM |
135 | interp_sec = bfd_get_section_by_name (exec_bfd, ".interp"); |
136 | if (!interp_sec) | |
137 | { | |
138 | return 0; | |
139 | } | |
c906108c | 140 | |
c5aa993b JM |
141 | size = bfd_section_size (exec_bfd, interp_sec); |
142 | interp_content = alloca (size); | |
143 | if (0 == bfd_get_section_contents (exec_bfd, interp_sec, | |
144 | interp_content, (file_ptr) 0, size)) | |
145 | { | |
146 | return 0; | |
147 | } | |
c906108c SS |
148 | |
149 | #ifdef VERBOSE_DEBUG | |
c5aa993b | 150 | printf ("proc_iter: \"%s\"\n", interp_content); |
c906108c | 151 | #endif |
c5aa993b JM |
152 | interp_fd = open (interp_content, O_RDONLY, 0); |
153 | if (-1 == interp_fd) | |
154 | { | |
155 | return 0; | |
156 | } | |
c906108c | 157 | |
c5aa993b JM |
158 | curseg = 0; |
159 | while (1) | |
160 | { | |
161 | rv = ptrace (PT_NEXT_VSEG, inferior_pid, &pv, curseg); | |
c906108c | 162 | #ifdef VERBOSE_DEBUG |
c5aa993b | 163 | printf ("PT_NEXT_VSEG: rv %d errno %d\n", rv, errno); |
c906108c | 164 | #endif |
c5aa993b JM |
165 | if (-1 == rv) |
166 | break; | |
167 | if (0 == rv) | |
168 | break; | |
c906108c | 169 | #ifdef VERBOSE_DEBUG |
c5aa993b JM |
170 | printf ("pv.pv_start 0x%x pv_size 0x%x pv_prot 0x%x\n", |
171 | pv.pv_start, pv.pv_size, pv.pv_prot); | |
c906108c | 172 | #endif |
c5aa993b JM |
173 | curseg = pv.pv_start + pv.pv_size; |
174 | ||
175 | rv = lseek (interp_fd, 0, SEEK_SET); | |
176 | if (-1 == rv) | |
177 | { | |
178 | perror ("lseek"); | |
179 | close (interp_fd); | |
180 | return 0; | |
181 | } | |
182 | for (memptr = pv.pv_start; memptr < pv.pv_start + pv.pv_size; | |
183 | memptr += NBPG) | |
184 | { | |
c906108c | 185 | #ifdef VERBOSE_DEBUG |
c5aa993b | 186 | printf ("memptr 0x%x\n", memptr); |
c906108c | 187 | #endif |
c5aa993b JM |
188 | rv = read (interp_fd, buf1, NBPG); |
189 | if (-1 == rv) | |
190 | { | |
191 | perror ("read"); | |
192 | close (interp_fd); | |
193 | return 0; | |
194 | } | |
195 | rv = ptrace (PT_RDATA_PAGE, inferior_pid, buf2, | |
196 | memptr); | |
197 | if (-1 == rv) | |
198 | { | |
199 | perror ("ptrace"); | |
200 | close (interp_fd); | |
201 | return 0; | |
202 | } | |
203 | cmperr = memcmp (buf1, buf2, NBPG); | |
204 | if (cmperr) | |
205 | break; | |
206 | } | |
207 | if (0 == cmperr) | |
208 | { | |
209 | /* this is it */ | |
210 | funcstat = (*func) (interp_fd, pv.pv_start); | |
211 | break; | |
c906108c | 212 | } |
c5aa993b JM |
213 | } |
214 | close (interp_fd); | |
215 | return 0; | |
c906108c | 216 | } |