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.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "linux-low.h"
24 #include "gdb_proc_service.h"
26 #include <sys/ptrace.h>
32 #ifndef PTRACE_GET_THREAD_AREA
33 #define PTRACE_GET_THREAD_AREA 25
36 /* This module only supports access to the general purpose registers. */
38 #define i386_num_regs 16
40 /* This stuff comes from i386-linux-nat.c. */
42 /* Mapping between the general-purpose registers in `struct user'
43 format and GDB's register array layout. */
44 static int i386_regmap
[] =
46 EAX
* 4, ECX
* 4, EDX
* 4, EBX
* 4,
47 UESP
* 4, EBP
* 4, ESI
* 4, EDI
* 4,
48 EIP
* 4, EFL
* 4, CS
* 4, SS
* 4,
49 DS
* 4, ES
* 4, FS
* 4, GS
* 4
52 /* Called by libthread_db. */
55 ps_get_thread_area (const struct ps_prochandle
*ph
,
56 lwpid_t lwpid
, int idx
, void **base
)
60 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
,
61 (void *) idx
, (unsigned long) &desc
) < 0)
64 *(int *)base
= desc
[1];
69 i386_cannot_store_register (int regno
)
71 return (regno
>= i386_num_regs
);
75 i386_cannot_fetch_register (int regno
)
77 return (regno
>= i386_num_regs
);
81 #ifdef HAVE_PTRACE_GETREGS
82 #include <sys/procfs.h>
83 #include <sys/ptrace.h>
86 i386_fill_gregset (void *buf
)
90 for (i
= 0; i
< i386_num_regs
; i
++)
91 collect_register (i
, ((char *) buf
) + i386_regmap
[i
]);
93 collect_register_by_name ("orig_eax", ((char *) buf
) + ORIG_EAX
* 4);
97 i386_store_gregset (const void *buf
)
101 for (i
= 0; i
< i386_num_regs
; i
++)
102 supply_register (i
, ((char *) buf
) + i386_regmap
[i
]);
104 supply_register_by_name ("orig_eax", ((char *) buf
) + ORIG_EAX
* 4);
108 i386_fill_fpregset (void *buf
)
110 i387_cache_to_fsave (buf
);
114 i386_store_fpregset (const void *buf
)
116 i387_fsave_to_cache (buf
);
120 i386_fill_fpxregset (void *buf
)
122 i387_cache_to_fxsave (buf
);
126 i386_store_fpxregset (const void *buf
)
128 i387_fxsave_to_cache (buf
);
131 #endif /* HAVE_PTRACE_GETREGS */
133 struct regset_info target_regsets
[] = {
134 #ifdef HAVE_PTRACE_GETREGS
135 { PTRACE_GETREGS
, PTRACE_SETREGS
, sizeof (elf_gregset_t
),
137 i386_fill_gregset
, i386_store_gregset
},
138 # ifdef HAVE_PTRACE_GETFPXREGS
139 { PTRACE_GETFPXREGS
, PTRACE_SETFPXREGS
, sizeof (elf_fpxregset_t
),
141 i386_fill_fpxregset
, i386_store_fpxregset
},
143 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, sizeof (elf_fpregset_t
),
145 i386_fill_fpregset
, i386_store_fpregset
},
146 #endif /* HAVE_PTRACE_GETREGS */
147 { 0, 0, -1, -1, NULL
, NULL
}
150 static const unsigned char i386_breakpoint
[] = { 0xCC };
151 #define i386_breakpoint_len 1
153 extern int debug_threads
;
160 collect_register_by_name ("eip", &pc
);
163 fprintf (stderr
, "stop pc (before any decrement) is %08lx\n", pc
);
168 i386_set_pc (CORE_ADDR newpc
)
171 fprintf (stderr
, "set pc to %08lx\n", (long) newpc
);
172 supply_register_by_name ("eip", &newpc
);
176 i386_breakpoint_at (CORE_ADDR pc
)
180 read_inferior_memory (pc
, &c
, 1);
187 struct linux_target_ops the_low_target
= {
190 i386_cannot_fetch_register
,
191 i386_cannot_store_register
,