From 5cd226f27555deecd8cb96019e0e915c7c7c2a3c Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 3 Jul 2009 12:06:36 +0000 Subject: [PATCH] 2009-06-29 Tristan Gingold * i386-darwin-tdep.c (amd64_darwin_thread_state_reg_offset) (amd64_darwin_thread_state_num_regs) (amd64_darwin_sigcontext_addr, x86_darwin_init_abi_64): Moved to amd64-darwin-tdep.c (_initialize_i386_darwin_tdep): Remove 64 bits parts. (darwin_dwarf_signal_frame_p): Make public. * amd64-darwin-tdep.c: New file with most chunks from i386-darwin-tdep.c * i386-darwin-tdep.h: Add a prototype for darwin_dwarf_signal_frame_p. (amd64_darwin_thread_state_reg_offset) (amd64_darwin_thread_state_num_regs): Moved to amd64-darwin-tdep.h * amd64-darwin-tdep.h: New file. * i386-darwin-nat.c: Only includes amd64-nat.h and amd64-darwin-tdep.h if BFD64 is defined. (i386_darwin_fetch_inferior_registers): Add #ifdef BFD64/#endif around 64 bits parts. (i386_darwin_store_inferior_registers): Ditto. (darwin_set_sstep): Ditto. (darwin_complete_target): Ditto. (amd64_darwin_sstep_at_sigreturn): Ditto. * configure.tgt: Create a separate entry for x86_64-*-darwin. Add 64 bits support for i386-*-darwin if --enable-64-bit-bfd. * Makefile.in (ALLDEPFILES): Add amd64-darwin-tdep.c, darwin-nat.c, i386-darwin-tdep.c i386-darwin-nat.c (ALL_64_TARGET_OBS): Add amd64-darwin-tdep.o --- gdb/ChangeLog | 28 +++++++++ gdb/Makefile.in | 7 ++- gdb/amd64-darwin-tdep.c | 129 ++++++++++++++++++++++++++++++++++++++++ gdb/amd64-darwin-tdep.h | 28 +++++++++ gdb/configure.tgt | 15 ++++- gdb/i386-darwin-nat.c | 16 ++++- gdb/i386-darwin-tdep.c | 81 +------------------------ gdb/i386-darwin-tdep.h | 9 ++- 8 files changed, 223 insertions(+), 90 deletions(-) create mode 100644 gdb/amd64-darwin-tdep.c create mode 100644 gdb/amd64-darwin-tdep.h diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9f4c730ed41..92534d9aa36 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,31 @@ +2009-06-29 Tristan Gingold + + * i386-darwin-tdep.c (amd64_darwin_thread_state_reg_offset) + (amd64_darwin_thread_state_num_regs) + (amd64_darwin_sigcontext_addr, x86_darwin_init_abi_64): Moved to + amd64-darwin-tdep.c + (_initialize_i386_darwin_tdep): Remove 64 bits parts. + (darwin_dwarf_signal_frame_p): Make public. + * amd64-darwin-tdep.c: New file with most chunks from + i386-darwin-tdep.c + * i386-darwin-tdep.h: Add a prototype for darwin_dwarf_signal_frame_p. + (amd64_darwin_thread_state_reg_offset) + (amd64_darwin_thread_state_num_regs): Moved to amd64-darwin-tdep.h + * amd64-darwin-tdep.h: New file. + * i386-darwin-nat.c: Only includes amd64-nat.h and amd64-darwin-tdep.h + if BFD64 is defined. + (i386_darwin_fetch_inferior_registers): Add #ifdef BFD64/#endif around + 64 bits parts. + (i386_darwin_store_inferior_registers): Ditto. + (darwin_set_sstep): Ditto. + (darwin_complete_target): Ditto. + (amd64_darwin_sstep_at_sigreturn): Ditto. + * configure.tgt: Create a separate entry for x86_64-*-darwin. + Add 64 bits support for i386-*-darwin if --enable-64-bit-bfd. + * Makefile.in (ALLDEPFILES): Add amd64-darwin-tdep.c, darwin-nat.c, + i386-darwin-tdep.c i386-darwin-nat.c + (ALL_64_TARGET_OBS): Add amd64-darwin-tdep.o + 2009-07-02 Pedro Alves * linux-fork.c (forks_exist_p): Drop unnecessary extern. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 903bbaac243..7659a8fb481 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -466,7 +466,8 @@ TARGET_OBS = @TARGET_OBS@ ALL_64_TARGET_OBS = \ alphabsd-tdep.o alphafbsd-tdep.o alpha-linux-tdep.o alpha-mdebug-tdep.o \ alphanbsd-tdep.o alphaobsd-tdep.o alpha-osf1-tdep.o alpha-tdep.o \ - amd64fbsd-tdep.o amd64-dicos-tdep.o amd64-linux-tdep.o amd64nbsd-tdep.o \ + amd64fbsd-tdep.o amd64-darwin-tdep.o amd64-dicos-tdep.o \ + amd64-linux-tdep.o amd64nbsd-tdep.o \ amd64obsd-tdep.o amd64-sol2-tdep.o amd64-tdep.o amd64-windows-tdep.o \ ia64-linux-tdep.o ia64-tdep.o \ mips64obsd-tdep.o \ @@ -1290,6 +1291,7 @@ ALLDEPFILES = \ amd64bsd-nat.c amd64fbsd-nat.c amd64fbsd-tdep.c \ amd64nbsd-nat.c amd64nbsd-tdep.c \ amd64obsd-nat.c amd64obsd-tdep.c \ + amd64-darwin-tdep.c \ amd64-dicos-tdep.c \ amd64-linux-nat.c amd64-linux-tdep.c \ amd64-sol2-tdep.c \ @@ -1298,7 +1300,7 @@ ALLDEPFILES = \ avr-tdep.c \ bsd-uthread.c bsd-kvm.c \ core-regset.c corelow.c \ - dcache.c dicos-tdep.c \ + dcache.c dicos-tdep.c darwin-nat.c \ exec.c \ fbsd-nat.c \ fork-child.c \ @@ -1314,6 +1316,7 @@ ALLDEPFILES = \ i386bsd-nat.c i386bsd-tdep.c i386fbsd-nat.c i386fbsd-tdep.c \ i386nbsd-nat.c i386nbsd-tdep.c i386obsd-nat.c i386obsd-tdep.c \ i387-tdep.c \ + i386-darwin-tdep.c i386-darwin-nat.c \ i386-dicos-tdep.c \ i386-linux-tdep.c i386-nat.c \ i386-sol2-nat.c i386-sol2-tdep.c \ diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c new file mode 100644 index 00000000000..69fd756ff0c --- /dev/null +++ b/gdb/amd64-darwin-tdep.c @@ -0,0 +1,129 @@ +/* Darwin support for GDB, the GNU debugger. + Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2008, 2009 + Free Software Foundation, Inc. + + Contributed by Apple Computer, 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 3 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, see . */ + +#include "defs.h" +#include "frame.h" +#include "inferior.h" +#include "gdbcore.h" +#include "target.h" +#include "floatformat.h" +#include "symtab.h" +#include "regcache.h" +#include "libbfd.h" +#include "objfiles.h" + +#include "i387-tdep.h" +#include "amd64-tdep.h" +#include "osabi.h" +#include "ui-out.h" +#include "symtab.h" +#include "frame.h" +#include "gdb_assert.h" +#include "amd64-darwin-tdep.h" +#include "i386-darwin-tdep.h" +#include "solib.h" +#include "solib-darwin.h" +#include "dwarf2-frame.h" + +/* Offsets into the struct x86_thread_state64 where we'll find the saved regs. + From and amd64-tdep.h. */ +int amd64_darwin_thread_state_reg_offset[] = +{ + 0 * 8, /* %rax */ + 1 * 8, /* %rbx */ + 2 * 8, /* %rcx */ + 3 * 8, /* %rdx */ + 5 * 8, /* %rsi */ + 4 * 8, /* %rdi */ + 6 * 8, /* %rbp */ + 7 * 8, /* %rsp */ + 8 * 8, /* %r8 ... */ + 9 * 8, + 10 * 8, + 11 * 8, + 12 * 8, + 13 * 8, + 14 * 8, + 15 * 8, /* ... %r15 */ + 16 * 8, /* %rip */ + 17 * 8, /* %rflags */ + 18 * 8, /* %cs */ + -1, /* %ss */ + -1, /* %ds */ + -1, /* %es */ + 19 * 8, /* %fs */ + 20 * 8 /* %gs */ +}; + +const int amd64_darwin_thread_state_num_regs = + ARRAY_SIZE (amd64_darwin_thread_state_reg_offset); + +/* Assuming THIS_FRAME is a Darwin sigtramp routine, return the + address of the associated sigcontext structure. */ + +static CORE_ADDR +amd64_darwin_sigcontext_addr (struct frame_info *this_frame) +{ + struct gdbarch *gdbarch = get_frame_arch (this_frame); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + CORE_ADDR rbx; + CORE_ADDR si; + gdb_byte buf[8]; + + /* A pointer to the ucontext is passed as the fourth argument + to the signal handler, which is saved in rbx. */ + get_frame_register (this_frame, AMD64_RBX_REGNUM, buf); + rbx = extract_unsigned_integer (buf, 8, byte_order); + + /* The pointer to mcontext is at offset 48. */ + read_memory (rbx + 48, buf, 8); + + /* First register (rax) is at offset 16. */ + return extract_unsigned_integer (buf, 8, byte_order) + 16; +} + +static void +x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + amd64_init_abi (info, gdbarch); + + tdep->struct_return = reg_struct_return; + + dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p); + + tdep->sigtramp_p = i386_sigtramp_p; + tdep->sigcontext_addr = amd64_darwin_sigcontext_addr; + tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset; + tdep->sc_num_regs = amd64_darwin_thread_state_num_regs; + + tdep->jb_pc_offset = 148; + + set_solib_ops (gdbarch, &darwin_so_ops); +} + +void +_initialize_amd64_darwin_tdep (void) +{ + gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, + GDB_OSABI_DARWIN, x86_darwin_init_abi_64); +} diff --git a/gdb/amd64-darwin-tdep.h b/gdb/amd64-darwin-tdep.h new file mode 100644 index 00000000000..c3a4beae6f9 --- /dev/null +++ b/gdb/amd64-darwin-tdep.h @@ -0,0 +1,28 @@ +/* Target-dependent code for Darwin x86-64. + + Copyright (C) 2009 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 3 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, see . */ +#ifndef __AMD64_DARWIN_TDEP_H__ +#define __AMD64_DARWIN_TDEP_H__ + +/* Mapping between the general-purpose registers in Darwin x86-64 thread + state and GDB's register cache layout. + Indexed by amd64_regnum. */ +extern int amd64_darwin_thread_state_reg_offset[]; +extern const int amd64_darwin_thread_state_num_regs; + +#endif /* __AMD64_DARWIN_TDEP_H__ */ diff --git a/gdb/configure.tgt b/gdb/configure.tgt index b704842077c..c76e316e56f 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -151,10 +151,14 @@ hppa*-*-*) gdb_target_obs="hppa-tdep.o" ;; -i[34567]86-*-darwin* | x86_64-*-darwin*) +i[34567]86-*-darwin*) # Target: Darwin/i386 - gdb_target_obs="amd64-tdep.o i386-tdep.o i387-tdep.o \ + gdb_target_obs="i386-tdep.o i387-tdep.o \ i386-darwin-tdep.o solib.o solib-darwin.o" + if test "x$enable_64_bit_bfd" = "xyes"; then + # Target: GNU/Linux x86-64 + gdb_target_obs="amd64-tdep.o amd64-darwin-tdep.o ${gdb_target_obs}" + fi ;; i[34567]86-*-dicos*) # Target: DICOS/i386 @@ -524,6 +528,13 @@ vax-*-*) gdb_target_obs="vax-tdep.o" ;; +x86_64-*-darwin*) + # Target: Darwin/x86-64 + gdb_target_obs="amd64-tdep.o i386-tdep.o i387-tdep.o \ + i386-darwin-tdep.o amd64-darwin-tdep.o \ + solib.o solib-darwin.o" + ;; + x86_64-*-dicos*) # Target: DICOS/x86-64 gdb_target_obs="amd64-tdep.o i386-tdep.o i387-tdep.o \ diff --git a/gdb/i386-darwin-nat.c b/gdb/i386-darwin-nat.c index df029bcfa02..328372357a9 100644 --- a/gdb/i386-darwin-nat.c +++ b/gdb/i386-darwin-nat.c @@ -30,7 +30,6 @@ #include "regcache.h" #include "gdb_assert.h" #include "i386-tdep.h" -#include "amd64-nat.h" #include "i387-tdep.h" #include "gdbarch.h" #include "arch-utils.h" @@ -39,6 +38,11 @@ #include "darwin-nat.h" #include "i386-darwin-tdep.h" +#ifdef BFD64 +#include "amd64-nat.h" +#include "amd64-darwin-tdep.h" +#endif + /* Read register values from the inferior process. If REGNO is -1, do this for all registers. Otherwise, REGNO specifies which register (so we can save time). */ @@ -50,6 +54,7 @@ i386_darwin_fetch_inferior_registers (struct target_ops *ops, int fetched = 0; struct gdbarch *gdbarch = get_regcache_arch (regcache); +#ifdef BFD64 if (gdbarch_ptr_bit (gdbarch) == 64) { if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno)) @@ -89,6 +94,7 @@ i386_darwin_fetch_inferior_registers (struct target_ops *ops, } } else +#endif { if (regno == -1 || regno < I386_NUM_GREGS) { @@ -151,6 +157,7 @@ i386_darwin_store_inferior_registers (struct target_ops *ops, thread_t current_thread = ptid_get_tid (inferior_ptid); struct gdbarch *gdbarch = get_regcache_arch (regcache); +#ifdef BFD64 if (gdbarch_ptr_bit (gdbarch) == 64) { if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno)) @@ -196,6 +203,7 @@ i386_darwin_store_inferior_registers (struct target_ops *ops, } } else +#endif { if (regno == -1 || regno < I386_NUM_GREGS) { @@ -475,6 +483,7 @@ i386_darwin_sstep_at_sigreturn (x86_thread_state_t *regs) return 0; } +#ifdef BFD64 static int amd64_darwin_sstep_at_sigreturn (x86_thread_state_t *regs) { @@ -504,6 +513,7 @@ amd64_darwin_sstep_at_sigreturn (x86_thread_state_t *regs) } return 0; } +#endif void darwin_set_sstep (thread_t thread, int enable) @@ -537,6 +547,7 @@ darwin_set_sstep (thread_t thread, int enable) MACH_CHECK_ERROR (kret); } break; +#ifdef BFD64 case x86_THREAD_STATE64: { __uint64_t bit = enable ? X86_EFLAGS_T : 0; @@ -551,6 +562,7 @@ darwin_set_sstep (thread_t thread, int enable) MACH_CHECK_ERROR (kret); } break; +#endif default: error (_("darwin_set_sstep: unknown flavour: %d\n"), regs.tsh.flavor); } @@ -559,10 +571,12 @@ darwin_set_sstep (thread_t thread, int enable) void darwin_complete_target (struct target_ops *target) { +#ifdef BFD64 amd64_native_gregset64_reg_offset = amd64_darwin_thread_state_reg_offset; amd64_native_gregset64_num_regs = amd64_darwin_thread_state_num_regs; amd64_native_gregset32_reg_offset = i386_darwin_thread_state_reg_offset; amd64_native_gregset32_num_regs = i386_darwin_thread_state_num_regs; +#endif target->to_fetch_registers = i386_darwin_fetch_inferior_registers; target->to_store_registers = i386_darwin_store_inferior_registers; diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c index fd53e791fa0..0cd9403ba62 100644 --- a/gdb/i386-darwin-tdep.c +++ b/gdb/i386-darwin-tdep.c @@ -32,7 +32,6 @@ #include "i387-tdep.h" #include "i386-tdep.h" -#include "amd64-tdep.h" #include "osabi.h" #include "ui-out.h" #include "symtab.h" @@ -68,39 +67,6 @@ int i386_darwin_thread_state_reg_offset[] = const int i386_darwin_thread_state_num_regs = ARRAY_SIZE (i386_darwin_thread_state_reg_offset); -/* Offsets into the struct x86_thread_state64 where we'll find the saved regs. - From and amd64-tdep.h. */ -int amd64_darwin_thread_state_reg_offset[] = -{ - 0 * 8, /* %rax */ - 1 * 8, /* %rbx */ - 2 * 8, /* %rcx */ - 3 * 8, /* %rdx */ - 5 * 8, /* %rsi */ - 4 * 8, /* %rdi */ - 6 * 8, /* %rbp */ - 7 * 8, /* %rsp */ - 8 * 8, /* %r8 ... */ - 9 * 8, - 10 * 8, - 11 * 8, - 12 * 8, - 13 * 8, - 14 * 8, - 15 * 8, /* ... %r15 */ - 16 * 8, /* %rip */ - 17 * 8, /* %rflags */ - 18 * 8, /* %cs */ - -1, /* %ss */ - -1, /* %ds */ - -1, /* %es */ - 19 * 8, /* %fs */ - 20 * 8 /* %gs */ -}; - -const int amd64_darwin_thread_state_num_regs = - ARRAY_SIZE (amd64_darwin_thread_state_reg_offset); - /* Assuming THIS_FRAME is a Darwin sigtramp routine, return the address of the associated sigcontext structure. */ @@ -128,27 +94,6 @@ i386_darwin_sigcontext_addr (struct frame_info *this_frame) return extract_unsigned_integer (buf, 4, byte_order) + 12; } -static CORE_ADDR -amd64_darwin_sigcontext_addr (struct frame_info *this_frame) -{ - struct gdbarch *gdbarch = get_frame_arch (this_frame); - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - CORE_ADDR rbx; - CORE_ADDR si; - gdb_byte buf[8]; - - /* A pointer to the ucontext is passed as the fourth argument - to the signal handler, which is saved in rbx. */ - get_frame_register (this_frame, AMD64_RBX_REGNUM, buf); - rbx = extract_unsigned_integer (buf, 8, byte_order); - - /* The pointer to mcontext is at offset 48. */ - read_memory (rbx + 48, buf, 8); - - /* First register (rax) is at offset 16. */ - return extract_unsigned_integer (buf, 8, byte_order) + 16; -} - /* Return true if the PC of THIS_FRAME is in a signal trampoline which may have DWARF-2 CFI. @@ -157,7 +102,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame) Without this function, the frame is recognized as a normal frame which is not expected. */ -static int +int darwin_dwarf_signal_frame_p (struct gdbarch *gdbarch, struct frame_info *this_frame) { @@ -187,27 +132,6 @@ i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_solib_ops (gdbarch, &darwin_so_ops); } -static void -x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch) -{ - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - - amd64_init_abi (info, gdbarch); - - tdep->struct_return = reg_struct_return; - - dwarf2_frame_set_signal_frame_p (gdbarch, darwin_dwarf_signal_frame_p); - - tdep->sigtramp_p = i386_sigtramp_p; - tdep->sigcontext_addr = amd64_darwin_sigcontext_addr; - tdep->sc_reg_offset = amd64_darwin_thread_state_reg_offset; - tdep->sc_num_regs = amd64_darwin_thread_state_num_regs; - - tdep->jb_pc_offset = 148; - - set_solib_ops (gdbarch, &darwin_so_ops); -} - static enum gdb_osabi i386_mach_o_osabi_sniffer (bfd *abfd) { @@ -228,7 +152,4 @@ _initialize_i386_darwin_tdep (void) gdbarch_register_osabi (bfd_arch_i386, bfd_mach_i386_i386, GDB_OSABI_DARWIN, i386_darwin_init_abi); - - gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, - GDB_OSABI_DARWIN, x86_darwin_init_abi_64); } diff --git a/gdb/i386-darwin-tdep.h b/gdb/i386-darwin-tdep.h index 4d16ceff17f..d0de560d61b 100644 --- a/gdb/i386-darwin-tdep.h +++ b/gdb/i386-darwin-tdep.h @@ -19,15 +19,14 @@ #ifndef __I386_DARWIN_TDEP_H__ #define __I386_DARWIN_TDEP_H__ +#include "defs.h" +#include "frame.h" + /* Mapping between the general-purpose registers in Darwin x86 thread_state struct and GDB's register cache layout. */ extern int i386_darwin_thread_state_reg_offset[]; extern const int i386_darwin_thread_state_num_regs; -/* Mapping between the general-purpose registers in Darwin x86-64 thread - state and GDB's register cache layout. - Indexed by amd64_regnum. */ -extern int amd64_darwin_thread_state_reg_offset[]; -extern const int amd64_darwin_thread_state_num_regs; +int darwin_dwarf_signal_frame_p (struct gdbarch *, struct frame_info *); #endif /* __I386_DARWIN_TDEP_H__ */ -- 2.30.2