1 /* Native-dependent code for Linux running on i386's, for GDB.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* For i386_linux_skip_solib_resolver */
29 #include <sys/ptrace.h>
31 #include <sys/procfs.h>
37 /* This is a duplicate of the table in i386-xdep.c. */
48 /* Given a pointer to a general register set in struct user format
49 (gregset_t *), unpack the register contents and supply them as
50 gdb's idea of the current register values. */
52 supply_gregset (gregsetp
)
56 register greg_t
*regp
= (greg_t
*) gregsetp
;
58 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
60 supply_register (regi
, (char *) (regp
+ regmap
[regi
]));
64 /* Fill in a gregset_t object with selected data from a gdb-format
66 - GREGSETP points to the gregset_t object to be filled.
67 - GDB_REGS points to the GDB-style register file providing the data.
68 - VALID is an array indicating which registers in GDB_REGS are
69 valid; the parts of *GREGSETP that would hold registers marked
70 invalid in GDB_REGS are left unchanged. If VALID is zero, all
71 registers are assumed to be valid. */
73 convert_to_gregset (gregset_t
*gregsetp
,
78 register greg_t
*regp
= (greg_t
*) gregsetp
;
80 for (regi
= 0; regi
< NUM_GREGS
; regi
++)
81 if (! valid
|| valid
[regi
])
82 *(regp
+ regmap
[regi
]) = * (int *) ®isters
[REGISTER_BYTE (regi
)];
86 fill_gregset (gregset_t
*gregsetp
,
90 convert_to_gregset (gregsetp
, registers
, 0);
93 signed char valid
[NUM_GREGS
];
94 memset (valid
, 0, sizeof (valid
));
96 convert_to_gregset (gregsetp
, valid
, valid
);
101 /* Where does st(N) start in the fpregset_t structure F? */
102 #define FPREGSET_T_FPREG_OFFSET(f, n) \
103 ((char *) &(f)->st_space + (n) * 10)
105 /* Fill GDB's register file with the floating-point register values in
108 supply_fpregset (fpregset_t
*fpregsetp
)
112 /* Supply the floating-point registers. */
113 for (i
= 0; i
< 8; i
++)
114 supply_register (FP0_REGNUM
+ i
, FPREGSET_T_FPREG_OFFSET (fpregsetp
, i
));
116 supply_register (FCTRL_REGNUM
, (char *) &fpregsetp
->cwd
);
117 supply_register (FSTAT_REGNUM
, (char *) &fpregsetp
->swd
);
118 supply_register (FTAG_REGNUM
, (char *) &fpregsetp
->twd
);
119 supply_register (FCOFF_REGNUM
, (char *) &fpregsetp
->fip
);
120 supply_register (FDS_REGNUM
, (char *) &fpregsetp
->fos
);
121 supply_register (FDOFF_REGNUM
, (char *) &fpregsetp
->foo
);
123 /* Extract the code segment and opcode from the "fcs" member. */
127 l
= fpregsetp
->fcs
& 0xffff;
128 supply_register (FCS_REGNUM
, (char *) &l
);
130 l
= (fpregsetp
->fcs
>> 16) & ((1 << 11) - 1);
131 supply_register (FOP_REGNUM
, (char *) &l
);
136 /* Fill in an fpregset_t structure with selected data from a
137 gdb-format register file.
138 - FPREGSETP points to the structure to be filled.
139 - GDB_REGS points to the GDB-style register file providing the data.
140 - VALID is an array indicating which registers in GDB_REGS are
141 valid; the parts of *FPREGSETP that would hold registers marked
142 invalid in GDB_REGS are left unchanged. If VALID is zero, all
143 registers are assumed to be valid. */
145 convert_to_fpregset (fpregset_t
*fpregsetp
,
151 /* Fill in the floating-point registers. */
152 for (i
= 0; i
< 8; i
++)
153 if (!valid
|| valid
[i
])
154 memcpy (FPREGSET_T_FPREG_OFFSET (fpregsetp
, i
),
155 ®isters
[REGISTER_BYTE (FP0_REGNUM
+ i
)],
156 REGISTER_RAW_SIZE(FP0_REGNUM
+ i
));
158 #define fill(MEMBER, REGNO) \
159 if (! valid || valid[(REGNO)]) \
160 memcpy (&fpregsetp->MEMBER, ®isters[REGISTER_BYTE (REGNO)], \
161 sizeof (fpregsetp->MEMBER))
163 fill (cwd
, FCTRL_REGNUM
);
164 fill (swd
, FSTAT_REGNUM
);
165 fill (twd
, FTAG_REGNUM
);
166 fill (fip
, FCOFF_REGNUM
);
167 fill (foo
, FDOFF_REGNUM
);
168 fill (fos
, FDS_REGNUM
);
172 if (! valid
|| valid
[FCS_REGNUM
])
174 = ((fpregsetp
->fcs
& ~0xffff)
175 | (* (int *) ®isters
[REGISTER_BYTE (FCS_REGNUM
)] & 0xffff));
177 if (! valid
|| valid
[FOP_REGNUM
])
179 = ((fpregsetp
->fcs
& 0xffff)
180 | ((*(int *) ®isters
[REGISTER_BYTE (FOP_REGNUM
)] & ((1 << 11) - 1))
185 /* Given a pointer to a floating point register set in (fpregset_t *)
186 format, update all of the registers from gdb's idea of the current
187 floating point register set. */
190 fill_fpregset (fpregset_t
*fpregsetp
,
193 convert_to_fpregset (fpregsetp
, registers
, 0);
197 /* Get the whole floating point state of the process and store the
198 floating point stack into registers[]. */
205 ret
= ptrace (PTRACE_GETFPREGS
, inferior_pid
, 0, (int) &buf
);
208 warning ("Couldn't get floating point status");
212 /* ptrace fills an fpregset_t, so we can use the same function we do
214 supply_fpregset (&buf
);
218 /* Set the inferior's floating-point registers to the values in
219 registers[] --- but only those registers marked valid. */
226 ret
= ptrace (PTRACE_GETFPREGS
, inferior_pid
, 0, (int) &buf
);
229 warning ("Couldn't get floating point status");
233 convert_to_fpregset (&buf
, registers
, register_valid
);
235 ret
= ptrace (PTRACE_SETFPREGS
, inferior_pid
, 0, (int) &buf
);
238 warning ("Couldn't write floating point status");
244 /* Read the general registers from the process, and store them
252 ret
= ptrace (PTRACE_GETREGS
, inferior_pid
, 0, (int) &buf
);
255 warning ("Couldn't get registers");
259 supply_gregset (&buf
);
263 /* Set the inferior's general registers to the values in registers[]
264 --- but only those registers marked as valid. */
271 ret
= ptrace (PTRACE_GETREGS
, inferior_pid
, 0, (int) &buf
);
274 warning ("Couldn't get registers");
278 convert_to_gregset (&buf
, registers
, register_valid
);
280 ret
= ptrace (PTRACE_SETREGS
, inferior_pid
, 0, (int)buf
);
283 warning ("Couldn't write registers");
289 /* Fetch registers from the child process.
290 Fetch all if regno == -1, otherwise fetch all ordinary
291 registers or all floating point registers depending
292 upon the value of regno. */
295 fetch_inferior_registers (int regno
)
297 if (regno
< NUM_GREGS
|| regno
== -1)
300 if (regno
>= NUM_GREGS
|| regno
== -1)
305 /* Store our register values back into the inferior.
306 If REGNO is -1, do this for all registers.
307 Otherwise, REGNO specifies which register, which
308 then determines whether we store all ordinary
309 registers or all of the floating point registers. */
312 store_inferior_registers (regno
)
315 if (regno
< NUM_GREGS
|| regno
== -1)
318 if (regno
>= NUM_GREGS
|| regno
== -1)
323 /* Find the minimal symbol named NAME, and return both the minsym
324 struct and its objfile. This probably ought to be in minsym.c, but
325 everything there is trying to deal with things like C++ and
326 SOFUN_ADDRESS_MAYBE_TURQUOISE, ... Since this is so simple, it may
327 be considered too special-purpose for general consumption. */
329 static struct minimal_symbol
*
330 find_minsym_and_objfile (char *name
, struct objfile
**objfile_p
)
332 struct objfile
*objfile
;
334 ALL_OBJFILES (objfile
)
336 struct minimal_symbol
*msym
;
338 ALL_OBJFILE_MSYMBOLS (objfile
, msym
)
340 if (SYMBOL_NAME (msym
)
341 && STREQ (SYMBOL_NAME (msym
), name
))
343 *objfile_p
= objfile
;
354 skip_hurd_resolver (CORE_ADDR pc
)
356 /* The HURD dynamic linker is part of the GNU C library, so many
357 GNU/Linux distributions use it. (All ELF versions, as far as I
358 know.) An unresolved PLT entry points to "_dl_runtime_resolve",
359 which calls "fixup" to patch the PLT, and then passes control to
362 We look for the symbol `_dl_runtime_resolve', and find `fixup' in
363 the same objfile. If we are at the entry point of `fixup', then
364 we set a breakpoint at the return address (at the top of the
365 stack), and continue.
367 It's kind of gross to do all these checks every time we're
368 called, since they don't change once the executable has gotten
369 started. But this is only a temporary hack --- upcoming versions
370 of Linux will provide a portable, efficient interface for
371 debugging programs that use shared libraries. */
373 struct objfile
*objfile
;
374 struct minimal_symbol
*resolver
375 = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile
);
379 struct minimal_symbol
*fixup
380 = lookup_minimal_symbol ("fixup", 0, objfile
);
382 if (fixup
&& SYMBOL_VALUE_ADDRESS (fixup
) == pc
)
383 return (SAVED_PC_AFTER_CALL (get_current_frame ()));
390 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
392 1) decides whether a PLT has sent us into the linker to resolve
393 a function reference, and
394 2) if so, tells us where to set a temporary breakpoint that will
395 trigger when the dynamic linker is done. */
398 i386_linux_skip_solib_resolver (CORE_ADDR pc
)
402 /* Plug in functions for other kinds of resolvers here. */
403 result
= skip_hurd_resolver (pc
);
This page took 0.041259 seconds and 4 git commands to generate.