]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbserver/linux-i386-low.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / gdbserver / linux-i386-low.c
CommitLineData
0a30fbc4 1/* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
6aba47ca
DJ
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
3 2007 Free Software Foundation, Inc.
0a30fbc4
DJ
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
6f0f660e
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
0a30fbc4
DJ
21
22#include "server.h"
58caa3dc
DJ
23#include "linux-low.h"
24#include "i387-fp.h"
0a30fbc4 25
0050a760 26#include "gdb_proc_service.h"
fd500816
DJ
27
28#include <sys/ptrace.h>
29
0a30fbc4
DJ
30#ifdef HAVE_SYS_REG_H
31#include <sys/reg.h>
32#endif
33
fd500816
DJ
34#ifndef PTRACE_GET_THREAD_AREA
35#define PTRACE_GET_THREAD_AREA 25
36#endif
37
58caa3dc 38/* This module only supports access to the general purpose registers. */
0a30fbc4 39
2ec06d2e 40#define i386_num_regs 16
0a30fbc4
DJ
41
42/* This stuff comes from i386-linux-nat.c. */
43
44/* Mapping between the general-purpose registers in `struct user'
45 format and GDB's register array layout. */
2ec06d2e 46static int i386_regmap[] =
0a30fbc4
DJ
47{
48 EAX * 4, ECX * 4, EDX * 4, EBX * 4,
49 UESP * 4, EBP * 4, ESI * 4, EDI * 4,
50 EIP * 4, EFL * 4, CS * 4, SS * 4,
51 DS * 4, ES * 4, FS * 4, GS * 4
52};
53
fd500816
DJ
54/* Called by libthread_db. */
55
56ps_err_e
57ps_get_thread_area (const struct ps_prochandle *ph,
58 lwpid_t lwpid, int idx, void **base)
59{
60 unsigned int desc[4];
61
62 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
63 (void *) idx, (unsigned long) &desc) < 0)
64 return PS_ERR;
65
66 *(int *)base = desc[1];
67 return PS_OK;
68}
69
2ec06d2e
DJ
70static int
71i386_cannot_store_register (int regno)
0a30fbc4 72{
2ec06d2e 73 return (regno >= i386_num_regs);
0a30fbc4
DJ
74}
75
2ec06d2e
DJ
76static int
77i386_cannot_fetch_register (int regno)
0a30fbc4 78{
2ec06d2e 79 return (regno >= i386_num_regs);
0a30fbc4 80}
58caa3dc
DJ
81
82
e9d25b98 83#ifdef HAVE_PTRACE_GETREGS
58caa3dc
DJ
84#include <sys/procfs.h>
85#include <sys/ptrace.h>
86
87static void
88i386_fill_gregset (void *buf)
89{
90 int i;
91
2ec06d2e
DJ
92 for (i = 0; i < i386_num_regs; i++)
93 collect_register (i, ((char *) buf) + i386_regmap[i]);
58caa3dc
DJ
94
95 collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
96}
97
98static void
0d62e5e8 99i386_store_gregset (const void *buf)
58caa3dc
DJ
100{
101 int i;
102
2ec06d2e
DJ
103 for (i = 0; i < i386_num_regs; i++)
104 supply_register (i, ((char *) buf) + i386_regmap[i]);
58caa3dc
DJ
105
106 supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
107}
108
109static void
110i386_fill_fpregset (void *buf)
111{
112 i387_cache_to_fsave (buf);
113}
114
115static void
0d62e5e8 116i386_store_fpregset (const void *buf)
58caa3dc
DJ
117{
118 i387_fsave_to_cache (buf);
119}
120
121static void
122i386_fill_fpxregset (void *buf)
123{
124 i387_cache_to_fxsave (buf);
125}
126
127static void
0d62e5e8 128i386_store_fpxregset (const void *buf)
58caa3dc
DJ
129{
130 i387_fxsave_to_cache (buf);
131}
132
e9d25b98 133#endif /* HAVE_PTRACE_GETREGS */
58caa3dc
DJ
134
135struct regset_info target_regsets[] = {
e9d25b98 136#ifdef HAVE_PTRACE_GETREGS
58caa3dc 137 { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
0d62e5e8 138 GENERAL_REGS,
58caa3dc 139 i386_fill_gregset, i386_store_gregset },
e9d25b98 140# ifdef HAVE_PTRACE_GETFPXREGS
58caa3dc 141 { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
0d62e5e8 142 EXTENDED_REGS,
58caa3dc 143 i386_fill_fpxregset, i386_store_fpxregset },
e9d25b98 144# endif
58caa3dc 145 { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
0d62e5e8 146 FP_REGS,
58caa3dc 147 i386_fill_fpregset, i386_store_fpregset },
e9d25b98 148#endif /* HAVE_PTRACE_GETREGS */
0d62e5e8 149 { 0, 0, -1, -1, NULL, NULL }
58caa3dc
DJ
150};
151
f450004a 152static const unsigned char i386_breakpoint[] = { 0xCC };
611cb4a5
DJ
153#define i386_breakpoint_len 1
154
0d62e5e8
DJ
155extern int debug_threads;
156
611cb4a5 157static CORE_ADDR
0d62e5e8 158i386_get_pc ()
611cb4a5
DJ
159{
160 unsigned long pc;
161
611cb4a5 162 collect_register_by_name ("eip", &pc);
0d62e5e8
DJ
163
164 if (debug_threads)
165 fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
166 return pc;
611cb4a5
DJ
167}
168
169static void
170i386_set_pc (CORE_ADDR newpc)
171{
0d62e5e8
DJ
172 if (debug_threads)
173 fprintf (stderr, "set pc to %08lx\n", (long) newpc);
611cb4a5 174 supply_register_by_name ("eip", &newpc);
0d62e5e8
DJ
175}
176
177static int
178i386_breakpoint_at (CORE_ADDR pc)
179{
180 unsigned char c;
181
182 read_inferior_memory (pc, &c, 1);
183 if (c == 0xCC)
184 return 1;
611cb4a5 185
0d62e5e8 186 return 0;
611cb4a5
DJ
187}
188
2ec06d2e
DJ
189struct linux_target_ops the_low_target = {
190 i386_num_regs,
191 i386_regmap,
192 i386_cannot_fetch_register,
193 i386_cannot_store_register,
0d62e5e8 194 i386_get_pc,
611cb4a5
DJ
195 i386_set_pc,
196 i386_breakpoint,
197 i386_breakpoint_len,
0d62e5e8
DJ
198 NULL,
199 1,
200 i386_breakpoint_at,
2ec06d2e 201};