Initial gdbserver support for amd64.

This commit is contained in:
Jung-uk Kim 2010-02-25 21:29:00 +00:00
parent 329a9a116e
commit bdcf2df5c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=204335
5 changed files with 320 additions and 4 deletions

View File

@ -2275,7 +2275,7 @@ OLD_FILES+=usr/lib/libpam_ssh.a
OLD_FILES+=usr/lib/libpam_ssh_p.a
OLD_FILES+=usr/bin/help
OLD_FILES+=usr/bin/sccs
.if ${TARGET_ARCH} != "arm" && ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "powerpc"
.if ${TARGET_ARCH} != "amd64" && ${TARGET_ARCH} != "arm" && ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "powerpc"
OLD_FILES+=usr/bin/gdbserver
.endif
OLD_FILES+=usr/bin/ssh-keysign

View File

@ -2,7 +2,7 @@
SUBDIR= doc libgdb gdb gdbtui kgdb
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "powerpc"
.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc"
SUBDIR+=gdbserver
.endif

View File

@ -14,14 +14,18 @@ SRCS= inferiors.c mem-break.c regcache.c remote-utils.c \
server.c signals.c target.c utils.c
SRCS+= fbsd-low.c
.if ${MACHINE_ARCH} == "i386"
SRCS+= fbsd-i386-low.c i387-fp.c reg-i386.c
.if ${MACHINE_ARCH} == "amd64"
SRCS+= fbsd-amd64-low.c i387-fp.c reg-x86-64.c
.endif
.if ${MACHINE_ARCH} == "arm"
SRCS+= fbsd-arm-low.c reg-arm.c
.endif
.if ${MACHINE_ARCH} == "i386"
SRCS+= fbsd-i386-low.c i387-fp.c reg-i386.c
.endif
.if ${MACHINE_ARCH} == "powerpc"
SRCS+= fbsd-ppc-low.c reg-ppc.c
.endif

View File

@ -0,0 +1,213 @@
/* GNU/FreeBSD/amd64 specific low level interface, for the remote server for GDB.
Copyright 1995, 1996, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "server.h"
#include "fbsd-low.h"
#include "i387-fp.h"
#include <sys/stddef.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <machine/reg.h>
/* Mapping between the general-purpose registers in `struct user'
format and GDB's register array layout. */
static int amd64_regmap[] = {
offsetof(struct reg, r_rax),
offsetof(struct reg, r_rbx),
offsetof(struct reg, r_rcx),
offsetof(struct reg, r_rdx),
offsetof(struct reg, r_rsi),
offsetof(struct reg, r_rdi),
offsetof(struct reg, r_rbp),
offsetof(struct reg, r_rsp),
offsetof(struct reg, r_r8),
offsetof(struct reg, r_r9),
offsetof(struct reg, r_r10),
offsetof(struct reg, r_r11),
offsetof(struct reg, r_r12),
offsetof(struct reg, r_r13),
offsetof(struct reg, r_r14),
offsetof(struct reg, r_r15),
offsetof(struct reg, r_rip),
offsetof(struct reg, r_rflags), /* XXX 64-bit */
offsetof(struct reg, r_cs),
offsetof(struct reg, r_ss),
offsetof(struct reg, r_ds),
offsetof(struct reg, r_es),
offsetof(struct reg, r_fs),
offsetof(struct reg, r_gs),
};
#define AMD64_NUM_REGS (sizeof(amd64_regmap) / sizeof(amd64_regmap[0]))
static const char amd64_breakpoint[] = { 0xCC };
#define AMD64_BP_LEN 1
extern int debug_threads;
static int
amd64_cannot_store_register(int regno)
{
return (regno >= AMD64_NUM_REGS);
}
static int
amd64_cannot_fetch_register(int regno)
{
return (regno >= AMD64_NUM_REGS);
}
static void
amd64_fill_gregset(void *buf)
{
int i;
for (i = 0; i < AMD64_NUM_REGS; i++)
collect_register(i, ((char *)buf) + amd64_regmap[i]);
}
static void
amd64_store_gregset(const void *buf)
{
int i;
for (i = 0; i < AMD64_NUM_REGS; i++)
supply_register(i, ((char *)buf) + amd64_regmap[i]);
}
static void
amd64_fill_fpregset(void *buf)
{
i387_cache_to_fsave(buf);
}
static void
amd64_store_fpregset(const void *buf)
{
i387_fsave_to_cache(buf);
}
static void
amd64_fill_fpxregset(void *buf)
{
i387_cache_to_fxsave(buf);
}
static void
amd64_store_fpxregset(const void *buf)
{
i387_fxsave_to_cache(buf);
}
struct regset_info target_regsets[] = {
{
PT_GETREGS,
PT_SETREGS,
sizeof(struct reg),
GENERAL_REGS,
amd64_fill_gregset,
amd64_store_gregset,
},
#ifdef HAVE_PTRACE_GETFPXREGS
{
PTRACE_GETFPXREGS,
PTRACE_SETFPXREGS,
sizeof(elf_fpxregset_t),
EXTENDED_REGS,
amd64_fill_fpxregset,
amd64_store_fpxregset,
},
#endif
{
PT_GETFPREGS,
PT_SETFPREGS,
sizeof(struct fpreg),
FP_REGS,
amd64_fill_fpregset,
amd64_store_fpregset,
},
{
0,
0,
-1,
-1,
NULL,
NULL,
}
};
static CORE_ADDR
amd64_get_pc(void)
{
unsigned long pc;
collect_register_by_name("rip", &pc);
if (debug_threads)
fprintf(stderr, "stop pc (before any decrement) is %016lx\n", pc);
return (pc);
}
static void
amd64_set_pc(CORE_ADDR newpc)
{
if (debug_threads)
fprintf(stderr, "set pc to %016lx\n", (long)newpc);
supply_register_by_name("rip", &newpc);
}
static int
amd64_breakpoint_at(CORE_ADDR pc)
{
unsigned char c;
read_inferior_memory(pc, &c, 1);
if (c == 0xCC)
return (1);
return (0);
}
struct fbsd_target_ops the_low_target = {
AMD64_NUM_REGS,
amd64_regmap,
amd64_cannot_fetch_register,
amd64_cannot_store_register,
amd64_get_pc,
amd64_set_pc,
amd64_breakpoint,
AMD64_BP_LEN,
NULL,
1,
amd64_breakpoint_at,
};

