i386-darwin-nat.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* Darwin support for GDB, the GNU debugger.
  2. Copyright (C) 1997-2022 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. struct i386_darwin_nat_target final : public x86_nat_target<darwin_nat_target>
  38. {
  39. /* Add our register access methods. */
  40. void fetch_registers (struct regcache *, int) override;
  41. void store_registers (struct regcache *, int) override;
  42. };
  43. static struct i386_darwin_nat_target darwin_target;
  44. /* Read register values from the inferior process.
  45. If REGNO is -1, do this for all registers.
  46. Otherwise, REGNO specifies which register (so we can save time). */
  47. void
  48. i386_darwin_nat_target::fetch_registers (struct regcache *regcache, int regno)
  49. {
  50. thread_t current_thread = regcache->ptid ().tid ();
  51. int fetched = 0;
  52. struct gdbarch *gdbarch = regcache->arch ();
  53. #ifdef BFD64
  54. if (gdbarch_ptr_bit (gdbarch) == 64)
  55. {
  56. if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno))
  57. {
  58. x86_thread_state_t gp_regs;
  59. unsigned int gp_count = x86_THREAD_STATE_COUNT;
  60. kern_return_t ret;
  61. ret = thread_get_state
  62. (current_thread, x86_THREAD_STATE, (thread_state_t) & gp_regs,
  63. &gp_count);
  64. if (ret != KERN_SUCCESS)
  65. {
  66. warning (_("Error calling thread_get_state for "
  67. "GP registers for thread 0x%lx\n"),
  68. (unsigned long) current_thread);
  69. MACH_CHECK_ERROR (ret);
  70. }
  71. /* Some kernels don't sanitize the values. */
  72. gp_regs.uts.ts64.__fs &= 0xffff;
  73. gp_regs.uts.ts64.__gs &= 0xffff;
  74. amd64_supply_native_gregset (regcache, &gp_regs.uts, -1);
  75. fetched++;
  76. }
  77. if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno))
  78. {
  79. x86_float_state_t fp_regs;
  80. unsigned int fp_count = x86_FLOAT_STATE_COUNT;
  81. kern_return_t ret;
  82. ret = thread_get_state
  83. (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs,
  84. &fp_count);
  85. if (ret != KERN_SUCCESS)
  86. {
  87. warning (_("Error calling thread_get_state for "
  88. "float registers for thread 0x%lx\n"),
  89. (unsigned long) current_thread);
  90. MACH_CHECK_ERROR (ret);
  91. }
  92. amd64_supply_fxsave (regcache, -1, &fp_regs.ufs.fs64.__fpu_fcw);
  93. fetched++;
  94. }
  95. }
  96. else
  97. #endif
  98. {
  99. if (regno == -1 || regno < I386_NUM_GREGS)
  100. {
  101. x86_thread_state32_t gp_regs;
  102. unsigned int gp_count = x86_THREAD_STATE32_COUNT;
  103. kern_return_t ret;
  104. int i;
  105. ret = thread_get_state
  106. (current_thread, x86_THREAD_STATE32, (thread_state_t) &gp_regs,
  107. &gp_count);
  108. if (ret != KERN_SUCCESS)
  109. {
  110. warning (_("Error calling thread_get_state for "
  111. "GP registers for thread 0x%lx\n"),
  112. (unsigned long) current_thread);
  113. MACH_CHECK_ERROR (ret);
  114. }
  115. for (i = 0; i < I386_NUM_GREGS; i++)
  116. regcache->raw_supply
  117. (i, (char *) &gp_regs + i386_darwin_thread_state_reg_offset[i]);
  118. fetched++;
  119. }
  120. if (regno == -1
  121. || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS))
  122. {
  123. x86_float_state32_t fp_regs;
  124. unsigned int fp_count = x86_FLOAT_STATE32_COUNT;
  125. kern_return_t ret;
  126. ret = thread_get_state
  127. (current_thread, x86_FLOAT_STATE32, (thread_state_t) &fp_regs,
  128. &fp_count);
  129. if (ret != KERN_SUCCESS)
  130. {
  131. warning (_("Error calling thread_get_state for "
  132. "float registers for thread 0x%lx\n"),
  133. (unsigned long) current_thread);
  134. MACH_CHECK_ERROR (ret);
  135. }
  136. i387_supply_fxsave (regcache, -1, &fp_regs.__fpu_fcw);
  137. fetched++;
  138. }
  139. }
  140. if (! fetched)
  141. {
  142. warning (_("unknown register %d"), regno);
  143. regcache->raw_supply (regno, NULL);
  144. }
  145. }
  146. /* Store our register values back into the inferior.
  147. If REGNO is -1, do this for all registers.
  148. Otherwise, REGNO specifies which register (so we can save time). */
  149. void
  150. i386_darwin_nat_target::store_registers (struct regcache *regcache,
  151. int regno)
  152. {
  153. thread_t current_thread = regcache->ptid ().tid ();
  154. struct gdbarch *gdbarch = regcache->arch ();
  155. #ifdef BFD64
  156. if (gdbarch_ptr_bit (gdbarch) == 64)
  157. {
  158. if (regno == -1 || amd64_native_gregset_supplies_p (gdbarch, regno))
  159. {
  160. x86_thread_state_t gp_regs;
  161. kern_return_t ret;
  162. unsigned int gp_count = x86_THREAD_STATE_COUNT;
  163. ret = thread_get_state
  164. (current_thread, x86_THREAD_STATE, (thread_state_t) &gp_regs,
  165. &gp_count);
  166. MACH_CHECK_ERROR (ret);
  167. gdb_assert (gp_regs.tsh.flavor == x86_THREAD_STATE64);
  168. gdb_assert (gp_regs.tsh.count == x86_THREAD_STATE64_COUNT);
  169. amd64_collect_native_gregset (regcache, &gp_regs.uts, regno);
  170. /* Some kernels don't sanitize the values. */
  171. gp_regs.uts.ts64.__fs &= 0xffff;
  172. gp_regs.uts.ts64.__gs &= 0xffff;
  173. ret = thread_set_state (current_thread, x86_THREAD_STATE,
  174. (thread_state_t) &gp_regs,
  175. x86_THREAD_STATE_COUNT);
  176. MACH_CHECK_ERROR (ret);
  177. }
  178. if (regno == -1 || !amd64_native_gregset_supplies_p (gdbarch, regno))
  179. {
  180. x86_float_state_t fp_regs;
  181. kern_return_t ret;
  182. unsigned int fp_count = x86_FLOAT_STATE_COUNT;
  183. ret = thread_get_state
  184. (current_thread, x86_FLOAT_STATE, (thread_state_t) & fp_regs,
  185. &fp_count);
  186. MACH_CHECK_ERROR (ret);
  187. gdb_assert (fp_regs.fsh.flavor == x86_FLOAT_STATE64);
  188. gdb_assert (fp_regs.fsh.count == x86_FLOAT_STATE64_COUNT);
  189. amd64_collect_fxsave (regcache, regno, &fp_regs.ufs.fs64.__fpu_fcw);
  190. ret = thread_set_state (current_thread, x86_FLOAT_STATE,
  191. (thread_state_t) & fp_regs,
  192. x86_FLOAT_STATE_COUNT);
  193. MACH_CHECK_ERROR (ret);
  194. }
  195. }
  196. else
  197. #endif
  198. {
  199. if (regno == -1 || regno < I386_NUM_GREGS)
  200. {
  201. x86_thread_state32_t gp_regs;
  202. kern_return_t ret;
  203. unsigned int gp_count = x86_THREAD_STATE32_COUNT;
  204. int i;
  205. ret = thread_get_state
  206. (current_thread, x86_THREAD_STATE32, (thread_state_t) &gp_regs,
  207. &gp_count);
  208. MACH_CHECK_ERROR (ret);
  209. for (i = 0; i < I386_NUM_GREGS; i++)
  210. if (regno == -1 || regno == i)
  211. regcache->raw_collect
  212. (i, (char *) &gp_regs + i386_darwin_thread_state_reg_offset[i]);
  213. ret = thread_set_state (current_thread, x86_THREAD_STATE32,
  214. (thread_state_t) &gp_regs,
  215. x86_THREAD_STATE32_COUNT);
  216. MACH_CHECK_ERROR (ret);
  217. }
  218. if (regno == -1
  219. || (regno >= I386_ST0_REGNUM && regno < I386_SSE_NUM_REGS))
  220. {
  221. x86_float_state32_t fp_regs;
  222. unsigned int fp_count = x86_FLOAT_STATE32_COUNT;
  223. kern_return_t ret;
  224. ret = thread_get_state
  225. (current_thread, x86_FLOAT_STATE32, (thread_state_t) & fp_regs,
  226. &fp_count);
  227. MACH_CHECK_ERROR (ret);
  228. i387_collect_fxsave (regcache, regno, &fp_regs.__fpu_fcw);
  229. ret = thread_set_state (current_thread, x86_FLOAT_STATE32,
  230. (thread_state_t) &fp_regs,
  231. x86_FLOAT_STATE32_COUNT);
  232. MACH_CHECK_ERROR (ret);
  233. }
  234. }
  235. }
  236. /* Support for debug registers, boosted mostly from i386-linux-nat.c. */
  237. static void
  238. i386_darwin_dr_set (int regnum, CORE_ADDR value)
  239. {
  240. thread_t current_thread;
  241. x86_debug_state_t dr_regs;
  242. kern_return_t ret;
  243. unsigned int dr_count;
  244. gdb_assert (regnum >= 0 && regnum <= DR_CONTROL);
  245. current_thread = inferior_ptid.tid ();
  246. dr_regs.dsh.flavor = x86_DEBUG_STATE;
  247. dr_regs.dsh.count = x86_DEBUG_STATE_COUNT;
  248. dr_count = x86_DEBUG_STATE_COUNT;
  249. ret = thread_get_state (current_thread, x86_DEBUG_STATE,
  250. (thread_state_t) &dr_regs, &dr_count);
  251. MACH_CHECK_ERROR (ret);
  252. switch (dr_regs.dsh.flavor)
  253. {
  254. case x86_DEBUG_STATE32:
  255. switch (regnum)
  256. {
  257. case 0:
  258. dr_regs.uds.ds32.__dr0 = value;
  259. break;
  260. case 1:
  261. dr_regs.uds.ds32.__dr1 = value;
  262. break;
  263. case 2:
  264. dr_regs.uds.ds32.__dr2 = value;
  265. break;
  266. case 3:
  267. dr_regs.uds.ds32.__dr3 = value;
  268. break;
  269. case 4:
  270. dr_regs.uds.ds32.__dr4 = value;
  271. break;
  272. case 5:
  273. dr_regs.uds.ds32.__dr5 = value;
  274. break;
  275. case 6:
  276. dr_regs.uds.ds32.__dr6 = value;
  277. break;
  278. case 7:
  279. dr_regs.uds.ds32.__dr7 = value;
  280. break;
  281. }
  282. break;
  283. #ifdef BFD64
  284. case x86_DEBUG_STATE64:
  285. switch (regnum)
  286. {
  287. case 0:
  288. dr_regs.uds.ds64.__dr0 = value;
  289. break;
  290. case 1:
  291. dr_regs.uds.ds64.__dr1 = value;
  292. break;
  293. case 2:
  294. dr_regs.uds.ds64.__dr2 = value;
  295. break;
  296. case 3:
  297. dr_regs.uds.ds64.__dr3 = value;
  298. break;
  299. case 4:
  300. dr_regs.uds.ds64.__dr4 = value;
  301. break;
  302. case 5:
  303. dr_regs.uds.ds64.__dr5 = value;
  304. break;
  305. case 6:
  306. dr_regs.uds.ds64.__dr6 = value;
  307. break;
  308. case 7:
  309. dr_regs.uds.ds64.__dr7 = value;
  310. break;
  311. }
  312. break;
  313. #endif
  314. }
  315. ret = thread_set_state (current_thread, dr_regs.dsh.flavor,
  316. (thread_state_t) &dr_regs.uds, dr_count);
  317. MACH_CHECK_ERROR (ret);
  318. }
  319. static CORE_ADDR
  320. i386_darwin_dr_get (int regnum)
  321. {
  322. thread_t current_thread;
  323. x86_debug_state_t dr_regs;
  324. kern_return_t ret;
  325. unsigned int dr_count;
  326. gdb_assert (regnum >= 0 && regnum <= DR_CONTROL);
  327. current_thread = inferior_ptid.tid ();
  328. dr_regs.dsh.flavor = x86_DEBUG_STATE;
  329. dr_regs.dsh.count = x86_DEBUG_STATE_COUNT;
  330. dr_count = x86_DEBUG_STATE_COUNT;
  331. ret = thread_get_state (current_thread, x86_DEBUG_STATE,
  332. (thread_state_t) &dr_regs, &dr_count);
  333. MACH_CHECK_ERROR (ret);
  334. switch (dr_regs.dsh.flavor)
  335. {
  336. case x86_DEBUG_STATE32:
  337. switch (regnum)
  338. {
  339. case 0:
  340. return dr_regs.uds.ds32.__dr0;
  341. case 1:
  342. return dr_regs.uds.ds32.__dr1;
  343. case 2:
  344. return dr_regs.uds.ds32.__dr2;
  345. case 3:
  346. return dr_regs.uds.ds32.__dr3;
  347. case 4:
  348. return dr_regs.uds.ds32.__dr4;
  349. case 5:
  350. return dr_regs.uds.ds32.__dr5;
  351. case 6:
  352. return dr_regs.uds.ds32.__dr6;
  353. case 7:
  354. return dr_regs.uds.ds32.__dr7;
  355. default:
  356. return -1;
  357. }
  358. break;
  359. #ifdef BFD64
  360. case x86_DEBUG_STATE64:
  361. switch (regnum)
  362. {
  363. case 0:
  364. return dr_regs.uds.ds64.__dr0;
  365. case 1:
  366. return dr_regs.uds.ds64.__dr1;
  367. case 2:
  368. return dr_regs.uds.ds64.__dr2;
  369. case 3:
  370. return dr_regs.uds.ds64.__dr3;
  371. case 4:
  372. return dr_regs.uds.ds64.__dr4;
  373. case 5:
  374. return dr_regs.uds.ds64.__dr5;
  375. case 6:
  376. return dr_regs.uds.ds64.__dr6;
  377. case 7:
  378. return dr_regs.uds.ds64.__dr7;
  379. default:
  380. return -1;
  381. }
  382. break;
  383. #endif
  384. default:
  385. return -1;
  386. }
  387. }
  388. static void
  389. i386_darwin_dr_set_control (unsigned long control)
  390. {
  391. i386_darwin_dr_set (DR_CONTROL, control);
  392. }
  393. static void
  394. i386_darwin_dr_set_addr (int regnum, CORE_ADDR addr)
  395. {
  396. gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
  397. i386_darwin_dr_set (DR_FIRSTADDR + regnum, addr);
  398. }
  399. static CORE_ADDR
  400. i386_darwin_dr_get_addr (int regnum)
  401. {
  402. return i386_darwin_dr_get (regnum);
  403. }
  404. static unsigned long
  405. i386_darwin_dr_get_status (void)
  406. {
  407. return i386_darwin_dr_get (DR_STATUS);
  408. }
  409. static unsigned long
  410. i386_darwin_dr_get_control (void)
  411. {
  412. return i386_darwin_dr_get (DR_CONTROL);
  413. }
  414. void
  415. darwin_check_osabi (darwin_inferior *inf, thread_t thread)
  416. {
  417. if (gdbarch_osabi (target_gdbarch ()) == GDB_OSABI_UNKNOWN)
  418. {
  419. /* Attaching to a process. Let's figure out what kind it is. */
  420. x86_thread_state_t gp_regs;
  421. unsigned int gp_count = x86_THREAD_STATE_COUNT;
  422. kern_return_t ret;
  423. ret = thread_get_state (thread, x86_THREAD_STATE,
  424. (thread_state_t) &gp_regs, &gp_count);
  425. if (ret != KERN_SUCCESS)
  426. {
  427. MACH_CHECK_ERROR (ret);
  428. return;
  429. }
  430. gdbarch_info info;
  431. gdbarch_info_fill (&info);
  432. info.byte_order = gdbarch_byte_order (target_gdbarch ());
  433. info.osabi = GDB_OSABI_DARWIN;
  434. if (gp_regs.tsh.flavor == x86_THREAD_STATE64)
  435. info.bfd_arch_info = bfd_lookup_arch (bfd_arch_i386,
  436. bfd_mach_x86_64);
  437. else
  438. info.bfd_arch_info = bfd_lookup_arch (bfd_arch_i386,
  439. bfd_mach_i386_i386);
  440. gdbarch_update_p (info);
  441. }
  442. }
  443. #define X86_EFLAGS_T 0x100UL
  444. /* Returning from a signal trampoline is done by calling a
  445. special system call (sigreturn). This system call
  446. restores the registers that were saved when the signal was
  447. raised, including %eflags/%rflags. That means that single-stepping
  448. won't work. Instead, we'll have to modify the signal context
  449. that's about to be restored, and set the trace flag there. */
  450. static int
  451. i386_darwin_sstep_at_sigreturn (x86_thread_state_t *regs)
  452. {
  453. enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  454. static const gdb_byte darwin_syscall[] = { 0xcd, 0x80 }; /* int 0x80 */
  455. gdb_byte buf[sizeof (darwin_syscall)];
  456. /* Check if PC is at a sigreturn system call. */
  457. if (target_read_memory (regs->uts.ts32.__eip, buf, sizeof (buf)) == 0
  458. && memcmp (buf, darwin_syscall, sizeof (darwin_syscall)) == 0
  459. && regs->uts.ts32.__eax == 0xb8 /* SYS_sigreturn */)
  460. {
  461. ULONGEST uctx_addr;
  462. ULONGEST mctx_addr;
  463. ULONGEST flags_addr;
  464. unsigned int eflags;
  465. uctx_addr = read_memory_unsigned_integer
  466. (regs->uts.ts32.__esp + 4, 4, byte_order);
  467. mctx_addr = read_memory_unsigned_integer
  468. (uctx_addr + 28, 4, byte_order);
  469. flags_addr = mctx_addr + 12 + 9 * 4;
  470. read_memory (flags_addr, (gdb_byte *) &eflags, 4);
  471. eflags |= X86_EFLAGS_T;
  472. write_memory (flags_addr, (gdb_byte *) &eflags, 4);
  473. return 1;
  474. }
  475. return 0;
  476. }
  477. #ifdef BFD64
  478. static int
  479. amd64_darwin_sstep_at_sigreturn (x86_thread_state_t *regs)
  480. {
  481. enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  482. static const gdb_byte darwin_syscall[] = { 0x0f, 0x05 }; /* syscall */
  483. gdb_byte buf[sizeof (darwin_syscall)];
  484. /* Check if PC is at a sigreturn system call. */
  485. if (target_read_memory (regs->uts.ts64.__rip, buf, sizeof (buf)) == 0
  486. && memcmp (buf, darwin_syscall, sizeof (darwin_syscall)) == 0
  487. && (regs->uts.ts64.__rax & 0xffffffff) == 0x20000b8 /* SYS_sigreturn */)
  488. {
  489. ULONGEST mctx_addr;
  490. ULONGEST flags_addr;
  491. unsigned int rflags;
  492. mctx_addr = read_memory_unsigned_integer
  493. (regs->uts.ts64.__rdi + 48, 8, byte_order);
  494. flags_addr = mctx_addr + 16 + 17 * 8;
  495. /* AMD64 is little endian. */
  496. read_memory (flags_addr, (gdb_byte *) &rflags, 4);
  497. rflags |= X86_EFLAGS_T;
  498. write_memory (flags_addr, (gdb_byte *) &rflags, 4);
  499. return 1;
  500. }
  501. return 0;
  502. }
  503. #endif
  504. void
  505. darwin_set_sstep (thread_t thread, int enable)
  506. {
  507. x86_thread_state_t regs;
  508. unsigned int count = x86_THREAD_STATE_COUNT;
  509. kern_return_t kret;
  510. kret = thread_get_state (thread, x86_THREAD_STATE,
  511. (thread_state_t) &regs, &count);
  512. if (kret != KERN_SUCCESS)
  513. {
  514. warning (_("darwin_set_sstep: error %x, thread=%x\n"),
  515. kret, thread);
  516. return;
  517. }
  518. switch (regs.tsh.flavor)
  519. {
  520. case x86_THREAD_STATE32:
  521. {
  522. __uint32_t bit = enable ? X86_EFLAGS_T : 0;
  523. if (enable && i386_darwin_sstep_at_sigreturn (&regs))
  524. return;
  525. if ((regs.uts.ts32.__eflags & X86_EFLAGS_T) == bit)
  526. return;
  527. regs.uts.ts32.__eflags
  528. = (regs.uts.ts32.__eflags & ~X86_EFLAGS_T) | bit;
  529. kret = thread_set_state (thread, x86_THREAD_STATE,
  530. (thread_state_t) &regs, count);
  531. MACH_CHECK_ERROR (kret);
  532. }
  533. break;
  534. #ifdef BFD64
  535. case x86_THREAD_STATE64:
  536. {
  537. __uint64_t bit = enable ? X86_EFLAGS_T : 0;
  538. if (enable && amd64_darwin_sstep_at_sigreturn (&regs))
  539. return;
  540. if ((regs.uts.ts64.__rflags & X86_EFLAGS_T) == bit)
  541. return;
  542. regs.uts.ts64.__rflags
  543. = (regs.uts.ts64.__rflags & ~X86_EFLAGS_T) | bit;
  544. kret = thread_set_state (thread, x86_THREAD_STATE,
  545. (thread_state_t) &regs, count);
  546. MACH_CHECK_ERROR (kret);
  547. }
  548. break;
  549. #endif
  550. default:
  551. error (_("darwin_set_sstep: unknown flavour: %d"), regs.tsh.flavor);
  552. }
  553. }
  554. void _initialize_i386_darwin_nat ();
  555. void
  556. _initialize_i386_darwin_nat ()
  557. {
  558. #ifdef BFD64
  559. amd64_native_gregset64_reg_offset = amd64_darwin_thread_state_reg_offset;
  560. amd64_native_gregset64_num_regs = amd64_darwin_thread_state_num_regs;
  561. amd64_native_gregset32_reg_offset = i386_darwin_thread_state_reg_offset;
  562. amd64_native_gregset32_num_regs = i386_darwin_thread_state_num_regs;
  563. #endif
  564. x86_dr_low.set_control = i386_darwin_dr_set_control;
  565. x86_dr_low.set_addr = i386_darwin_dr_set_addr;
  566. x86_dr_low.get_addr = i386_darwin_dr_get_addr;
  567. x86_dr_low.get_status = i386_darwin_dr_get_status;
  568. x86_dr_low.get_control = i386_darwin_dr_get_control;
  569. /* Let's assume that the kernel is 64 bits iff the executable is. */
  570. #ifdef __x86_64__
  571. x86_set_debug_register_length (8);
  572. #else
  573. x86_set_debug_register_length (4);
  574. #endif
  575. add_inf_child_target (&darwin_target);
  576. }