]> Git Repo - binutils.git/blob - gdb/gdbserver/linux-i386-low.c
* linux-low.h (struct linux_target_ops): Replace left_pad_xfer field
[binutils.git] / gdb / gdbserver / linux-i386-low.c
1 /* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
2    Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
3    2007, 2008 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #include "server.h"
21 #include "linux-low.h"
22 #include "i387-fp.h"
23
24 #include "gdb_proc_service.h"
25
26 #include <sys/ptrace.h>
27
28 #ifdef HAVE_SYS_REG_H
29 #include <sys/reg.h>
30 #endif
31
32 #ifndef PTRACE_GET_THREAD_AREA
33 #define PTRACE_GET_THREAD_AREA 25
34 #endif
35
36 /* Defined in auto-generated file reg-i386-linux.c.  */
37 void init_registers_i386_linux (void);
38
39
40 /* This module only supports access to the general purpose registers.  */
41
42 #define i386_num_regs 16
43
44 /* This stuff comes from i386-linux-nat.c.  */
45
46 /* Mapping between the general-purpose registers in `struct user'
47    format and GDB's register array layout.  */
48 static int i386_regmap[] = 
49 {
50   EAX * 4, ECX * 4, EDX * 4, EBX * 4,
51   UESP * 4, EBP * 4, ESI * 4, EDI * 4,
52   EIP * 4, EFL * 4, CS * 4, SS * 4,
53   DS * 4, ES * 4, FS * 4, GS * 4
54 };
55
56 /* Called by libthread_db.  */
57
58 ps_err_e
59 ps_get_thread_area (const struct ps_prochandle *ph, 
60                     lwpid_t lwpid, int idx, void **base)
61 {
62   unsigned int desc[4];
63
64   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
65               (void *) idx, (unsigned long) &desc) < 0)
66     return PS_ERR;
67
68   *(int *)base = desc[1];
69   return PS_OK;
70 }
71
72 static int
73 i386_cannot_store_register (int regno)
74 {
75   return (regno >= i386_num_regs);
76 }
77
78 static int
79 i386_cannot_fetch_register (int regno)
80 {
81   return (regno >= i386_num_regs);
82 }
83
84
85 #ifdef HAVE_PTRACE_GETREGS
86 #include <sys/procfs.h>
87 #include <sys/ptrace.h>
88
89 static void
90 i386_fill_gregset (void *buf)
91 {
92   int i;
93
94   for (i = 0; i < i386_num_regs; i++)
95     collect_register (i, ((char *) buf) + i386_regmap[i]);
96
97   collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
98 }
99
100 static void
101 i386_store_gregset (const void *buf)
102 {
103   int i;
104
105   for (i = 0; i < i386_num_regs; i++)
106     supply_register (i, ((char *) buf) + i386_regmap[i]);
107
108   supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
109 }
110
111 static void
112 i386_fill_fpregset (void *buf)
113 {
114   i387_cache_to_fsave (buf);
115 }
116
117 static void
118 i386_store_fpregset (const void *buf)
119 {
120   i387_fsave_to_cache (buf);
121 }
122
123 static void
124 i386_fill_fpxregset (void *buf)
125 {
126   i387_cache_to_fxsave (buf);
127 }
128
129 static void
130 i386_store_fpxregset (const void *buf)
131 {
132   i387_fxsave_to_cache (buf);
133 }
134
135 #endif /* HAVE_PTRACE_GETREGS */
136
137 struct regset_info target_regsets[] = {
138 #ifdef HAVE_PTRACE_GETREGS
139   { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
140     GENERAL_REGS,
141     i386_fill_gregset, i386_store_gregset },
142 # ifdef HAVE_PTRACE_GETFPXREGS
143   { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
144     EXTENDED_REGS,
145     i386_fill_fpxregset, i386_store_fpxregset },
146 # endif
147   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
148     FP_REGS,
149     i386_fill_fpregset, i386_store_fpregset },
150 #endif /* HAVE_PTRACE_GETREGS */
151   { 0, 0, -1, -1, NULL, NULL }
152 };
153
154 static const unsigned char i386_breakpoint[] = { 0xCC };
155 #define i386_breakpoint_len 1
156
157 extern int debug_threads;
158
159 static CORE_ADDR
160 i386_get_pc ()
161 {
162   unsigned long pc;
163
164   collect_register_by_name ("eip", &pc);
165
166   if (debug_threads)
167     fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
168   return pc;
169 }
170
171 static void
172 i386_set_pc (CORE_ADDR newpc)
173 {
174   if (debug_threads)
175     fprintf (stderr, "set pc to %08lx\n", (long) newpc);
176   supply_register_by_name ("eip", &newpc);
177 }
178
179 static int
180 i386_breakpoint_at (CORE_ADDR pc)
181 {
182   unsigned char c;
183
184   read_inferior_memory (pc, &c, 1);
185   if (c == 0xCC)
186     return 1;
187
188   return 0;
189 }
190
191 struct linux_target_ops the_low_target = {
192   init_registers_i386_linux,
193   i386_num_regs,
194   i386_regmap,
195   i386_cannot_fetch_register,
196   i386_cannot_store_register,
197   i386_get_pc,
198   i386_set_pc,
199   i386_breakpoint,
200   i386_breakpoint_len,
201   NULL,
202   1,
203   i386_breakpoint_at,
204   NULL,
205   NULL,
206   NULL,
207   NULL,
208   NULL,
209   NULL,
210   "i386"
211 };
This page took 0.037176 seconds and 4 git commands to generate.