1 /* IBM RS/6000 host-dependent code for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include <sys/param.h>
31 #include <sys/ioctl.h>
34 #include <sys/ptrace.h>
42 #include <sys/utsname.h>
45 extern int attach_flag
;
47 /* Conversion from gdb-to-system special purpose register numbers.. */
49 static int special_regs
[] = {
60 /* Nonzero if we just simulated a single step break. */
61 extern int one_stepped
;
65 fetch_inferior_registers (regno
)
69 extern char registers
[];
71 /* read 32 general purpose registers. */
73 for (ii
=0; ii
< 32; ++ii
)
74 *(int*)®isters
[REGISTER_BYTE (ii
)] =
75 ptrace (PT_READ_GPR
, inferior_pid
, ii
, 0, 0);
77 /* read general purpose floating point registers. */
79 for (ii
=0; ii
< 32; ++ii
)
80 ptrace (PT_READ_FPR
, inferior_pid
,
81 (int*)®isters
[REGISTER_BYTE (FP0_REGNUM
+ii
)], FPR0
+ii
, 0);
83 /* read special registers. */
84 for (ii
=0; ii
<= LAST_SP_REGNUM
-FIRST_SP_REGNUM
; ++ii
)
85 *(int*)®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
+ii
)] =
86 ptrace (PT_READ_GPR
, inferior_pid
, special_regs
[ii
], 0, 0);
89 /* Store our register values back into the inferior.
90 If REGNO is -1, do this for all registers.
91 Otherwise, REGNO specifies which register (so we can save time). */
94 store_inferior_registers (regno
)
97 extern char registers
[];
101 if (regno
== -1) { /* for all registers.. */
104 /* execute one dummy instruction (which is a breakpoint) in inferior
105 process. So give kernel a chance to do internal house keeping.
106 Otherwise the following ptrace(2) calls will mess up user stack
107 since kernel will get confused about the bottom of the stack (%sp) */
109 exec_one_dummy_insn ();
111 /* write general purpose registers first! */
112 for ( ii
=GPR0
; ii
<=GPR31
; ++ii
) {
113 ptrace (PT_WRITE_GPR
, inferior_pid
, ii
,
114 *(int*)®isters
[REGISTER_BYTE (ii
)], 0);
116 perror ("ptrace write_gpr"); errno
= 0;
120 /* write floating point registers now. */
121 for ( ii
=0; ii
< 32; ++ii
) {
122 ptrace (PT_WRITE_FPR
, inferior_pid
,
123 (int*)®isters
[REGISTER_BYTE (FP0_REGNUM
+ii
)], FPR0
+ii
, 0);
125 perror ("ptrace write_fpr"); errno
= 0;
129 /* write special registers. */
130 for (ii
=0; ii
<= LAST_SP_REGNUM
-FIRST_SP_REGNUM
; ++ii
) {
131 ptrace (PT_WRITE_GPR
, inferior_pid
, special_regs
[ii
],
132 *(int*)®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
+ii
)], 0);
134 perror ("ptrace write_gpr"); errno
= 0;
139 /* else, a specific register number is given... */
141 else if (regno
< FP0_REGNUM
) { /* a GPR */
143 ptrace (PT_WRITE_GPR
, inferior_pid
, regno
,
144 *(int*)®isters
[REGISTER_BYTE (regno
)], 0);
147 else if (regno
<= FPLAST_REGNUM
) { /* a FPR */
148 ptrace (PT_WRITE_FPR
, inferior_pid
,
149 (int*)®isters
[REGISTER_BYTE (regno
)], regno
-FP0_REGNUM
+FPR0
, 0);
152 else if (regno
<= LAST_SP_REGNUM
) { /* a special register */
154 ptrace (PT_WRITE_GPR
, inferior_pid
, special_regs
[regno
-FIRST_SP_REGNUM
],
155 *(int*)®isters
[REGISTER_BYTE (regno
)], 0);
159 fprintf (stderr
, "Gdb error: register no %d not implemented.\n", regno
);
162 perror ("ptrace write"); errno
= 0;
167 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
169 unsigned core_reg_size
;
171 unsigned int reg_addr
; /* Unused in this version */
173 /* fetch GPRs and special registers from the first register section
177 /* copy GPRs first. */
178 bcopy (core_reg_sect
, registers
, 32 * 4);
180 /* gdb's internal register template and bfd's register section layout
181 should share a common include file. FIXMEmgo */
182 /* then comes special registes. They are supposed to be in the same
183 order in gdb template and bfd `.reg' section. */
184 core_reg_sect
+= (32 * 4);
185 bcopy (core_reg_sect
, ®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
)],
186 (LAST_SP_REGNUM
- FIRST_SP_REGNUM
+ 1) * 4);
189 /* fetch floating point registers from register section 2 in core bfd. */
191 bcopy (core_reg_sect
, ®isters
[REGISTER_BYTE (FP0_REGNUM
)], 32 * 8);
194 fprintf (stderr
, "Gdb error: unknown parameter to fetch_core_registers().\n");
198 frameless_function_invocation (fi
)
199 struct frame_info
*fi
;
201 CORE_ADDR func_start
;
202 int frameless
, dummy
;
204 func_start
= get_pc_function_start (fi
->pc
) + FUNCTION_START_OFFSET
;
206 /* If we failed to find the start of the function, it is a mistake
207 to inspect the instructions. */
212 function_frame_info (func_start
, &frameless
, &dummy
, &dummy
, &dummy
);
217 /* aixcoff_relocate_symtab - hook for symbol table relocation.
218 also reads shared libraries.. */
220 aixcoff_relocate_symtab (pid
)
223 #define MAX_LOAD_SEGS 64 /* maximum number of load segments */
228 ldi
= (void *) alloca(MAX_LOAD_SEGS
* sizeof (*ldi
));
230 /* According to my humble theory, aixcoff has some timing problems and
231 when the user stack grows, kernel doesn't update stack info in time
232 and ptrace calls step on user stack. That is why we sleep here a little,
233 and give kernel to update its internals. */
238 ptrace(PT_LDINFO
, pid
, ldi
, MAX_LOAD_SEGS
* sizeof(*ldi
), ldi
);
240 perror_with_name ("ptrace ldinfo");
247 add_text_to_loadinfo (ldi
->ldinfo_textorg
, ldi
->ldinfo_dataorg
);
248 } while (ldi
->ldinfo_next
249 && (ldi
= (void *) (ldi
->ldinfo_next
+ (char *) ldi
)));
252 /* Now that we've jumbled things around, re-sort them. */
253 sort_minimal_symbols ();
256 /* relocate the exec and core sections as well. */
261 /* Keep an array of load segment information and their TOC table addresses.
262 This info will be useful when calling a shared library function by hand. */
265 unsigned long textorg
, dataorg
, toc_offset
;
268 #define LOADINFOLEN 10
270 static LoadInfo
*loadInfo
= NULL
;
271 static int loadInfoLen
= 0;
272 static int loadInfoTocIndex
= 0;
273 int aix_loadInfoTextIndex
= 0;
276 xcoff_init_loadinfo ()
278 loadInfoTocIndex
= 0;
279 aix_loadInfoTextIndex
= 0;
281 if (loadInfoLen
== 0) {
282 loadInfo
= (void*) xmalloc (sizeof (LoadInfo
) * LOADINFOLEN
);
283 loadInfoLen
= LOADINFOLEN
;
294 loadInfoTocIndex
= 0;
295 aix_loadInfoTextIndex
= 0;
299 xcoff_add_toc_to_loadinfo (unsigned long tocaddr
)
301 while (loadInfoTocIndex
>= loadInfoLen
) {
302 loadInfoLen
+= LOADINFOLEN
;
303 loadInfo
= (void*) xrealloc (loadInfo
, sizeof(LoadInfo
) * loadInfoLen
);
305 loadInfo
[loadInfoTocIndex
++].toc_offset
= tocaddr
;
309 add_text_to_loadinfo (unsigned long textaddr
, unsigned long dataaddr
)
311 while (aix_loadInfoTextIndex
>= loadInfoLen
) {
312 loadInfoLen
+= LOADINFOLEN
;
313 loadInfo
= (void*) xrealloc (loadInfo
, sizeof(LoadInfo
) * loadInfoLen
);
315 loadInfo
[aix_loadInfoTextIndex
].textorg
= textaddr
;
316 loadInfo
[aix_loadInfoTextIndex
].dataorg
= dataaddr
;
317 ++aix_loadInfoTextIndex
;
322 find_toc_address (unsigned long pc
)
324 int ii
, toc_entry
, tocbase
= 0;
326 for (ii
=0; ii
< aix_loadInfoTextIndex
; ++ii
)
327 if (pc
> loadInfo
[ii
].textorg
&& loadInfo
[ii
].textorg
> tocbase
) {
329 tocbase
= loadInfo
[ii
].textorg
;
332 return loadInfo
[toc_entry
].dataorg
+ loadInfo
[toc_entry
].toc_offset
;
336 /* execute one dummy breakpoint instruction. This way we give kernel
337 a chance to do some housekeeping and update inferior's internal data,
340 exec_one_dummy_insn ()
342 #define DUMMY_INSN_ADDR (TEXT_SEGMENT_BASE)+0x200
344 unsigned long shadow
;
345 unsigned int status
, pid
;
347 /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address. We assume that
348 this address will never be executed again by the real code. */
350 target_insert_breakpoint (DUMMY_INSN_ADDR
, &shadow
);
353 ptrace (PT_CONTINUE
, inferior_pid
, DUMMY_INSN_ADDR
, 0, 0);
355 perror ("pt_continue");
358 pid
= wait (&status
);
359 } while (pid
!= inferior_pid
);
361 target_remove_breakpoint (DUMMY_INSN_ADDR
, &shadow
);
365 /* Return the number of initial trap signals we need to ignore once the inferior
366 process starts running. This will be `2' for aix-3.1, `3' for aix-3.2 */
369 aix_starting_inferior_traps ()
371 struct utsname unamebuf
;
373 if (uname (&unamebuf
) == -1)
374 fatal ("uname(3) failed.");
376 /* Assume the future versions will behave like 3.2 and return '3' for
377 anything other than 3.1x. The extra trap in 3.2 is the "trap after the
378 program is loaded" signal. */
380 if (unamebuf
.version
[0] == '3' && unamebuf
.release
[0] == '1')
This page took 0.037445 seconds and 5 git commands to generate.