i386-linux-nat.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /* Native-dependent code for GNU/Linux i386.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "inferior.h"
  16. #include "gdbcore.h"
  17. #include "regcache.h"
  18. #include "elf/common.h"
  19. #include "nat/gdb_ptrace.h"
  20. #include <sys/uio.h>
  21. #include "gregset.h"
  22. #include "gdb_proc_service.h"
  23. #include "i386-linux-nat.h"
  24. #include "i387-tdep.h"
  25. #include "i386-tdep.h"
  26. #include "i386-linux-tdep.h"
  27. #include "gdbsupport/x86-xstate.h"
  28. #include "x86-linux-nat.h"
  29. #include "nat/linux-ptrace.h"
  30. #include "inf-ptrace.h"
  31. struct i386_linux_nat_target final : public x86_linux_nat_target
  32. {
  33. /* Add our register access methods. */
  34. void fetch_registers (struct regcache *, int) override;
  35. void store_registers (struct regcache *, int) override;
  36. /* Override the default ptrace resume method. */
  37. void low_resume (ptid_t ptid, int step, enum gdb_signal sig) override;
  38. };
  39. static i386_linux_nat_target the_i386_linux_nat_target;
  40. /* The register sets used in GNU/Linux ELF core-dumps are identical to
  41. the register sets in `struct user' that is used for a.out
  42. core-dumps, and is also used by `ptrace'. The corresponding types
  43. are `elf_gregset_t' for the general-purpose registers (with
  44. `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
  45. for the floating-point registers.
  46. Those types used to be available under the names `gregset_t' and
  47. `fpregset_t' too, and this file used those names in the past. But
  48. those names are now used for the register sets used in the
  49. `mcontext_t' type, and have a different size and layout. */
  50. /* Which ptrace request retrieves which registers?
  51. These apply to the corresponding SET requests as well. */
  52. #define GETREGS_SUPPLIES(regno) \
  53. ((0 <= (regno) && (regno) <= 15) || (regno) == I386_LINUX_ORIG_EAX_REGNUM)
  54. #define GETFPXREGS_SUPPLIES(regno) \
  55. (I386_ST0_REGNUM <= (regno) && (regno) < I386_SSE_NUM_REGS)
  56. #define GETXSTATEREGS_SUPPLIES(regno) \
  57. (I386_ST0_REGNUM <= (regno) && (regno) < I386_PKEYS_NUM_REGS)
  58. /* Does the current host support the GETREGS request? */
  59. int have_ptrace_getregs =
  60. #ifdef HAVE_PTRACE_GETREGS
  61. 1
  62. #else
  63. 0
  64. #endif
  65. ;
  66. /* Does the current host support the GETFPXREGS request? The header
  67. file may or may not define it, and even if it is defined, the
  68. kernel will return EIO if it's running on a pre-SSE processor.
  69. My instinct is to attach this to some architecture- or
  70. target-specific data structure, but really, a particular GDB
  71. process can only run on top of one kernel at a time. So it's okay
  72. for this to be a simple variable. */
  73. int have_ptrace_getfpxregs =
  74. #ifdef HAVE_PTRACE_GETFPXREGS
  75. -1
  76. #else
  77. 0
  78. #endif
  79. ;
  80. /* Accessing registers through the U area, one at a time. */
  81. /* Fetch one register. */
  82. static void
  83. fetch_register (struct regcache *regcache, int regno)
  84. {
  85. pid_t tid;
  86. int val;
  87. gdb_assert (!have_ptrace_getregs);
  88. if (i386_linux_gregset_reg_offset[regno] == -1)
  89. {
  90. regcache->raw_supply (regno, NULL);
  91. return;
  92. }
  93. tid = get_ptrace_pid (regcache->ptid ());
  94. errno = 0;
  95. val = ptrace (PTRACE_PEEKUSER, tid,
  96. i386_linux_gregset_reg_offset[regno], 0);
  97. if (errno != 0)
  98. error (_("Couldn't read register %s (#%d): %s."),
  99. gdbarch_register_name (regcache->arch (), regno),
  100. regno, safe_strerror (errno));
  101. regcache->raw_supply (regno, &val);
  102. }
  103. /* Store one register. */
  104. static void
  105. store_register (const struct regcache *regcache, int regno)
  106. {
  107. pid_t tid;
  108. int val;
  109. gdb_assert (!have_ptrace_getregs);
  110. if (i386_linux_gregset_reg_offset[regno] == -1)
  111. return;
  112. tid = get_ptrace_pid (regcache->ptid ());
  113. errno = 0;
  114. regcache->raw_collect (regno, &val);
  115. ptrace (PTRACE_POKEUSER, tid,
  116. i386_linux_gregset_reg_offset[regno], val);
  117. if (errno != 0)
  118. error (_("Couldn't write register %s (#%d): %s."),
  119. gdbarch_register_name (regcache->arch (), regno),
  120. regno, safe_strerror (errno));
  121. }
  122. /* Transfering the general-purpose registers between GDB, inferiors
  123. and core files. */
  124. /* Fill GDB's register array with the general-purpose register values
  125. in *GREGSETP. */
  126. void
  127. supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
  128. {
  129. const gdb_byte *regp = (const gdb_byte *) gregsetp;
  130. int i;
  131. for (i = 0; i < I386_NUM_GREGS; i++)
  132. regcache->raw_supply (i, regp + i386_linux_gregset_reg_offset[i]);
  133. if (I386_LINUX_ORIG_EAX_REGNUM
  134. < gdbarch_num_regs (regcache->arch ()))
  135. regcache->raw_supply
  136. (I386_LINUX_ORIG_EAX_REGNUM,
  137. regp + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
  138. }
  139. /* Fill register REGNO (if it is a general-purpose register) in
  140. *GREGSETPS with the value in GDB's register array. If REGNO is -1,
  141. do this for all registers. */
  142. void
  143. fill_gregset (const struct regcache *regcache,
  144. elf_gregset_t *gregsetp, int regno)
  145. {
  146. gdb_byte *regp = (gdb_byte *) gregsetp;
  147. int i;
  148. for (i = 0; i < I386_NUM_GREGS; i++)
  149. if (regno == -1 || regno == i)
  150. regcache->raw_collect (i, regp + i386_linux_gregset_reg_offset[i]);
  151. if ((regno == -1 || regno == I386_LINUX_ORIG_EAX_REGNUM)
  152. && I386_LINUX_ORIG_EAX_REGNUM
  153. < gdbarch_num_regs (regcache->arch ()))
  154. regcache->raw_collect
  155. (I386_LINUX_ORIG_EAX_REGNUM,
  156. regp + i386_linux_gregset_reg_offset[I386_LINUX_ORIG_EAX_REGNUM]);
  157. }
  158. #ifdef HAVE_PTRACE_GETREGS
  159. /* Fetch all general-purpose registers from process/thread TID and
  160. store their values in GDB's register array. */
  161. static void
  162. fetch_regs (struct regcache *regcache, int tid)
  163. {
  164. elf_gregset_t regs;
  165. elf_gregset_t *regs_p = &regs;
  166. if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
  167. {
  168. if (errno == EIO)
  169. {
  170. /* The kernel we're running on doesn't support the GETREGS
  171. request. Reset `have_ptrace_getregs'. */
  172. have_ptrace_getregs = 0;
  173. return;
  174. }
  175. perror_with_name (_("Couldn't get registers"));
  176. }
  177. supply_gregset (regcache, (const elf_gregset_t *) regs_p);
  178. }
  179. /* Store all valid general-purpose registers in GDB's register array
  180. into the process/thread specified by TID. */
  181. static void
  182. store_regs (const struct regcache *regcache, int tid, int regno)
  183. {
  184. elf_gregset_t regs;
  185. if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
  186. perror_with_name (_("Couldn't get registers"));
  187. fill_gregset (regcache, &regs, regno);
  188. if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
  189. perror_with_name (_("Couldn't write registers"));
  190. }
  191. #else
  192. static void fetch_regs (struct regcache *regcache, int tid) {}
  193. static void store_regs (const struct regcache *regcache, int tid, int regno) {}
  194. #endif
  195. /* Transfering floating-point registers between GDB, inferiors and cores. */
  196. /* Fill GDB's register array with the floating-point register values in
  197. *FPREGSETP. */
  198. void
  199. supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp)
  200. {
  201. i387_supply_fsave (regcache, -1, fpregsetp);
  202. }
  203. /* Fill register REGNO (if it is a floating-point register) in
  204. *FPREGSETP with the value in GDB's register array. If REGNO is -1,
  205. do this for all registers. */
  206. void
  207. fill_fpregset (const struct regcache *regcache,
  208. elf_fpregset_t *fpregsetp, int regno)
  209. {
  210. i387_collect_fsave (regcache, regno, fpregsetp);
  211. }
  212. #ifdef HAVE_PTRACE_GETREGS
  213. /* Fetch all floating-point registers from process/thread TID and store
  214. thier values in GDB's register array. */
  215. static void
  216. fetch_fpregs (struct regcache *regcache, int tid)
  217. {
  218. elf_fpregset_t fpregs;
  219. if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
  220. perror_with_name (_("Couldn't get floating point status"));
  221. supply_fpregset (regcache, (const elf_fpregset_t *) &fpregs);
  222. }
  223. /* Store all valid floating-point registers in GDB's register array
  224. into the process/thread specified by TID. */
  225. static void
  226. store_fpregs (const struct regcache *regcache, int tid, int regno)
  227. {
  228. elf_fpregset_t fpregs;
  229. if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0)
  230. perror_with_name (_("Couldn't get floating point status"));
  231. fill_fpregset (regcache, &fpregs, regno);
  232. if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0)
  233. perror_with_name (_("Couldn't write floating point status"));
  234. }
  235. #else
  236. static void
  237. fetch_fpregs (struct regcache *regcache, int tid)
  238. {
  239. }
  240. static void
  241. store_fpregs (const struct regcache *regcache, int tid, int regno)
  242. {
  243. }
  244. #endif
  245. /* Transfering floating-point and SSE registers to and from GDB. */
  246. /* Fetch all registers covered by the PTRACE_GETREGSET request from
  247. process/thread TID and store their values in GDB's register array.
  248. Return non-zero if successful, zero otherwise. */
  249. static int
  250. fetch_xstateregs (struct regcache *regcache, int tid)
  251. {
  252. char xstateregs[X86_XSTATE_MAX_SIZE];
  253. struct iovec iov;
  254. if (have_ptrace_getregset != TRIBOOL_TRUE)
  255. return 0;
  256. iov.iov_base = xstateregs;
  257. iov.iov_len = sizeof(xstateregs);
  258. if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  259. &iov) < 0)
  260. perror_with_name (_("Couldn't read extended state status"));
  261. i387_supply_xsave (regcache, -1, xstateregs);
  262. return 1;
  263. }
  264. /* Store all valid registers in GDB's register array covered by the
  265. PTRACE_SETREGSET request into the process/thread specified by TID.
  266. Return non-zero if successful, zero otherwise. */
  267. static int
  268. store_xstateregs (const struct regcache *regcache, int tid, int regno)
  269. {
  270. char xstateregs[X86_XSTATE_MAX_SIZE];
  271. struct iovec iov;
  272. if (have_ptrace_getregset != TRIBOOL_TRUE)
  273. return 0;
  274. iov.iov_base = xstateregs;
  275. iov.iov_len = sizeof(xstateregs);
  276. if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  277. &iov) < 0)
  278. perror_with_name (_("Couldn't read extended state status"));
  279. i387_collect_xsave (regcache, regno, xstateregs, 0);
  280. if (ptrace (PTRACE_SETREGSET, tid, (unsigned int) NT_X86_XSTATE,
  281. (int) &iov) < 0)
  282. perror_with_name (_("Couldn't write extended state status"));
  283. return 1;
  284. }
  285. #ifdef HAVE_PTRACE_GETFPXREGS
  286. /* Fetch all registers covered by the PTRACE_GETFPXREGS request from
  287. process/thread TID and store their values in GDB's register array.
  288. Return non-zero if successful, zero otherwise. */
  289. static int
  290. fetch_fpxregs (struct regcache *regcache, int tid)
  291. {
  292. elf_fpxregset_t fpxregs;
  293. if (! have_ptrace_getfpxregs)
  294. return 0;
  295. if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0)
  296. {
  297. if (errno == EIO)
  298. {
  299. have_ptrace_getfpxregs = 0;
  300. return 0;
  301. }
  302. perror_with_name (_("Couldn't read floating-point and SSE registers"));
  303. }
  304. i387_supply_fxsave (regcache, -1, (const elf_fpxregset_t *) &fpxregs);
  305. return 1;
  306. }
  307. /* Store all valid registers in GDB's register array covered by the
  308. PTRACE_SETFPXREGS request into the process/thread specified by TID.
  309. Return non-zero if successful, zero otherwise. */
  310. static int
  311. store_fpxregs (const struct regcache *regcache, int tid, int regno)
  312. {
  313. elf_fpxregset_t fpxregs;
  314. if (! have_ptrace_getfpxregs)
  315. return 0;
  316. if (ptrace (PTRACE_GETFPXREGS, tid, 0, &fpxregs) == -1)
  317. {
  318. if (errno == EIO)
  319. {
  320. have_ptrace_getfpxregs = 0;
  321. return 0;
  322. }
  323. perror_with_name (_("Couldn't read floating-point and SSE registers"));
  324. }
  325. i387_collect_fxsave (regcache, regno, &fpxregs);
  326. if (ptrace (PTRACE_SETFPXREGS, tid, 0, &fpxregs) == -1)
  327. perror_with_name (_("Couldn't write floating-point and SSE registers"));
  328. return 1;
  329. }
  330. #else
  331. static int
  332. fetch_fpxregs (struct regcache *regcache, int tid)
  333. {
  334. return 0;
  335. }
  336. static int
  337. store_fpxregs (const struct regcache *regcache, int tid, int regno)
  338. {
  339. return 0;
  340. }
  341. #endif /* HAVE_PTRACE_GETFPXREGS */
  342. /* Transferring arbitrary registers between GDB and inferior. */
  343. /* Fetch register REGNO from the child process. If REGNO is -1, do
  344. this for all registers (including the floating point and SSE
  345. registers). */
  346. void
  347. i386_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
  348. {
  349. pid_t tid;
  350. /* Use the old method of peeking around in `struct user' if the
  351. GETREGS request isn't available. */
  352. if (!have_ptrace_getregs)
  353. {
  354. int i;
  355. for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
  356. if (regno == -1 || regno == i)
  357. fetch_register (regcache, i);
  358. return;
  359. }
  360. tid = get_ptrace_pid (regcache->ptid ());
  361. /* Use the PTRACE_GETFPXREGS request whenever possible, since it
  362. transfers more registers in one system call, and we'll cache the
  363. results. But remember that fetch_fpxregs can fail, and return
  364. zero. */
  365. if (regno == -1)
  366. {
  367. fetch_regs (regcache, tid);
  368. /* The call above might reset `have_ptrace_getregs'. */
  369. if (!have_ptrace_getregs)
  370. {
  371. fetch_registers (regcache, regno);
  372. return;
  373. }
  374. if (fetch_xstateregs (regcache, tid))
  375. return;
  376. if (fetch_fpxregs (regcache, tid))
  377. return;
  378. fetch_fpregs (regcache, tid);
  379. return;
  380. }
  381. if (GETREGS_SUPPLIES (regno))
  382. {
  383. fetch_regs (regcache, tid);
  384. return;
  385. }
  386. if (GETXSTATEREGS_SUPPLIES (regno))
  387. {
  388. if (fetch_xstateregs (regcache, tid))
  389. return;
  390. }
  391. if (GETFPXREGS_SUPPLIES (regno))
  392. {
  393. if (fetch_fpxregs (regcache, tid))
  394. return;
  395. /* Either our processor or our kernel doesn't support the SSE
  396. registers, so read the FP registers in the traditional way,
  397. and fill the SSE registers with dummy values. It would be
  398. more graceful to handle differences in the register set using
  399. gdbarch. Until then, this will at least make things work
  400. plausibly. */
  401. fetch_fpregs (regcache, tid);
  402. return;
  403. }
  404. internal_error (__FILE__, __LINE__,
  405. _("Got request for bad register number %d."), regno);
  406. }
  407. /* Store register REGNO back into the child process. If REGNO is -1,
  408. do this for all registers (including the floating point and SSE
  409. registers). */
  410. void
  411. i386_linux_nat_target::store_registers (struct regcache *regcache, int regno)
  412. {
  413. pid_t tid;
  414. /* Use the old method of poking around in `struct user' if the
  415. SETREGS request isn't available. */
  416. if (!have_ptrace_getregs)
  417. {
  418. int i;
  419. for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
  420. if (regno == -1 || regno == i)
  421. store_register (regcache, i);
  422. return;
  423. }
  424. tid = get_ptrace_pid (regcache->ptid ());
  425. /* Use the PTRACE_SETFPXREGS requests whenever possible, since it
  426. transfers more registers in one system call. But remember that
  427. store_fpxregs can fail, and return zero. */
  428. if (regno == -1)
  429. {
  430. store_regs (regcache, tid, regno);
  431. if (store_xstateregs (regcache, tid, regno))
  432. return;
  433. if (store_fpxregs (regcache, tid, regno))
  434. return;
  435. store_fpregs (regcache, tid, regno);
  436. return;
  437. }
  438. if (GETREGS_SUPPLIES (regno))
  439. {
  440. store_regs (regcache, tid, regno);
  441. return;
  442. }
  443. if (GETXSTATEREGS_SUPPLIES (regno))
  444. {
  445. if (store_xstateregs (regcache, tid, regno))
  446. return;
  447. }
  448. if (GETFPXREGS_SUPPLIES (regno))
  449. {
  450. if (store_fpxregs (regcache, tid, regno))
  451. return;
  452. /* Either our processor or our kernel doesn't support the SSE
  453. registers, so just write the FP registers in the traditional
  454. way. */
  455. store_fpregs (regcache, tid, regno);
  456. return;
  457. }
  458. internal_error (__FILE__, __LINE__,
  459. _("Got request to store bad register number %d."), regno);
  460. }
  461. /* Called by libthread_db. Returns a pointer to the thread local
  462. storage (or its descriptor). */
  463. ps_err_e
  464. ps_get_thread_area (struct ps_prochandle *ph,
  465. lwpid_t lwpid, int idx, void **base)
  466. {
  467. unsigned int base_addr;
  468. ps_err_e result;
  469. result = x86_linux_get_thread_area (lwpid, (void *) idx, &base_addr);
  470. if (result == PS_OK)
  471. *(int *) base = base_addr;
  472. return result;
  473. }
  474. /* The instruction for a GNU/Linux system call is:
  475. int $0x80
  476. or 0xcd 0x80. */
  477. static const unsigned char linux_syscall[] = { 0xcd, 0x80 };
  478. #define LINUX_SYSCALL_LEN (sizeof linux_syscall)
  479. /* The system call number is stored in the %eax register. */
  480. #define LINUX_SYSCALL_REGNUM I386_EAX_REGNUM
  481. /* We are specifically interested in the sigreturn and rt_sigreturn
  482. system calls. */
  483. #ifndef SYS_sigreturn
  484. #define SYS_sigreturn 0x77
  485. #endif
  486. #ifndef SYS_rt_sigreturn
  487. #define SYS_rt_sigreturn 0xad
  488. #endif
  489. /* Offset to saved processor flags, from <asm/sigcontext.h>. */
  490. #define LINUX_SIGCONTEXT_EFLAGS_OFFSET (64)
  491. /* Resume execution of the inferior process.
  492. If STEP is nonzero, single-step it.
  493. If SIGNAL is nonzero, give it that signal. */
  494. void
  495. i386_linux_nat_target::low_resume (ptid_t ptid, int step, enum gdb_signal signal)
  496. {
  497. int pid = ptid.lwp ();
  498. int request;
  499. if (catch_syscall_enabled () > 0)
  500. request = PTRACE_SYSCALL;
  501. else
  502. request = PTRACE_CONT;
  503. if (step)
  504. {
  505. struct regcache *regcache = get_thread_regcache (this, ptid);
  506. struct gdbarch *gdbarch = regcache->arch ();
  507. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  508. ULONGEST pc;
  509. gdb_byte buf[LINUX_SYSCALL_LEN];
  510. request = PTRACE_SINGLESTEP;
  511. regcache_cooked_read_unsigned (regcache,
  512. gdbarch_pc_regnum (gdbarch), &pc);
  513. /* Returning from a signal trampoline is done by calling a
  514. special system call (sigreturn or rt_sigreturn, see
  515. i386-linux-tdep.c for more information). This system call
  516. restores the registers that were saved when the signal was
  517. raised, including %eflags. That means that single-stepping
  518. won't work. Instead, we'll have to modify the signal context
  519. that's about to be restored, and set the trace flag there. */
  520. /* First check if PC is at a system call. */
  521. if (target_read_memory (pc, buf, LINUX_SYSCALL_LEN) == 0
  522. && memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
  523. {
  524. ULONGEST syscall;
  525. regcache_cooked_read_unsigned (regcache,
  526. LINUX_SYSCALL_REGNUM, &syscall);
  527. /* Then check the system call number. */
  528. if (syscall == SYS_sigreturn || syscall == SYS_rt_sigreturn)
  529. {
  530. ULONGEST sp, addr;
  531. unsigned long int eflags;
  532. regcache_cooked_read_unsigned (regcache, I386_ESP_REGNUM, &sp);
  533. if (syscall == SYS_rt_sigreturn)
  534. addr = read_memory_unsigned_integer (sp + 8, 4, byte_order)
  535. + 20;
  536. else
  537. addr = sp;
  538. /* Set the trace flag in the context that's about to be
  539. restored. */
  540. addr += LINUX_SIGCONTEXT_EFLAGS_OFFSET;
  541. read_memory (addr, (gdb_byte *) &eflags, 4);
  542. eflags |= 0x0100;
  543. write_memory (addr, (gdb_byte *) &eflags, 4);
  544. }
  545. }
  546. }
  547. if (ptrace (request, pid, 0, gdb_signal_to_host (signal)) == -1)
  548. perror_with_name (("ptrace"));
  549. }
  550. void _initialize_i386_linux_nat ();
  551. void
  552. _initialize_i386_linux_nat ()
  553. {
  554. linux_target = &the_i386_linux_nat_target;
  555. /* Add the target. */
  556. add_inf_child_target (linux_target);
  557. }