View File

@ -0,0 +1,99 @@
/* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
/* A register protocol for GDB, the GNU debugger.
Copyright 2001, 2002 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This file was created with the aid of ``regdat.sh'' and ``../../../../contrib/gdb/gdb/regformats/reg-x86-64.dat''. */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "regdef.h"
#include "regcache.h"
struct reg regs_x86_64[] = {
{ "rax", 0, 64 },
{ "rbx", 64, 64 },
{ "rcx", 128, 64 },
{ "rdx", 192, 64 },
{ "rsi", 256, 64 },
{ "rdi", 320, 64 },
{ "rbp", 384, 64 },
{ "rsp", 448, 64 },
{ "r8", 512, 64 },
{ "r9", 576, 64 },
{ "r10", 640, 64 },
{ "r11", 704, 64 },
{ "r12", 768, 64 },
{ "r13", 832, 64 },
{ "r14", 896, 64 },
{ "r15", 960, 64 },
{ "rip", 1024, 64 },
{ "eflags", 1088, 32 },
{ "cs", 1120, 32 },
{ "ss", 1152, 32 },
{ "ds", 1184, 32 },
{ "es", 1216, 32 },
{ "fs", 1248, 32 },
{ "gs", 1280, 32 },
{ "st0", 1312, 80 },
{ "st1", 1392, 80 },
{ "st2", 1472, 80 },
{ "st3", 1552, 80 },
{ "st4", 1632, 80 },
{ "st5", 1712, 80 },
{ "st6", 1792, 80 },
{ "st7", 1872, 80 },
{ "fctrl", 1952, 32 },
{ "fstat", 1984, 32 },
{ "ftag", 2016, 32 },
{ "fiseg", 2048, 32 },
{ "fioff", 2080, 32 },
{ "foseg", 2112, 32 },
{ "fooff", 2144, 32 },
{ "fop", 2176, 32 },
{ "xmm0", 2208, 128 },
{ "xmm1", 2336, 128 },
{ "xmm2", 2464, 128 },
{ "xmm3", 2592, 128 },
{ "xmm4", 2720, 128 },
{ "xmm5", 2848, 128 },
{ "xmm6", 2976, 128 },
{ "xmm7", 3104, 128 },
{ "xmm8", 3232, 128 },
{ "xmm9", 3360, 128 },
{ "xmm10", 3488, 128 },
{ "xmm11", 3616, 128 },
{ "xmm12", 3744, 128 },
{ "xmm13", 3872, 128 },
{ "xmm14", 4000, 128 },
{ "xmm15", 4128, 128 },
{ "mxcsr", 4256, 32 },
};
const char *expedite_regs_x86_64[] = { "rbp", "rsp", "rip", 0 };
void
init_registers ()
{
set_register_cache (regs_x86_64,
sizeof (regs_x86_64) / sizeof (regs_x86_64[0]));
gdbserver_expedite_regs = expedite_regs_x86_64;
}