gdb/i386-darwin-nat.c - gdb

Functions defined

Macros defined

Source code

  1. /* Darwin support for GDB, the GNU debugger.
  2.    Copyright (C) 1997-2015 Free Software Foundation, Inc.

  3.    Contributed by Apple Computer, Inc.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "frame.h"
  17. #include "inferior.h"
  18. #include "target.h"
  19. #include "symfile.h"
  20. #include "symtab.h"
  21. #include "objfiles.h"
  22. #include "gdbcmd.h"
  23. #include "regcache.h"
  24. #include "i386-tdep.h"
  25. #include "i387-tdep.h"
  26. #include "gdbarch.h"
  27. #include "arch-utils.h"
  28. #include "gdbcore.h"

  29. #include "x86-nat.h"
  30. #include "darwin-nat.h"
  31. #include "i386-darwin-tdep.h"

  32. #ifdef BFD64
  33. #include "amd64-nat.h"
  34. #include "amd64-tdep.h"
  35. #include "amd64-darwin-tdep.h"
  36. #endif

  37. /* Read register values from the inferior process.
  38.    If REGNO is -1, do this for all registers.
  39.    Otherwise, REGNO specifies which register (so we can save time).  */
  40. static void
  41. i386_darwin_fetch_inferior_registers (struct target_ops *ops,
  42.                                       struct regcache *regcache, int regno)
  43. {
  44.   thread_t current_thread = ptid_get_tid (inferior_ptid);
  45.   int fetched = 0;
  46.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  47. #ifdef BFD64
  48.   if (gdbarch_ptr_bit (gdbarch) == 64)
  49.     {
  50.       if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno))
  51.         {
  52.           x86_thread_state_t gp_regs;
  53.           unsigned int gp_count = x86_THREAD_STATE_COUNT;
  54.           kern_return_t ret;

  55.           ret = thread_get_state
  56.             (current_thread, x86_THREAD_STATE, (thread_state_t) & gp_regs,
  57.              &gp_count);
  58.           if (ret != KERN_SUCCESS)
  59.             {
  60.               printf_unfiltered (_("Error calling thread_get_state for "
  61.                                    "GP registers for thread 0x%lx\n"),
  62.                                  (unsigned long) current_thread);
  63.               MACH_CHECK_ERROR (ret);
  64.             }

  65.           /* Some kernels don't sanitize the values.  */
  66.           gp_regs.uts.ts64.__fs &= 0xffff;
  67.           gp_regs.uts.ts64.__gs &= 0xffff;

  68.           amd64_supply_native_gregset (regcache, &gp_regs.uts, -1);
  69.           fetched++;
  70.         }

  71.       if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno))
  72.         {
  73.           x86_float_state_t fp_regs;
  74.           unsigned int fp_count = x86_FLOAT_STATE_COUNT;
  75.           kern_return_t ret;

  76.           ret = thread_get_state
  77.             (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs,
  78.              &fp_count);
  79.           if (ret != KERN_SUCCESS)
  80.             {
  81.               printf_unfiltered (_("Error calling thread_get_state for "
  82.                                    "float registers for thread 0x%lx\n"),
  83.                                  (unsigned long) current_thread);
  84.               MACH_CHECK_ERROR (ret);
  85.             }
  86.           amd64_supply_fxsave (regcache, -1, &fp_regs.ufs.fs64.__fpu_fcw);
  87.           fetched++;
  88.         }
  89.     }
  90.   else
  91. #endif
  92.     {
  93.       if (regno == -1 || regno < I386_NUM_GREGS)
  94.         {
  95.           x86_thread_state32_t gp_regs;
  96.           unsigned int gp_count = x86_THREAD_STATE32_COUNT;
  97.           kern_return_t ret;
  98.           int i;

  99.           ret = thread_get_state
  100.             (current_thread, x86_THREAD_STATE32, (thread_state_t) &gp_regs,
  101.              &gp_count);
  102.           if (ret != KERN_SUCCESS)
  103.             {
  104.               printf_unfiltered (_("Error calling thread_get_state for "
  105.                                    "GP registers for thread 0x%lx\n"),
  106.                                  (unsigned long) current_thread);
  107.               MACH_CHECK_ERROR (ret);
  108.             }
  109.           for (i = 0; i < I386_NUM_GREGS; i++)
  110.             regcache_raw_supply
  111.               (regcache, i,
  112.                (char *)&gp_regs + i386_darwin_thread_state_reg_offset[i]);

  113.           fetched++;
  114.         }

  115.       if (regno == -1
  116.           || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS))
  117.         {
  118.           x86_float_state32_t fp_regs;
  119.           unsigned int fp_count = x86_FLOAT_STATE32_COUNT;
  120.           kern_return_t ret;

  121.           ret = thread_get_state
  122.             (current_thread, x86_FLOAT_STATE32, (thread_state_t) &fp_regs,
  123.              &fp_count);
  124.           if (ret != KERN_SUCCESS)
  125.             {
  126.               printf_unfiltered (_("Error calling thread_get_state for "
  127.                                    "float registers for thread 0x%lx\n"),
  128.                                  (unsigned long) current_thread);
  129.               MACH_CHECK_ERROR (ret);
  130.             }
  131.           i387_supply_fxsave (regcache, -1, &fp_regs.__fpu_fcw);
  132.           fetched++;
  133.         }
  134.     }

  135.   if (! fetched)
  136.     {
  137.       warning (_("unknown register %d"), regno);
  138.       regcache_raw_supply (regcache, regno, NULL);
  139.     }
  140. }

  141. /* Store our register values back into the inferior.
  142.    If REGNO is -1, do this for all registers.
  143.    Otherwise, REGNO specifies which register (so we can save time).  */

  144. static void
  145. i386_darwin_store_inferior_registers (struct target_ops *ops,
  146.                                       struct regcache *regcache, int regno)
  147. {
  148.   thread_t current_thread = ptid_get_tid (inferior_ptid);
  149.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  150. #ifdef BFD64
  151.   if (gdbarch_ptr_bit (gdbarch) == 64)
  152.     {
  153.       if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno))
  154.         {
  155.           x86_thread_state_t gp_regs;
  156.           kern_return_t ret;
  157.           unsigned int gp_count = x86_THREAD_STATE_COUNT;

  158.           ret = thread_get_state
  159.             (current_thread, x86_THREAD_STATE, (thread_state_t) &gp_regs,
  160.              &gp_count);
  161.           MACH_CHECK_ERROR (ret);
  162.           gdb_assert (gp_regs.tsh.flavor == x86_THREAD_STATE64);
  163.           gdb_assert (gp_regs.tsh.count == x86_THREAD_STATE64_COUNT);

  164.           amd64_collect_native_gregset (regcache, &gp_regs.uts, regno);

  165.           /* Some kernels don't sanitize the values.  */
  166.           gp_regs.uts.ts64.__fs &= 0xffff;
  167.           gp_regs.uts.ts64.__gs &= 0xffff;

  168.           ret = thread_set_state (current_thread, x86_THREAD_STATE,
  169.                                   (thread_state_t) &gp_regs,
  170.                                   x86_THREAD_STATE_COUNT);
  171.           MACH_CHECK_ERROR (ret);
  172.         }

  173.       if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno))
  174.         {
  175.           x86_float_state_t fp_regs;
  176.           kern_return_t ret;
  177.           unsigned int fp_count = x86_FLOAT_STATE_COUNT;

  178.           ret = thread_get_state
  179.             (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs,
  180.              &fp_count);
  181.           MACH_CHECK_ERROR (ret);
  182.           gdb_assert (fp_regs.fsh.flavor == x86_FLOAT_STATE64);
  183.           gdb_assert (fp_regs.fsh.count == x86_FLOAT_STATE64_COUNT);

  184.           amd64_collect_fxsave (regcache, regno, &fp_regs.ufs.fs64.__fpu_fcw);

  185.           ret = thread_set_state (current_thread, x86_FLOAT_STATE,
  186.                                   (thread_state_t) & fp_regs,
  187.                                   x86_FLOAT_STATE_COUNT);
  188.           MACH_CHECK_ERROR (ret);
  189.         }
  190.     }
  191.   else
  192. #endif
  193.     {
  194.       if (regno == -1 || regno < I386_NUM_GREGS)
  195.         {
  196.           x86_thread_state32_t gp_regs;
  197.           kern_return_t ret;
  198.           unsigned int gp_count = x86_THREAD_STATE32_COUNT;
  199.           int i;

  200.           ret = thread_get_state
  201.             (current_thread, x86_THREAD_STATE32, (thread_state_t) &gp_regs,
  202.              &gp_count);
  203.           MACH_CHECK_ERROR (ret);

  204.           for (i = 0; i < I386_NUM_GREGS; i++)
  205.             if (regno == -1 || regno == i)
  206.               regcache_raw_collect
  207.                 (regcache, i,
  208.                  (char *)&gp_regs + i386_darwin_thread_state_reg_offset[i]);

  209.           ret = thread_set_state (current_thread, x86_THREAD_STATE32,
  210.                                   (thread_state_t) &gp_regs,
  211.                                   x86_THREAD_STATE32_COUNT);
  212.           MACH_CHECK_ERROR (ret);
  213.         }

  214.       if (regno == -1
  215.           || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS))
  216.         {
  217.           x86_float_state32_t fp_regs;
  218.           unsigned int fp_count = x86_FLOAT_STATE32_COUNT;
  219.           kern_return_t ret;

  220.           ret = thread_get_state
  221.             (current_thread, x86_FLOAT_STATE32, (thread_state_t) & fp_regs,
  222.              &fp_count);
  223.           MACH_CHECK_ERROR (ret);

  224.           i387_collect_fxsave (regcache, regno, &fp_regs.__fpu_fcw);

  225.           ret = thread_set_state (current_thread, x86_FLOAT_STATE32,
  226.                                   (thread_state_t) &fp_regs,
  227.                                   x86_FLOAT_STATE32_COUNT);
  228.           MACH_CHECK_ERROR (ret);
  229.         }
  230.     }
  231. }

  232. /* Support for debug registers, boosted mostly from i386-linux-nat.c.  */

  233. static void
  234. i386_darwin_dr_set (int regnum, CORE_ADDR value)
  235. {
  236.   int current_pid;
  237.   thread_t current_thread;
  238.   x86_debug_state_t dr_regs;
  239.   kern_return_t ret;
  240.   unsigned int dr_count;

  241.   gdb_assert (regnum >= 0 && regnum <= DR_CONTROL);

  242.   current_thread = ptid_get_tid (inferior_ptid);

  243.   dr_regs.dsh.flavor = x86_DEBUG_STATE;
  244.   dr_regs.dsh.count = x86_DEBUG_STATE_COUNT;
  245.   dr_count = x86_DEBUG_STATE_COUNT;
  246.   ret = thread_get_state (current_thread, x86_DEBUG_STATE,
  247.                           (thread_state_t) &dr_regs, &dr_count);
  248.   MACH_CHECK_ERROR (ret);

  249.   switch (dr_regs.dsh.flavor)
  250.     {
  251.     case x86_DEBUG_STATE32:
  252.       switch (regnum)
  253.         {
  254.         case 0:
  255.           dr_regs.uds.ds32.__dr0 = value;
  256.           break;
  257.         case 1:
  258.           dr_regs.uds.ds32.__dr1 = value;
  259.           break;
  260.         case 2:
  261.           dr_regs.uds.ds32.__dr2 = value;
  262.           break;
  263.         case 3:
  264.           dr_regs.uds.ds32.__dr3 = value;
  265.           break;
  266.         case 4:
  267.           dr_regs.uds.ds32.__dr4 = value;
  268.           break;
  269.         case 5:
  270.           dr_regs.uds.ds32.__dr5 = value;
  271.           break;
  272.         case 6:
  273.           dr_regs.uds.ds32.__dr6 = value;
  274.           break;
  275.         case 7:
  276.           dr_regs.uds.ds32.__dr7 = value;
  277.           break;
  278.         }
  279.       break;
  280. #ifdef BFD64
  281.     case x86_DEBUG_STATE64:
  282.       switch (regnum)
  283.         {
  284.         case 0:
  285.           dr_regs.uds.ds64.__dr0 = value;
  286.           break;
  287.         case 1:
  288.           dr_regs.uds.ds64.__dr1 = value;
  289.           break;
  290.         case 2:
  291.           dr_regs.uds.ds64.__dr2 = value;
  292.           break;
  293.         case 3:
  294.           dr_regs.uds.ds64.__dr3 = value;
  295.           break;
  296.         case 4:
  297.           dr_regs.uds.ds64.__dr4 = value;
  298.           break;
  299.         case 5:
  300.           dr_regs.uds.ds64.__dr5 = value;
  301.           break;
  302.         case 6:
  303.           dr_regs.uds.ds64.__dr6 = value;
  304.           break;
  305.         case 7:
  306.           dr_regs.uds.ds64.__dr7 = value;
  307.           break;
  308.         }
  309.       break;
  310. #endif
  311.     }

  312.   ret = thread_set_state (current_thread, dr_regs.dsh.flavor,
  313.                           (thread_state_t) &dr_regs.uds, dr_count);

  314.   MACH_CHECK_ERROR (ret);
  315. }

  316. static CORE_ADDR
  317. i386_darwin_dr_get (int regnum)
  318. {
  319.   thread_t current_thread;
  320.   x86_debug_state_t dr_regs;
  321.   kern_return_t ret;
  322.   unsigned int dr_count;

  323.   gdb_assert (regnum >= 0 && regnum <= DR_CONTROL);

  324.   current_thread = ptid_get_tid (inferior_ptid);

  325.   dr_regs.dsh.flavor = x86_DEBUG_STATE;
  326.   dr_regs.dsh.count = x86_DEBUG_STATE_COUNT;
  327.   dr_count = x86_DEBUG_STATE_COUNT;
  328.   ret = thread_get_state (current_thread, x86_DEBUG_STATE,
  329.                           (thread_state_t) &dr_regs, &dr_count);
  330.   MACH_CHECK_ERROR (ret);

  331.   switch (dr_regs.dsh.flavor)
  332.     {
  333.     case x86_DEBUG_STATE32:
  334.       switch (regnum)
  335.         {
  336.         case 0:
  337.           return dr_regs.uds.ds32.__dr0;
  338.         case 1:
  339.           return dr_regs.uds.ds32.__dr1;
  340.         case 2:
  341.           return dr_regs.uds.ds32.__dr2;
  342.         case 3:
  343.           return dr_regs.uds.ds32.__dr3;
  344.         case 4:
  345.           return dr_regs.uds.ds32.__dr4;
  346.         case 5:
  347.           return dr_regs.uds.ds32.__dr5;
  348.         case 6:
  349.           return dr_regs.uds.ds32.__dr6;
  350.         case 7:
  351.           return dr_regs.uds.ds32.__dr7;
  352.         default:
  353.           return -1;
  354.         }
  355.       break;
  356. #ifdef BFD64
  357.     case x86_DEBUG_STATE64:
  358.       switch (regnum)
  359.         {
  360.         case 0:
  361.           return dr_regs.uds.ds64.__dr0;
  362.         case 1:
  363.           return dr_regs.uds.ds64.__dr1;
  364.         case 2:
  365.           return dr_regs.uds.ds64.__dr2;
  366.         case 3:
  367.           return dr_regs.uds.ds64.__dr3;
  368.         case 4:
  369.           return dr_regs.uds.ds64.__dr4;
  370.         case 5:
  371.           return dr_regs.uds.ds64.__dr5;
  372.         case 6:
  373.           return dr_regs.uds.ds64.__dr6;
  374.         case 7:
  375.           return dr_regs.uds.ds64.__dr7;
  376.         default:
  377.           return -1;
  378.         }
  379.       break;
  380. #endif
  381.     default:
  382.       return -1;
  383.     }
  384. }

  385. static void
  386. i386_darwin_dr_set_control (unsigned long control)
  387. {
  388.   i386_darwin_dr_set (DR_CONTROL, control);
  389. }

  390. static void
  391. i386_darwin_dr_set_addr (int regnum, CORE_ADDR addr)
  392. {
  393.   gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);

  394.   i386_darwin_dr_set (DR_FIRSTADDR + regnum, addr);
  395. }

  396. static CORE_ADDR
  397. i386_darwin_dr_get_addr (int regnum)
  398. {
  399.   return i386_darwin_dr_get (regnum);
  400. }

  401. static unsigned long
  402. i386_darwin_dr_get_status (void)
  403. {
  404.   return i386_darwin_dr_get (DR_STATUS);
  405. }

  406. static unsigned long
  407. i386_darwin_dr_get_control (void)
  408. {
  409.   return i386_darwin_dr_get (DR_CONTROL);
  410. }

  411. void
  412. darwin_check_osabi (darwin_inferior *inf, thread_t thread)
  413. {
  414.   if (gdbarch_osabi (target_gdbarch ()) == GDB_OSABI_UNKNOWN)
  415.     {
  416.       /* Attaching to a process.  Let's figure out what kind it is.  */
  417.       x86_thread_state_t gp_regs;
  418.       struct gdbarch_info info;
  419.       unsigned int gp_count = x86_THREAD_STATE_COUNT;
  420.       kern_return_t ret;

  421.       ret = thread_get_state (thread, x86_THREAD_STATE,
  422.                               (thread_state_t) &gp_regs, &gp_count);
  423.       if (ret != KERN_SUCCESS)
  424.         {
  425.           MACH_CHECK_ERROR (ret);
  426.           return;
  427.         }

  428.       gdbarch_info_init (&info);
  429.       gdbarch_info_fill (&info);
  430.       info.byte_order = gdbarch_byte_order (target_gdbarch ());
  431.       info.osabi = GDB_OSABI_DARWIN;
  432.       if (gp_regs.tsh.flavor == x86_THREAD_STATE64)
  433.         info.bfd_arch_info = bfd_lookup_arch (bfd_arch_i386,
  434.                                               bfd_mach_x86_64);
  435.       else
  436.         info.bfd_arch_info = bfd_lookup_arch (bfd_arch_i386,
  437.                                               bfd_mach_i386_i386);
  438.       gdbarch_update_p (info);
  439.     }
  440. }

  441. #define X86_EFLAGS_T 0x100UL

  442. /* Returning from a signal trampoline is done by calling a
  443.    special system call (sigreturn).  This system call
  444.    restores the registers that were saved when the signal was
  445.    raised, including %eflags/%rflags.  That means that single-stepping
  446.    won't work.  Instead, we'll have to modify the signal context
  447.    that's about to be restored, and set the trace flag there.  */

  448. static int
  449. i386_darwin_sstep_at_sigreturn (x86_thread_state_t *regs)
  450. {
  451.   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  452.   static const gdb_byte darwin_syscall[] = { 0xcd, 0x80 }; /* int 0x80 */
  453.   gdb_byte buf[sizeof (darwin_syscall)];

  454.   /* Check if PC is at a sigreturn system call.  */
  455.   if (target_read_memory (regs->uts.ts32.__eip, buf, sizeof (buf)) == 0
  456.       && memcmp (buf, darwin_syscall, sizeof (darwin_syscall)) == 0
  457.       && regs->uts.ts32.__eax == 0xb8 /* SYS_sigreturn */)
  458.     {
  459.       ULONGEST uctx_addr;
  460.       ULONGEST mctx_addr;
  461.       ULONGEST flags_addr;
  462.       unsigned int eflags;

  463.       uctx_addr = read_memory_unsigned_integer
  464.                     (regs->uts.ts32.__esp + 4, 4, byte_order);
  465.       mctx_addr = read_memory_unsigned_integer
  466.                     (uctx_addr + 28, 4, byte_order);

  467.       flags_addr = mctx_addr + 12 + 9 * 4;
  468.       read_memory (flags_addr, (gdb_byte *) &eflags, 4);
  469.       eflags |= X86_EFLAGS_T;
  470.       write_memory (flags_addr, (gdb_byte *) &eflags, 4);

  471.       return 1;
  472.     }
  473.   return 0;
  474. }

  475. #ifdef BFD64
  476. static int
  477. amd64_darwin_sstep_at_sigreturn (x86_thread_state_t *regs)
  478. {
  479.   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  480.   static const gdb_byte darwin_syscall[] = { 0x0f, 0x05 }; /* syscall */
  481.   gdb_byte buf[sizeof (darwin_syscall)];

  482.   /* Check if PC is at a sigreturn system call.  */
  483.   if (target_read_memory (regs->uts.ts64.__rip, buf, sizeof (buf)) == 0
  484.       && memcmp (buf, darwin_syscall, sizeof (darwin_syscall)) == 0
  485.       && (regs->uts.ts64.__rax & 0xffffffff) == 0x20000b8 /* SYS_sigreturn */)
  486.     {
  487.       ULONGEST mctx_addr;
  488.       ULONGEST flags_addr;
  489.       unsigned int rflags;

  490.       mctx_addr = read_memory_unsigned_integer
  491.                     (regs->uts.ts64.__rdi + 48, 8, byte_order);
  492.       flags_addr = mctx_addr + 16 + 17 * 8;

  493.       /* AMD64 is little endian.  */
  494.       read_memory (flags_addr, (gdb_byte *) &rflags, 4);
  495.       rflags |= X86_EFLAGS_T;
  496.       write_memory (flags_addr, (gdb_byte *) &rflags, 4);

  497.       return 1;
  498.     }
  499.   return 0;
  500. }
  501. #endif

  502. void
  503. darwin_set_sstep (thread_t thread, int enable)
  504. {
  505.   x86_thread_state_t regs;
  506.   unsigned int count = x86_THREAD_STATE_COUNT;
  507.   kern_return_t kret;

  508.   kret = thread_get_state (thread, x86_THREAD_STATE,
  509.                            (thread_state_t) &regs, &count);
  510.   if (kret != KERN_SUCCESS)
  511.     {
  512.       printf_unfiltered (_("darwin_set_sstep: error %x, thread=%x\n"),
  513.                          kret, thread);
  514.       return;
  515.     }

  516.   switch (regs.tsh.flavor)
  517.     {
  518.     case x86_THREAD_STATE32:
  519.       {
  520.         __uint32_t bit = enable ? X86_EFLAGS_T : 0;

  521.         if (enable && i386_darwin_sstep_at_sigreturn (&regs))
  522.           return;
  523.         if ((regs.uts.ts32.__eflags & X86_EFLAGS_T) == bit)
  524.           return;
  525.         regs.uts.ts32.__eflags
  526.           = (regs.uts.ts32.__eflags & ~X86_EFLAGS_T) | bit;
  527.         kret = thread_set_state (thread, x86_THREAD_STATE,
  528.                                  (thread_state_t) &regs, count);
  529.         MACH_CHECK_ERROR (kret);
  530.       }
  531.       break;
  532. #ifdef BFD64
  533.     case x86_THREAD_STATE64:
  534.       {
  535.         __uint64_t bit = enable ? X86_EFLAGS_T : 0;

  536.         if (enable && amd64_darwin_sstep_at_sigreturn (&regs))
  537.           return;
  538.         if ((regs.uts.ts64.__rflags & X86_EFLAGS_T) == bit)
  539.           return;
  540.         regs.uts.ts64.__rflags
  541.           = (regs.uts.ts64.__rflags & ~X86_EFLAGS_T) | bit;
  542.         kret = thread_set_state (thread, x86_THREAD_STATE,
  543.                                  (thread_state_t) &regs, count);
  544.         MACH_CHECK_ERROR (kret);
  545.       }
  546.       break;
  547. #endif
  548.     default:
  549.       error (_("darwin_set_sstep: unknown flavour: %d"), regs.tsh.flavor);
  550.     }
  551. }

  552. void
  553. darwin_complete_target (struct target_ops *target)
  554. {
  555. #ifdef BFD64
  556.   amd64_native_gregset64_reg_offset = amd64_darwin_thread_state_reg_offset;
  557.   amd64_native_gregset64_num_regs = amd64_darwin_thread_state_num_regs;
  558.   amd64_native_gregset32_reg_offset = i386_darwin_thread_state_reg_offset;
  559.   amd64_native_gregset32_num_regs = i386_darwin_thread_state_num_regs;
  560. #endif

  561.   x86_use_watchpoints (target);

  562.   x86_dr_low.set_control = i386_darwin_dr_set_control;
  563.   x86_dr_low.set_addr = i386_darwin_dr_set_addr;
  564.   x86_dr_low.get_addr = i386_darwin_dr_get_addr;
  565.   x86_dr_low.get_status = i386_darwin_dr_get_status;
  566.   x86_dr_low.get_control = i386_darwin_dr_get_control;

  567.   /* Let's assume that the kernel is 64 bits iff the executable is.  */
  568. #ifdef __x86_64__
  569.   x86_set_debug_register_length (8);
  570. #else
  571.   x86_set_debug_register_length (4);
  572. #endif

  573.   target->to_fetch_registers = i386_darwin_fetch_inferior_registers;
  574.   target->to_store_registers = i386_darwin_store_inferior_registers;
  575. }