1 /* GNU/Linux/x86-64 specific low level interface, for the remote server
3 Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "linux-low.h"
27 #include "i386-xstate.h"
28 #include "elf/common.h"
30 #include "gdb_proc_service.h"
32 /* Defined in auto-generated file i386-linux.c. */
33 void init_registers_i386_linux (void);
34 /* Defined in auto-generated file amd64-linux.c. */
35 void init_registers_amd64_linux (void);
36 /* Defined in auto-generated file i386-avx-linux.c. */
37 void init_registers_i386_avx_linux (void);
38 /* Defined in auto-generated file amd64-avx-linux.c. */
39 void init_registers_amd64_avx_linux (void);
40 /* Defined in auto-generated file i386-mmx-linux.c. */
41 void init_registers_i386_mmx_linux (void);
43 /* Backward compatibility for gdb without XML support. */
45 static const char *xmltarget_i386_linux_no_xml
= "@<target>\
46 <architecture>i386</architecture>\
47 <osabi>GNU/Linux</osabi>\
51 static const char *xmltarget_amd64_linux_no_xml
= "@<target>\
52 <architecture>i386:x86-64</architecture>\
53 <osabi>GNU/Linux</osabi>\
58 #include <sys/procfs.h>
59 #include <sys/ptrace.h>
62 #ifndef PTRACE_GETREGSET
63 #define PTRACE_GETREGSET 0x4204
66 #ifndef PTRACE_SETREGSET
67 #define PTRACE_SETREGSET 0x4205
71 #ifndef PTRACE_GET_THREAD_AREA
72 #define PTRACE_GET_THREAD_AREA 25
75 /* This definition comes from prctl.h, but some kernels may not have it. */
76 #ifndef PTRACE_ARCH_PRCTL
77 #define PTRACE_ARCH_PRCTL 30
80 /* The following definitions come from prctl.h, but may be absent
81 for certain configurations. */
83 #define ARCH_SET_GS 0x1001
84 #define ARCH_SET_FS 0x1002
85 #define ARCH_GET_FS 0x1003
86 #define ARCH_GET_GS 0x1004
89 /* Per-process arch-specific data we want to keep. */
91 struct arch_process_info
93 struct i386_debug_reg_state debug_reg_state
;
96 /* Per-thread arch-specific data we want to keep. */
100 /* Non-zero if our copy differs from what's recorded in the thread. */
101 int debug_registers_changed
;
106 /* Mapping between the general-purpose registers in `struct user'
107 format and GDB's register array layout.
108 Note that the transfer layout uses 64-bit regs. */
109 static /*const*/ int i386_regmap
[] =
111 RAX
* 8, RCX
* 8, RDX
* 8, RBX
* 8,
112 RSP
* 8, RBP
* 8, RSI
* 8, RDI
* 8,
113 RIP
* 8, EFLAGS
* 8, CS
* 8, SS
* 8,
114 DS
* 8, ES
* 8, FS
* 8, GS
* 8
117 #define I386_NUM_REGS (sizeof (i386_regmap) / sizeof (i386_regmap[0]))
119 /* So code below doesn't have to care, i386 or amd64. */
120 #define ORIG_EAX ORIG_RAX
122 static const int x86_64_regmap
[] =
124 RAX
* 8, RBX
* 8, RCX
* 8, RDX
* 8,
125 RSI
* 8, RDI
* 8, RBP
* 8, RSP
* 8,
126 R8
* 8, R9
* 8, R10
* 8, R11
* 8,
127 R12
* 8, R13
* 8, R14
* 8, R15
* 8,
128 RIP
* 8, EFLAGS
* 8, CS
* 8, SS
* 8,
129 DS
* 8, ES
* 8, FS
* 8, GS
* 8,
130 -1, -1, -1, -1, -1, -1, -1, -1,
131 -1, -1, -1, -1, -1, -1, -1, -1,
132 -1, -1, -1, -1, -1, -1, -1, -1,
133 -1, -1, -1, -1, -1, -1, -1, -1, -1,
137 #define X86_64_NUM_REGS (sizeof (x86_64_regmap) / sizeof (x86_64_regmap[0]))
139 #else /* ! __x86_64__ */
141 /* Mapping between the general-purpose registers in `struct user'
142 format and GDB's register array layout. */
143 static /*const*/ int i386_regmap
[] =
145 EAX
* 4, ECX
* 4, EDX
* 4, EBX
* 4,
146 UESP
* 4, EBP
* 4, ESI
* 4, EDI
* 4,
147 EIP
* 4, EFL
* 4, CS
* 4, SS
* 4,
148 DS
* 4, ES
* 4, FS
* 4, GS
* 4
151 #define I386_NUM_REGS (sizeof (i386_regmap) / sizeof (i386_regmap[0]))
155 /* Called by libthread_db. */
158 ps_get_thread_area (const struct ps_prochandle
*ph
,
159 lwpid_t lwpid
, int idx
, void **base
)
162 int use_64bit
= register_size (0) == 8;
169 if (ptrace (PTRACE_ARCH_PRCTL
, lwpid
, base
, ARCH_GET_FS
) == 0)
173 if (ptrace (PTRACE_ARCH_PRCTL
, lwpid
, base
, ARCH_GET_GS
) == 0)
184 unsigned int desc
[4];
186 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
,
187 (void *) (intptr_t) idx
, (unsigned long) &desc
) < 0)
190 *(int *)base
= desc
[1];
196 i386_cannot_store_register (int regno
)
198 return regno
>= I386_NUM_REGS
;
202 i386_cannot_fetch_register (int regno
)
204 return regno
>= I386_NUM_REGS
;
208 x86_fill_gregset (struct regcache
*regcache
, void *buf
)
213 if (register_size (0) == 8)
215 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
216 if (x86_64_regmap
[i
] != -1)
217 collect_register (regcache
, i
, ((char *) buf
) + x86_64_regmap
[i
]);
222 for (i
= 0; i
< I386_NUM_REGS
; i
++)
223 collect_register (regcache
, i
, ((char *) buf
) + i386_regmap
[i
]);
225 collect_register_by_name (regcache
, "orig_eax",
226 ((char *) buf
) + ORIG_EAX
* 4);
230 x86_store_gregset (struct regcache
*regcache
, const void *buf
)
235 if (register_size (0) == 8)
237 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
238 if (x86_64_regmap
[i
] != -1)
239 supply_register (regcache
, i
, ((char *) buf
) + x86_64_regmap
[i
]);
244 for (i
= 0; i
< I386_NUM_REGS
; i
++)
245 supply_register (regcache
, i
, ((char *) buf
) + i386_regmap
[i
]);
247 supply_register_by_name (regcache
, "orig_eax",
248 ((char *) buf
) + ORIG_EAX
* 4);
252 x86_fill_fpregset (struct regcache
*regcache
, void *buf
)
255 i387_cache_to_fxsave (regcache
, buf
);
257 i387_cache_to_fsave (regcache
, buf
);
262 x86_store_fpregset (struct regcache
*regcache
, const void *buf
)
265 i387_fxsave_to_cache (regcache
, buf
);
267 i387_fsave_to_cache (regcache
, buf
);
274 x86_fill_fpxregset (struct regcache
*regcache
, void *buf
)
276 i387_cache_to_fxsave (regcache
, buf
);
280 x86_store_fpxregset (struct regcache
*regcache
, const void *buf
)
282 i387_fxsave_to_cache (regcache
, buf
);
288 x86_fill_xstateregset (struct regcache
*regcache
, void *buf
)
290 i387_cache_to_xsave (regcache
, buf
);
294 x86_store_xstateregset (struct regcache
*regcache
, const void *buf
)
296 i387_xsave_to_cache (regcache
, buf
);
299 /* ??? The non-biarch i386 case stores all the i387 regs twice.
300 Once in i387_.*fsave.* and once in i387_.*fxsave.*.
301 This is, presumably, to handle the case where PTRACE_[GS]ETFPXREGS
302 doesn't work. IWBN to avoid the duplication in the case where it
303 does work. Maybe the arch_setup routine could check whether it works
304 and update target_regsets accordingly, maybe by moving target_regsets
305 to linux_target_ops and set the right one there, rather than having to
306 modify the target_regsets global. */
308 struct regset_info target_regsets
[] =
310 #ifdef HAVE_PTRACE_GETREGS
311 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, sizeof (elf_gregset_t
),
313 x86_fill_gregset
, x86_store_gregset
},
314 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_X86_XSTATE
, 0,
315 EXTENDED_REGS
, x86_fill_xstateregset
, x86_store_xstateregset
},
317 # ifdef HAVE_PTRACE_GETFPXREGS
318 { PTRACE_GETFPXREGS
, PTRACE_SETFPXREGS
, 0, sizeof (elf_fpxregset_t
),
320 x86_fill_fpxregset
, x86_store_fpxregset
},
323 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, sizeof (elf_fpregset_t
),
325 x86_fill_fpregset
, x86_store_fpregset
},
326 #endif /* HAVE_PTRACE_GETREGS */
327 { 0, 0, 0, -1, -1, NULL
, NULL
}
331 x86_get_pc (struct regcache
*regcache
)
333 int use_64bit
= register_size (0) == 8;
338 collect_register_by_name (regcache
, "rip", &pc
);
339 return (CORE_ADDR
) pc
;
344 collect_register_by_name (regcache
, "eip", &pc
);
345 return (CORE_ADDR
) pc
;
350 x86_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
352 int use_64bit
= register_size (0) == 8;
356 unsigned long newpc
= pc
;
357 supply_register_by_name (regcache
, "rip", &newpc
);
361 unsigned int newpc
= pc
;
362 supply_register_by_name (regcache
, "eip", &newpc
);
366 static const unsigned char x86_breakpoint
[] = { 0xCC };
367 #define x86_breakpoint_len 1
370 x86_breakpoint_at (CORE_ADDR pc
)
374 (*the_target
->read_memory
) (pc
, &c
, 1);
381 /* Support for debug registers. */
384 x86_linux_dr_get (ptid_t ptid
, int regnum
)
389 tid
= ptid_get_lwp (ptid
);
392 value
= ptrace (PTRACE_PEEKUSER
, tid
,
393 offsetof (struct user
, u_debugreg
[regnum
]), 0);
395 error ("Couldn't read debug register");
401 x86_linux_dr_set (ptid_t ptid
, int regnum
, unsigned long value
)
405 tid
= ptid_get_lwp (ptid
);
408 ptrace (PTRACE_POKEUSER
, tid
,
409 offsetof (struct user
, u_debugreg
[regnum
]), value
);
411 error ("Couldn't write debug register");
414 /* Update the inferior's debug register REGNUM from STATE. */
417 i386_dr_low_set_addr (const struct i386_debug_reg_state
*state
, int regnum
)
419 struct inferior_list_entry
*lp
;
421 /* Only need to update the threads of this process. */
422 int pid
= pid_of (get_thread_lwp (current_inferior
));
424 if (! (regnum
>= 0 && regnum
<= DR_LASTADDR
- DR_FIRSTADDR
))
425 fatal ("Invalid debug register %d", regnum
);
427 addr
= state
->dr_mirror
[regnum
];
429 for (lp
= all_lwps
.head
; lp
; lp
= lp
->next
)
431 struct lwp_info
*lwp
= (struct lwp_info
*) lp
;
433 /* The actual update is done later, we just mark that the register
435 if (pid_of (lwp
) == pid
)
436 lwp
->arch_private
->debug_registers_changed
= 1;
440 /* Update the inferior's DR7 debug control register from STATE. */
443 i386_dr_low_set_control (const struct i386_debug_reg_state
*state
)
445 struct inferior_list_entry
*lp
;
446 /* Only need to update the threads of this process. */
447 int pid
= pid_of (get_thread_lwp (current_inferior
));
449 for (lp
= all_lwps
.head
; lp
; lp
= lp
->next
)
451 struct lwp_info
*lwp
= (struct lwp_info
*) lp
;
453 /* The actual update is done later, we just mark that the register
455 if (pid_of (lwp
) == pid
)
456 lwp
->arch_private
->debug_registers_changed
= 1;
460 /* Get the value of the DR6 debug status register from the inferior
461 and record it in STATE. */
464 i386_dr_low_get_status (struct i386_debug_reg_state
*state
)
466 struct lwp_info
*lwp
= get_thread_lwp (current_inferior
);
467 ptid_t ptid
= ptid_of (lwp
);
469 state
->dr_status_mirror
= x86_linux_dr_get (ptid
, DR_STATUS
);
472 /* Watchpoint support. */
475 x86_insert_point (char type
, CORE_ADDR addr
, int len
)
477 struct process_info
*proc
= current_process ();
481 return set_gdb_breakpoint_at (addr
);
485 return i386_low_insert_watchpoint (&proc
->private->arch_private
->debug_reg_state
,
494 x86_remove_point (char type
, CORE_ADDR addr
, int len
)
496 struct process_info
*proc
= current_process ();
500 return delete_gdb_breakpoint_at (addr
);
504 return i386_low_remove_watchpoint (&proc
->private->arch_private
->debug_reg_state
,
513 x86_stopped_by_watchpoint (void)
515 struct process_info
*proc
= current_process ();
516 return i386_low_stopped_by_watchpoint (&proc
->private->arch_private
->debug_reg_state
);
520 x86_stopped_data_address (void)
522 struct process_info
*proc
= current_process ();
524 if (i386_low_stopped_data_address (&proc
->private->arch_private
->debug_reg_state
,
530 /* Called when a new process is created. */
532 static struct arch_process_info
*
533 x86_linux_new_process (void)
535 struct arch_process_info
*info
= xcalloc (1, sizeof (*info
));
537 i386_low_init_dregs (&info
->debug_reg_state
);
542 /* Called when a new thread is detected. */
544 static struct arch_lwp_info
*
545 x86_linux_new_thread (void)
547 struct arch_lwp_info
*info
= xcalloc (1, sizeof (*info
));
549 info
->debug_registers_changed
= 1;
554 /* Called when resuming a thread.
555 If the debug regs have changed, update the thread's copies. */
558 x86_linux_prepare_to_resume (struct lwp_info
*lwp
)
560 ptid_t ptid
= ptid_of (lwp
);
562 if (lwp
->arch_private
->debug_registers_changed
)
565 int pid
= ptid_get_pid (ptid
);
566 struct process_info
*proc
= find_process_pid (pid
);
567 struct i386_debug_reg_state
*state
= &proc
->private->arch_private
->debug_reg_state
;
569 for (i
= DR_FIRSTADDR
; i
<= DR_LASTADDR
; i
++)
570 x86_linux_dr_set (ptid
, i
, state
->dr_mirror
[i
]);
572 x86_linux_dr_set (ptid
, DR_CONTROL
, state
->dr_control_mirror
);
574 lwp
->arch_private
->debug_registers_changed
= 0;
577 if (lwp
->stopped_by_watchpoint
)
578 x86_linux_dr_set (ptid
, DR_STATUS
, 0);
581 /* When GDBSERVER is built as a 64-bit application on linux, the
582 PTRACE_GETSIGINFO data is always presented in 64-bit layout. Since
583 debugging a 32-bit inferior with a 64-bit GDBSERVER should look the same
584 as debugging it with a 32-bit GDBSERVER, we do the 32-bit <-> 64-bit
585 conversion in-place ourselves. */
587 /* These types below (compat_*) define a siginfo type that is layout
588 compatible with the siginfo type exported by the 32-bit userspace
593 typedef int compat_int_t
;
594 typedef unsigned int compat_uptr_t
;
596 typedef int compat_time_t
;
597 typedef int compat_timer_t
;
598 typedef int compat_clock_t
;
600 struct compat_timeval
602 compat_time_t tv_sec
;
606 typedef union compat_sigval
608 compat_int_t sival_int
;
609 compat_uptr_t sival_ptr
;
612 typedef struct compat_siginfo
620 int _pad
[((128 / sizeof (int)) - 3)];
629 /* POSIX.1b timers */
634 compat_sigval_t _sigval
;
637 /* POSIX.1b signals */
642 compat_sigval_t _sigval
;
651 compat_clock_t _utime
;
652 compat_clock_t _stime
;
655 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
670 #define cpt_si_pid _sifields._kill._pid
671 #define cpt_si_uid _sifields._kill._uid
672 #define cpt_si_timerid _sifields._timer._tid
673 #define cpt_si_overrun _sifields._timer._overrun
674 #define cpt_si_status _sifields._sigchld._status
675 #define cpt_si_utime _sifields._sigchld._utime
676 #define cpt_si_stime _sifields._sigchld._stime
677 #define cpt_si_ptr _sifields._rt._sigval.sival_ptr
678 #define cpt_si_addr _sifields._sigfault._addr
679 #define cpt_si_band _sifields._sigpoll._band
680 #define cpt_si_fd _sifields._sigpoll._fd
682 /* glibc at least up to 2.3.2 doesn't have si_timerid, si_overrun.
683 In their place is si_timer1,si_timer2. */
685 #define si_timerid si_timer1
688 #define si_overrun si_timer2
692 compat_siginfo_from_siginfo (compat_siginfo_t
*to
, siginfo_t
*from
)
694 memset (to
, 0, sizeof (*to
));
696 to
->si_signo
= from
->si_signo
;
697 to
->si_errno
= from
->si_errno
;
698 to
->si_code
= from
->si_code
;
702 to
->cpt_si_ptr
= (intptr_t) from
->si_ptr
;
704 else if (to
->si_code
== SI_USER
)
706 to
->cpt_si_pid
= from
->si_pid
;
707 to
->cpt_si_uid
= from
->si_uid
;
709 else if (to
->si_code
== SI_TIMER
)
711 to
->cpt_si_timerid
= from
->si_timerid
;
712 to
->cpt_si_overrun
= from
->si_overrun
;
713 to
->cpt_si_ptr
= (intptr_t) from
->si_ptr
;
717 switch (to
->si_signo
)
720 to
->cpt_si_pid
= from
->si_pid
;
721 to
->cpt_si_uid
= from
->si_uid
;
722 to
->cpt_si_status
= from
->si_status
;
723 to
->cpt_si_utime
= from
->si_utime
;
724 to
->cpt_si_stime
= from
->si_stime
;
730 to
->cpt_si_addr
= (intptr_t) from
->si_addr
;
733 to
->cpt_si_band
= from
->si_band
;
734 to
->cpt_si_fd
= from
->si_fd
;
737 to
->cpt_si_pid
= from
->si_pid
;
738 to
->cpt_si_uid
= from
->si_uid
;
739 to
->cpt_si_ptr
= (intptr_t) from
->si_ptr
;
746 siginfo_from_compat_siginfo (siginfo_t
*to
, compat_siginfo_t
*from
)
748 memset (to
, 0, sizeof (*to
));
750 to
->si_signo
= from
->si_signo
;
751 to
->si_errno
= from
->si_errno
;
752 to
->si_code
= from
->si_code
;
756 to
->si_ptr
= (void *) (intptr_t) from
->cpt_si_ptr
;
758 else if (to
->si_code
== SI_USER
)
760 to
->si_pid
= from
->cpt_si_pid
;
761 to
->si_uid
= from
->cpt_si_uid
;
763 else if (to
->si_code
== SI_TIMER
)
765 to
->si_timerid
= from
->cpt_si_timerid
;
766 to
->si_overrun
= from
->cpt_si_overrun
;
767 to
->si_ptr
= (void *) (intptr_t) from
->cpt_si_ptr
;
771 switch (to
->si_signo
)
774 to
->si_pid
= from
->cpt_si_pid
;
775 to
->si_uid
= from
->cpt_si_uid
;
776 to
->si_status
= from
->cpt_si_status
;
777 to
->si_utime
= from
->cpt_si_utime
;
778 to
->si_stime
= from
->cpt_si_stime
;
784 to
->si_addr
= (void *) (intptr_t) from
->cpt_si_addr
;
787 to
->si_band
= from
->cpt_si_band
;
788 to
->si_fd
= from
->cpt_si_fd
;
791 to
->si_pid
= from
->cpt_si_pid
;
792 to
->si_uid
= from
->cpt_si_uid
;
793 to
->si_ptr
= (void* ) (intptr_t) from
->cpt_si_ptr
;
799 #endif /* __x86_64__ */
801 /* Convert a native/host siginfo object, into/from the siginfo in the
802 layout of the inferiors' architecture. Returns true if any
803 conversion was done; false otherwise. If DIRECTION is 1, then copy
804 from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to
808 x86_siginfo_fixup (struct siginfo
*native
, void *inf
, int direction
)
811 /* Is the inferior 32-bit? If so, then fixup the siginfo object. */
812 if (register_size (0) == 4)
814 if (sizeof (struct siginfo
) != sizeof (compat_siginfo_t
))
815 fatal ("unexpected difference in siginfo");
818 compat_siginfo_from_siginfo ((struct compat_siginfo
*) inf
, native
);
820 siginfo_from_compat_siginfo (native
, (struct compat_siginfo
*) inf
);
831 /* Update gdbserver_xmltarget. */
834 x86_linux_update_xmltarget (void)
837 struct regset_info
*regset
;
838 static unsigned long long xcr0
;
839 static int have_ptrace_getregset
= -1;
840 #if !defined(__x86_64__) && defined(HAVE_PTRACE_GETFPXREGS)
841 static int have_ptrace_getfpxregs
= -1;
844 if (!current_inferior
)
847 /* Before changing the register cache internal layout or the target
848 regsets, flush the contents of the current valid caches back to
850 regcache_invalidate ();
852 pid
= pid_of (get_thread_lwp (current_inferior
));
854 if (num_xmm_registers
== 8)
855 init_registers_i386_linux ();
857 init_registers_amd64_linux ();
860 # ifdef HAVE_PTRACE_GETFPXREGS
861 if (have_ptrace_getfpxregs
== -1)
863 elf_fpxregset_t fpxregs
;
865 if (ptrace (PTRACE_GETFPXREGS
, pid
, 0, (int) &fpxregs
) < 0)
867 have_ptrace_getfpxregs
= 0;
868 x86_xcr0
= I386_XSTATE_X87_MASK
;
870 /* Disable PTRACE_GETFPXREGS. */
871 for (regset
= target_regsets
;
872 regset
->fill_function
!= NULL
; regset
++)
873 if (regset
->get_request
== PTRACE_GETFPXREGS
)
880 have_ptrace_getfpxregs
= 1;
883 if (!have_ptrace_getfpxregs
)
885 init_registers_i386_mmx_linux ();
889 init_registers_i386_linux ();
897 if (num_xmm_registers
== 8)
898 gdbserver_xmltarget
= xmltarget_i386_linux_no_xml
;
900 gdbserver_xmltarget
= xmltarget_amd64_linux_no_xml
;
902 gdbserver_xmltarget
= xmltarget_i386_linux_no_xml
;
905 x86_xcr0
= I386_XSTATE_SSE_MASK
;
910 /* Check if XSAVE extended state is supported. */
911 if (have_ptrace_getregset
== -1)
913 unsigned long long xstateregs
[I386_XSTATE_SSE_SIZE
/ sizeof (long long)];
916 iov
.iov_base
= xstateregs
;
917 iov
.iov_len
= sizeof (xstateregs
);
919 /* Check if PTRACE_GETREGSET works. */
920 if (ptrace (PTRACE_GETREGSET
, pid
, (unsigned int) NT_X86_XSTATE
,
923 have_ptrace_getregset
= 0;
927 have_ptrace_getregset
= 1;
929 /* Get XCR0 from XSAVE extended state at byte 464. */
930 xcr0
= xstateregs
[464 / sizeof (long long)];
932 /* Use PTRACE_GETREGSET if it is available. */
933 for (regset
= target_regsets
;
934 regset
->fill_function
!= NULL
; regset
++)
935 if (regset
->get_request
== PTRACE_GETREGSET
)
936 regset
->size
= I386_XSTATE_SIZE (xcr0
);
937 else if (regset
->type
!= GENERAL_REGS
)
941 if (have_ptrace_getregset
)
943 /* AVX is the highest feature we support. */
944 if ((xcr0
& I386_XSTATE_AVX_MASK
) == I386_XSTATE_AVX_MASK
)
949 /* I386 has 8 xmm regs. */
950 if (num_xmm_registers
== 8)
951 init_registers_i386_avx_linux ();
953 init_registers_amd64_avx_linux ();
955 init_registers_i386_avx_linux ();
961 /* Process qSupported query, "xmlRegisters=". Update the buffer size for
965 x86_linux_process_qsupported (const char *query
)
967 /* Return if gdb doesn't support XML. If gdb sends "xmlRegisters="
968 with "i386" in qSupported query, it supports x86 XML target
971 if (query
!= NULL
&& strncmp (query
, "xmlRegisters=", 13) == 0)
973 char *copy
= xstrdup (query
+ 13);
976 for (p
= strtok (copy
, ","); p
!= NULL
; p
= strtok (NULL
, ","))
978 if (strcmp (p
, "i386") == 0)
988 x86_linux_update_xmltarget ();
991 /* Initialize gdbserver for the architecture of the inferior. */
994 x86_arch_setup (void)
997 int pid
= pid_of (get_thread_lwp (current_inferior
));
998 char *file
= linux_child_pid_to_exec_file (pid
);
999 int use_64bit
= elf_64_file_p (file
);
1005 /* This can only happen if /proc/<pid>/exe is unreadable,
1006 but "that can't happen" if we've gotten this far.
1007 Fall through and assume this is a 32-bit program. */
1011 /* Amd64 doesn't have HAVE_LINUX_USRREGS. */
1012 the_low_target
.num_regs
= -1;
1013 the_low_target
.regmap
= NULL
;
1014 the_low_target
.cannot_fetch_register
= NULL
;
1015 the_low_target
.cannot_store_register
= NULL
;
1017 /* Amd64 has 16 xmm regs. */
1018 num_xmm_registers
= 16;
1020 x86_linux_update_xmltarget ();
1025 /* Ok we have a 32-bit inferior. */
1027 the_low_target
.num_regs
= I386_NUM_REGS
;
1028 the_low_target
.regmap
= i386_regmap
;
1029 the_low_target
.cannot_fetch_register
= i386_cannot_fetch_register
;
1030 the_low_target
.cannot_store_register
= i386_cannot_store_register
;
1032 /* I386 has 8 xmm regs. */
1033 num_xmm_registers
= 8;
1035 x86_linux_update_xmltarget ();
1039 x86_supports_tracepoints (void)
1044 /* This is initialized assuming an amd64 target.
1045 x86_arch_setup will correct it for i386 or amd64 targets. */
1047 struct linux_target_ops the_low_target
=
1063 x86_stopped_by_watchpoint
,
1064 x86_stopped_data_address
,
1065 /* collect_ptrace_register/supply_ptrace_register are not needed in the
1066 native i386 case (no registers smaller than an xfer unit), and are not
1067 used in the biarch case (HAVE_LINUX_USRREGS is not defined). */
1070 /* need to fix up i386 siginfo if host is amd64 */
1072 x86_linux_new_process
,
1073 x86_linux_new_thread
,
1074 x86_linux_prepare_to_resume
,
1075 x86_linux_process_qsupported
,
1076 x86_supports_tracepoints