arm-linux-nat.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /* GNU/Linux on ARM native support.
  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 "target.h"
  19. #include "linux-nat.h"
  20. #include "target-descriptions.h"
  21. #include "auxv.h"
  22. #include "observable.h"
  23. #include "gdbthread.h"
  24. #include "aarch32-tdep.h"
  25. #include "arm-tdep.h"
  26. #include "arm-linux-tdep.h"
  27. #include "aarch32-linux-nat.h"
  28. #include <elf/common.h>
  29. #include <sys/user.h>
  30. #include "nat/gdb_ptrace.h"
  31. #include <sys/utsname.h>
  32. #include <sys/procfs.h>
  33. #include "nat/linux-ptrace.h"
  34. #include "linux-tdep.h"
  35. /* Prototypes for supply_gregset etc. */
  36. #include "gregset.h"
  37. /* Defines ps_err_e, struct ps_prochandle. */
  38. #include "gdb_proc_service.h"
  39. #ifndef PTRACE_GET_THREAD_AREA
  40. #define PTRACE_GET_THREAD_AREA 22
  41. #endif
  42. #ifndef PTRACE_GETWMMXREGS
  43. #define PTRACE_GETWMMXREGS 18
  44. #define PTRACE_SETWMMXREGS 19
  45. #endif
  46. #ifndef PTRACE_GETVFPREGS
  47. #define PTRACE_GETVFPREGS 27
  48. #define PTRACE_SETVFPREGS 28
  49. #endif
  50. #ifndef PTRACE_GETHBPREGS
  51. #define PTRACE_GETHBPREGS 29
  52. #define PTRACE_SETHBPREGS 30
  53. #endif
  54. class arm_linux_nat_target final : public linux_nat_target
  55. {
  56. public:
  57. /* Add our register access methods. */
  58. void fetch_registers (struct regcache *, int) override;
  59. void store_registers (struct regcache *, int) override;
  60. /* Add our hardware breakpoint and watchpoint implementation. */
  61. int can_use_hw_breakpoint (enum bptype, int, int) override;
  62. int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
  63. int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *) override;
  64. int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
  65. int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
  66. struct expression *) override;
  67. int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
  68. struct expression *) override;
  69. bool stopped_by_watchpoint () override;
  70. bool stopped_data_address (CORE_ADDR *) override;
  71. bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
  72. const struct target_desc *read_description () override;
  73. /* Override linux_nat_target low methods. */
  74. /* Handle thread creation and exit. */
  75. void low_new_thread (struct lwp_info *lp) override;
  76. void low_delete_thread (struct arch_lwp_info *lp) override;
  77. void low_prepare_to_resume (struct lwp_info *lp) override;
  78. /* Handle process creation and exit. */
  79. void low_new_fork (struct lwp_info *parent, pid_t child_pid) override;
  80. void low_forget_process (pid_t pid) override;
  81. };
  82. static arm_linux_nat_target the_arm_linux_nat_target;
  83. /* Get the whole floating point state of the process and store it
  84. into regcache. */
  85. static void
  86. fetch_fpregs (struct regcache *regcache)
  87. {
  88. int ret, regno, tid;
  89. gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
  90. /* Get the thread id for the ptrace call. */
  91. tid = regcache->ptid ().lwp ();
  92. /* Read the floating point state. */
  93. if (have_ptrace_getregset == TRIBOOL_TRUE)
  94. {
  95. struct iovec iov;
  96. iov.iov_base = &fp;
  97. iov.iov_len = ARM_LINUX_SIZEOF_NWFPE;
  98. ret = ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iov);
  99. }
  100. else
  101. ret = ptrace (PT_GETFPREGS, tid, 0, fp);
  102. if (ret < 0)
  103. perror_with_name (_("Unable to fetch the floating point registers."));
  104. /* Fetch fpsr. */
  105. regcache->raw_supply (ARM_FPS_REGNUM, fp + NWFPE_FPSR_OFFSET);
  106. /* Fetch the floating point registers. */
  107. for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
  108. supply_nwfpe_register (regcache, regno, fp);
  109. }
  110. /* Save the whole floating point state of the process using
  111. the contents from regcache. */
  112. static void
  113. store_fpregs (const struct regcache *regcache)
  114. {
  115. int ret, regno, tid;
  116. gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE];
  117. /* Get the thread id for the ptrace call. */
  118. tid = regcache->ptid ().lwp ();
  119. /* Read the floating point state. */
  120. if (have_ptrace_getregset == TRIBOOL_TRUE)
  121. {
  122. elf_fpregset_t fpregs;
  123. struct iovec iov;
  124. iov.iov_base = &fpregs;
  125. iov.iov_len = sizeof (fpregs);
  126. ret = ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iov);
  127. }
  128. else
  129. ret = ptrace (PT_GETFPREGS, tid, 0, fp);
  130. if (ret < 0)
  131. perror_with_name (_("Unable to fetch the floating point registers."));
  132. /* Store fpsr. */
  133. if (REG_VALID == regcache->get_register_status (ARM_FPS_REGNUM))
  134. regcache->raw_collect (ARM_FPS_REGNUM, fp + NWFPE_FPSR_OFFSET);
  135. /* Store the floating point registers. */
  136. for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
  137. if (REG_VALID == regcache->get_register_status (regno))
  138. collect_nwfpe_register (regcache, regno, fp);
  139. if (have_ptrace_getregset == TRIBOOL_TRUE)
  140. {
  141. struct iovec iov;
  142. iov.iov_base = &fp;
  143. iov.iov_len = ARM_LINUX_SIZEOF_NWFPE;
  144. ret = ptrace (PTRACE_SETREGSET, tid, NT_FPREGSET, &iov);
  145. }
  146. else
  147. ret = ptrace (PTRACE_SETFPREGS, tid, 0, fp);
  148. if (ret < 0)
  149. perror_with_name (_("Unable to store floating point registers."));
  150. }
  151. /* Fetch all general registers of the process and store into
  152. regcache. */
  153. static void
  154. fetch_regs (struct regcache *regcache)
  155. {
  156. int ret, tid;
  157. elf_gregset_t regs;
  158. /* Get the thread id for the ptrace call. */
  159. tid = regcache->ptid ().lwp ();
  160. if (have_ptrace_getregset == TRIBOOL_TRUE)
  161. {
  162. struct iovec iov;
  163. iov.iov_base = &regs;
  164. iov.iov_len = sizeof (regs);
  165. ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov);
  166. }
  167. else
  168. ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
  169. if (ret < 0)
  170. perror_with_name (_("Unable to fetch general registers."));
  171. aarch32_gp_regcache_supply (regcache, (uint32_t *) regs, arm_apcs_32);
  172. }
  173. static void
  174. store_regs (const struct regcache *regcache)
  175. {
  176. int ret, tid;
  177. elf_gregset_t regs;
  178. /* Get the thread id for the ptrace call. */
  179. tid = regcache->ptid ().lwp ();
  180. /* Fetch the general registers. */
  181. if (have_ptrace_getregset == TRIBOOL_TRUE)
  182. {
  183. struct iovec iov;
  184. iov.iov_base = &regs;
  185. iov.iov_len = sizeof (regs);
  186. ret = ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov);
  187. }
  188. else
  189. ret = ptrace (PTRACE_GETREGS, tid, 0, &regs);
  190. if (ret < 0)
  191. perror_with_name (_("Unable to fetch general registers."));
  192. aarch32_gp_regcache_collect (regcache, (uint32_t *) regs, arm_apcs_32);
  193. if (have_ptrace_getregset == TRIBOOL_TRUE)
  194. {
  195. struct iovec iov;
  196. iov.iov_base = &regs;
  197. iov.iov_len = sizeof (regs);
  198. ret = ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS, &iov);
  199. }
  200. else
  201. ret = ptrace (PTRACE_SETREGS, tid, 0, &regs);
  202. if (ret < 0)
  203. perror_with_name (_("Unable to store general registers."));
  204. }
  205. /* Fetch all WMMX registers of the process and store into
  206. regcache. */
  207. static void
  208. fetch_wmmx_regs (struct regcache *regcache)
  209. {
  210. char regbuf[IWMMXT_REGS_SIZE];
  211. int ret, regno, tid;
  212. /* Get the thread id for the ptrace call. */
  213. tid = regcache->ptid ().lwp ();
  214. ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf);
  215. if (ret < 0)
  216. perror_with_name (_("Unable to fetch WMMX registers."));
  217. for (regno = 0; regno < 16; regno++)
  218. regcache->raw_supply (regno + ARM_WR0_REGNUM, &regbuf[regno * 8]);
  219. for (regno = 0; regno < 2; regno++)
  220. regcache->raw_supply (regno + ARM_WCSSF_REGNUM,
  221. &regbuf[16 * 8 + regno * 4]);
  222. for (regno = 0; regno < 4; regno++)
  223. regcache->raw_supply (regno + ARM_WCGR0_REGNUM,
  224. &regbuf[16 * 8 + 2 * 4 + regno * 4]);
  225. }
  226. static void
  227. store_wmmx_regs (const struct regcache *regcache)
  228. {
  229. char regbuf[IWMMXT_REGS_SIZE];
  230. int ret, regno, tid;
  231. /* Get the thread id for the ptrace call. */
  232. tid = regcache->ptid ().lwp ();
  233. ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf);
  234. if (ret < 0)
  235. perror_with_name (_("Unable to fetch WMMX registers."));
  236. for (regno = 0; regno < 16; regno++)
  237. if (REG_VALID == regcache->get_register_status (regno + ARM_WR0_REGNUM))
  238. regcache->raw_collect (regno + ARM_WR0_REGNUM, &regbuf[regno * 8]);
  239. for (regno = 0; regno < 2; regno++)
  240. if (REG_VALID == regcache->get_register_status (regno + ARM_WCSSF_REGNUM))
  241. regcache->raw_collect (regno + ARM_WCSSF_REGNUM,
  242. &regbuf[16 * 8 + regno * 4]);
  243. for (regno = 0; regno < 4; regno++)
  244. if (REG_VALID == regcache->get_register_status (regno + ARM_WCGR0_REGNUM))
  245. regcache->raw_collect (regno + ARM_WCGR0_REGNUM,
  246. &regbuf[16 * 8 + 2 * 4 + regno * 4]);
  247. ret = ptrace (PTRACE_SETWMMXREGS, tid, 0, regbuf);
  248. if (ret < 0)
  249. perror_with_name (_("Unable to store WMMX registers."));
  250. }
  251. static void
  252. fetch_vfp_regs (struct regcache *regcache)
  253. {
  254. gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
  255. int ret, tid;
  256. struct gdbarch *gdbarch = regcache->arch ();
  257. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  258. /* Get the thread id for the ptrace call. */
  259. tid = regcache->ptid ().lwp ();
  260. if (have_ptrace_getregset == TRIBOOL_TRUE)
  261. {
  262. struct iovec iov;
  263. iov.iov_base = regbuf;
  264. iov.iov_len = ARM_VFP3_REGS_SIZE;
  265. ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iov);
  266. }
  267. else
  268. ret = ptrace (PTRACE_GETVFPREGS, tid, 0, regbuf);
  269. if (ret < 0)
  270. perror_with_name (_("Unable to fetch VFP registers."));
  271. aarch32_vfp_regcache_supply (regcache, regbuf,
  272. tdep->vfp_register_count);
  273. }
  274. static void
  275. store_vfp_regs (const struct regcache *regcache)
  276. {
  277. gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
  278. int ret, tid;
  279. struct gdbarch *gdbarch = regcache->arch ();
  280. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  281. /* Get the thread id for the ptrace call. */
  282. tid = regcache->ptid ().lwp ();
  283. if (have_ptrace_getregset == TRIBOOL_TRUE)
  284. {
  285. struct iovec iov;
  286. iov.iov_base = regbuf;
  287. iov.iov_len = ARM_VFP3_REGS_SIZE;
  288. ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iov);
  289. }
  290. else
  291. ret = ptrace (PTRACE_GETVFPREGS, tid, 0, regbuf);
  292. if (ret < 0)
  293. perror_with_name (_("Unable to fetch VFP registers (for update)."));
  294. aarch32_vfp_regcache_collect (regcache, regbuf,
  295. tdep->vfp_register_count);
  296. if (have_ptrace_getregset == TRIBOOL_TRUE)
  297. {
  298. struct iovec iov;
  299. iov.iov_base = regbuf;
  300. iov.iov_len = ARM_VFP3_REGS_SIZE;
  301. ret = ptrace (PTRACE_SETREGSET, tid, NT_ARM_VFP, &iov);
  302. }
  303. else
  304. ret = ptrace (PTRACE_SETVFPREGS, tid, 0, regbuf);
  305. if (ret < 0)
  306. perror_with_name (_("Unable to store VFP registers."));
  307. }
  308. /* Fetch registers from the child process. Fetch all registers if
  309. regno == -1, otherwise fetch all general registers or all floating
  310. point registers depending upon the value of regno. */
  311. void
  312. arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
  313. {
  314. struct gdbarch *gdbarch = regcache->arch ();
  315. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  316. if (-1 == regno)
  317. {
  318. fetch_regs (regcache);
  319. if (tdep->have_wmmx_registers)
  320. fetch_wmmx_regs (regcache);
  321. if (tdep->vfp_register_count > 0)
  322. fetch_vfp_regs (regcache);
  323. if (tdep->have_fpa_registers)
  324. fetch_fpregs (regcache);
  325. }
  326. else
  327. {
  328. if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM)
  329. fetch_regs (regcache);
  330. else if (regno >= ARM_F0_REGNUM && regno <= ARM_FPS_REGNUM)
  331. fetch_fpregs (regcache);
  332. else if (tdep->have_wmmx_registers
  333. && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM)
  334. fetch_wmmx_regs (regcache);
  335. else if (tdep->vfp_register_count > 0
  336. && regno >= ARM_D0_REGNUM
  337. && (regno < ARM_D0_REGNUM + tdep->vfp_register_count
  338. || regno == ARM_FPSCR_REGNUM))
  339. fetch_vfp_regs (regcache);
  340. }
  341. }
  342. /* Store registers back into the inferior. Store all registers if
  343. regno == -1, otherwise store all general registers or all floating
  344. point registers depending upon the value of regno. */
  345. void
  346. arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
  347. {
  348. struct gdbarch *gdbarch = regcache->arch ();
  349. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  350. if (-1 == regno)
  351. {
  352. store_regs (regcache);
  353. if (tdep->have_wmmx_registers)
  354. store_wmmx_regs (regcache);
  355. if (tdep->vfp_register_count > 0)
  356. store_vfp_regs (regcache);
  357. if (tdep->have_fpa_registers)
  358. store_fpregs (regcache);
  359. }
  360. else
  361. {
  362. if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM)
  363. store_regs (regcache);
  364. else if ((regno >= ARM_F0_REGNUM) && (regno <= ARM_FPS_REGNUM))
  365. store_fpregs (regcache);
  366. else if (tdep->have_wmmx_registers
  367. && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM)
  368. store_wmmx_regs (regcache);
  369. else if (tdep->vfp_register_count > 0
  370. && regno >= ARM_D0_REGNUM
  371. && (regno < ARM_D0_REGNUM + tdep->vfp_register_count
  372. || regno == ARM_FPSCR_REGNUM))
  373. store_vfp_regs (regcache);
  374. }
  375. }
  376. /* Wrapper functions for the standard regset handling, used by
  377. thread debugging. */
  378. void
  379. fill_gregset (const struct regcache *regcache,
  380. gdb_gregset_t *gregsetp, int regno)
  381. {
  382. arm_linux_collect_gregset (NULL, regcache, regno, gregsetp, 0);
  383. }
  384. void
  385. supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
  386. {
  387. arm_linux_supply_gregset (NULL, regcache, -1, gregsetp, 0);
  388. }
  389. void
  390. fill_fpregset (const struct regcache *regcache,
  391. gdb_fpregset_t *fpregsetp, int regno)
  392. {
  393. arm_linux_collect_nwfpe (NULL, regcache, regno, fpregsetp, 0);
  394. }
  395. /* Fill GDB's register array with the floating-point register values
  396. in *fpregsetp. */
  397. void
  398. supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
  399. {
  400. arm_linux_supply_nwfpe (NULL, regcache, -1, fpregsetp, 0);
  401. }
  402. /* Fetch the thread-local storage pointer for libthread_db. */
  403. ps_err_e
  404. ps_get_thread_area (struct ps_prochandle *ph,
  405. lwpid_t lwpid, int idx, void **base)
  406. {
  407. if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
  408. return PS_ERR;
  409. /* IDX is the bias from the thread pointer to the beginning of the
  410. thread descriptor. It has to be subtracted due to implementation
  411. quirks in libthread_db. */
  412. *base = (void *) ((char *)*base - idx);
  413. return PS_OK;
  414. }
  415. const struct target_desc *
  416. arm_linux_nat_target::read_description ()
  417. {
  418. CORE_ADDR arm_hwcap = linux_get_hwcap (this);
  419. if (have_ptrace_getregset == TRIBOOL_UNKNOWN)
  420. {
  421. elf_gregset_t gpregs;
  422. struct iovec iov;
  423. int tid = inferior_ptid.pid ();
  424. iov.iov_base = &gpregs;
  425. iov.iov_len = sizeof (gpregs);
  426. /* Check if PTRACE_GETREGSET works. */
  427. if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) < 0)
  428. have_ptrace_getregset = TRIBOOL_FALSE;
  429. else
  430. have_ptrace_getregset = TRIBOOL_TRUE;
  431. }
  432. if (arm_hwcap & HWCAP_IWMMXT)
  433. return arm_read_description (ARM_FP_TYPE_IWMMXT);
  434. if (arm_hwcap & HWCAP_VFP)
  435. {
  436. /* Make sure that the kernel supports reading VFP registers. Support was
  437. added in 2.6.30. */
  438. int pid = inferior_ptid.pid ();
  439. errno = 0;
  440. char *buf = (char *) alloca (ARM_VFP3_REGS_SIZE);
  441. if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0 && errno == EIO)
  442. return nullptr;
  443. /* NEON implies VFPv3-D32 or no-VFP unit. Say that we only support
  444. Neon with VFPv3-D32. */
  445. if (arm_hwcap & HWCAP_NEON)
  446. return aarch32_read_description ();
  447. else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
  448. return arm_read_description (ARM_FP_TYPE_VFPV3);
  449. return arm_read_description (ARM_FP_TYPE_VFPV2);
  450. }
  451. return this->beneath ()->read_description ();
  452. }
  453. /* Information describing the hardware breakpoint capabilities. */
  454. struct arm_linux_hwbp_cap
  455. {
  456. gdb_byte arch;
  457. gdb_byte max_wp_length;
  458. gdb_byte wp_count;
  459. gdb_byte bp_count;
  460. };
  461. /* Since we cannot dynamically allocate subfields of arm_linux_process_info,
  462. assume a maximum number of supported break-/watchpoints. */
  463. #define MAX_BPTS 16
  464. #define MAX_WPTS 16
  465. /* Get hold of the Hardware Breakpoint information for the target we are
  466. attached to. Returns NULL if the kernel doesn't support Hardware
  467. breakpoints at all, or a pointer to the information structure. */
  468. static const struct arm_linux_hwbp_cap *
  469. arm_linux_get_hwbp_cap (void)
  470. {
  471. /* The info structure we return. */
  472. static struct arm_linux_hwbp_cap info;
  473. /* Is INFO in a good state? -1 means that no attempt has been made to
  474. initialize INFO; 0 means an attempt has been made, but it failed; 1
  475. means INFO is in an initialized state. */
  476. static int available = -1;
  477. if (available == -1)
  478. {
  479. int tid;
  480. unsigned int val;
  481. tid = inferior_ptid.lwp ();
  482. if (ptrace (PTRACE_GETHBPREGS, tid, 0, &val) < 0)
  483. available = 0;
  484. else
  485. {
  486. info.arch = (gdb_byte)((val >> 24) & 0xff);
  487. info.max_wp_length = (gdb_byte)((val >> 16) & 0xff);
  488. info.wp_count = (gdb_byte)((val >> 8) & 0xff);
  489. info.bp_count = (gdb_byte)(val & 0xff);
  490. if (info.wp_count > MAX_WPTS)
  491. {
  492. warning (_("arm-linux-gdb supports %d hardware watchpoints but target \
  493. supports %d"), MAX_WPTS, info.wp_count);
  494. info.wp_count = MAX_WPTS;
  495. }
  496. if (info.bp_count > MAX_BPTS)
  497. {
  498. warning (_("arm-linux-gdb supports %d hardware breakpoints but target \
  499. supports %d"), MAX_BPTS, info.bp_count);
  500. info.bp_count = MAX_BPTS;
  501. }
  502. available = (info.arch != 0);
  503. }
  504. }
  505. return available == 1 ? &info : NULL;
  506. }
  507. /* How many hardware breakpoints are available? */
  508. static int
  509. arm_linux_get_hw_breakpoint_count (void)
  510. {
  511. const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
  512. return cap != NULL ? cap->bp_count : 0;
  513. }
  514. /* How many hardware watchpoints are available? */
  515. static int
  516. arm_linux_get_hw_watchpoint_count (void)
  517. {
  518. const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
  519. return cap != NULL ? cap->wp_count : 0;
  520. }
  521. /* Have we got a free break-/watch-point available for use? Returns -1 if
  522. there is not an appropriate resource available, otherwise returns 1. */
  523. int
  524. arm_linux_nat_target::can_use_hw_breakpoint (enum bptype type,
  525. int cnt, int ot)
  526. {
  527. if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
  528. || type == bp_access_watchpoint || type == bp_watchpoint)
  529. {
  530. int count = arm_linux_get_hw_watchpoint_count ();
  531. if (count == 0)
  532. return 0;
  533. else if (cnt + ot > count)
  534. return -1;
  535. }
  536. else if (type == bp_hardware_breakpoint)
  537. {
  538. int count = arm_linux_get_hw_breakpoint_count ();
  539. if (count == 0)
  540. return 0;
  541. else if (cnt > count)
  542. return -1;
  543. }
  544. else
  545. gdb_assert_not_reached ("unknown breakpoint type");
  546. return 1;
  547. }
  548. /* Enum describing the different types of ARM hardware break-/watch-points. */
  549. typedef enum
  550. {
  551. arm_hwbp_break = 0,
  552. arm_hwbp_load = 1,
  553. arm_hwbp_store = 2,
  554. arm_hwbp_access = 3
  555. } arm_hwbp_type;
  556. /* Type describing an ARM Hardware Breakpoint Control register value. */
  557. typedef unsigned int arm_hwbp_control_t;
  558. /* Structure used to keep track of hardware break-/watch-points. */
  559. struct arm_linux_hw_breakpoint
  560. {
  561. /* Address to break on, or being watched. */
  562. unsigned int address;
  563. /* Control register for break-/watch- point. */
  564. arm_hwbp_control_t control;
  565. };
  566. /* Structure containing arrays of per process hardware break-/watchpoints
  567. for caching address and control information.
  568. The Linux ptrace interface to hardware break-/watch-points presents the
  569. values in a vector centred around 0 (which is used fo generic information).
  570. Positive indicies refer to breakpoint addresses/control registers, negative
  571. indices to watchpoint addresses/control registers.
  572. The Linux vector is indexed as follows:
  573. -((i << 1) + 2): Control register for watchpoint i.
  574. -((i << 1) + 1): Address register for watchpoint i.
  575. 0: Information register.
  576. ((i << 1) + 1): Address register for breakpoint i.
  577. ((i << 1) + 2): Control register for breakpoint i.
  578. This structure is used as a per-thread cache of the state stored by the
  579. kernel, so that we don't need to keep calling into the kernel to find a
  580. free breakpoint.
  581. We treat break-/watch-points with their enable bit clear as being deleted.
  582. */
  583. struct arm_linux_debug_reg_state
  584. {
  585. /* Hardware breakpoints for this process. */
  586. struct arm_linux_hw_breakpoint bpts[MAX_BPTS];
  587. /* Hardware watchpoints for this process. */
  588. struct arm_linux_hw_breakpoint wpts[MAX_WPTS];
  589. };
  590. /* Per-process arch-specific data we want to keep. */
  591. struct arm_linux_process_info
  592. {
  593. /* Linked list. */
  594. struct arm_linux_process_info *next;
  595. /* The process identifier. */
  596. pid_t pid;
  597. /* Hardware break-/watchpoints state information. */
  598. struct arm_linux_debug_reg_state state;
  599. };
  600. /* Per-thread arch-specific data we want to keep. */
  601. struct arch_lwp_info
  602. {
  603. /* Non-zero if our copy differs from what's recorded in the thread. */
  604. char bpts_changed[MAX_BPTS];
  605. char wpts_changed[MAX_WPTS];
  606. };
  607. static struct arm_linux_process_info *arm_linux_process_list = NULL;
  608. /* Find process data for process PID. */
  609. static struct arm_linux_process_info *
  610. arm_linux_find_process_pid (pid_t pid)
  611. {
  612. struct arm_linux_process_info *proc;
  613. for (proc = arm_linux_process_list; proc; proc = proc->next)
  614. if (proc->pid == pid)
  615. return proc;
  616. return NULL;
  617. }
  618. /* Add process data for process PID. Returns newly allocated info
  619. object. */
  620. static struct arm_linux_process_info *
  621. arm_linux_add_process (pid_t pid)
  622. {
  623. struct arm_linux_process_info *proc;
  624. proc = XCNEW (struct arm_linux_process_info);
  625. proc->pid = pid;
  626. proc->next = arm_linux_process_list;
  627. arm_linux_process_list = proc;
  628. return proc;
  629. }
  630. /* Get data specific info for process PID, creating it if necessary.
  631. Never returns NULL. */
  632. static struct arm_linux_process_info *
  633. arm_linux_process_info_get (pid_t pid)
  634. {
  635. struct arm_linux_process_info *proc;
  636. proc = arm_linux_find_process_pid (pid);
  637. if (proc == NULL)
  638. proc = arm_linux_add_process (pid);
  639. return proc;
  640. }
  641. /* Called whenever GDB is no longer debugging process PID. It deletes
  642. data structures that keep track of debug register state. */
  643. void
  644. arm_linux_nat_target::low_forget_process (pid_t pid)
  645. {
  646. struct arm_linux_process_info *proc, **proc_link;
  647. proc = arm_linux_process_list;
  648. proc_link = &arm_linux_process_list;
  649. while (proc != NULL)
  650. {
  651. if (proc->pid == pid)
  652. {
  653. *proc_link = proc->next;
  654. xfree (proc);
  655. return;
  656. }
  657. proc_link = &proc->next;
  658. proc = *proc_link;
  659. }
  660. }
  661. /* Get hardware break-/watchpoint state for process PID. */
  662. static struct arm_linux_debug_reg_state *
  663. arm_linux_get_debug_reg_state (pid_t pid)
  664. {
  665. return &arm_linux_process_info_get (pid)->state;
  666. }
  667. /* Initialize an ARM hardware break-/watch-point control register value.
  668. BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
  669. type of break-/watch-point; ENABLE indicates whether the point is enabled.
  670. */
  671. static arm_hwbp_control_t
  672. arm_hwbp_control_initialize (unsigned byte_address_select,
  673. arm_hwbp_type hwbp_type,
  674. int enable)
  675. {
  676. gdb_assert ((byte_address_select & ~0xffU) == 0);
  677. gdb_assert (hwbp_type != arm_hwbp_break
  678. || ((byte_address_select & 0xfU) != 0));
  679. return (byte_address_select << 5) | (hwbp_type << 3) | (3 << 1) | enable;
  680. }
  681. /* Does the breakpoint control value CONTROL have the enable bit set? */
  682. static int
  683. arm_hwbp_control_is_enabled (arm_hwbp_control_t control)
  684. {
  685. return control & 0x1;
  686. }
  687. /* Change a breakpoint control word so that it is in the disabled state. */
  688. static arm_hwbp_control_t
  689. arm_hwbp_control_disable (arm_hwbp_control_t control)
  690. {
  691. return control & ~0x1;
  692. }
  693. /* Initialise the hardware breakpoint structure P. The breakpoint will be
  694. enabled, and will point to the placed address of BP_TGT. */
  695. static void
  696. arm_linux_hw_breakpoint_initialize (struct gdbarch *gdbarch,
  697. struct bp_target_info *bp_tgt,
  698. struct arm_linux_hw_breakpoint *p)
  699. {
  700. unsigned mask;
  701. CORE_ADDR address = bp_tgt->placed_address = bp_tgt->reqstd_address;
  702. /* We have to create a mask for the control register which says which bits
  703. of the word pointed to by address to break on. */
  704. if (arm_pc_is_thumb (gdbarch, address))
  705. {
  706. mask = 0x3;
  707. address &= ~1;
  708. }
  709. else
  710. {
  711. mask = 0xf;
  712. address &= ~3;
  713. }
  714. p->address = (unsigned int) address;
  715. p->control = arm_hwbp_control_initialize (mask, arm_hwbp_break, 1);
  716. }
  717. /* Get the ARM hardware breakpoint type from the TYPE value we're
  718. given when asked to set a watchpoint. */
  719. static arm_hwbp_type
  720. arm_linux_get_hwbp_type (enum target_hw_bp_type type)
  721. {
  722. if (type == hw_read)
  723. return arm_hwbp_load;
  724. else if (type == hw_write)
  725. return arm_hwbp_store;
  726. else
  727. return arm_hwbp_access;
  728. }
  729. /* Initialize the hardware breakpoint structure P for a watchpoint at ADDR
  730. to LEN. The type of watchpoint is given in RW. */
  731. static void
  732. arm_linux_hw_watchpoint_initialize (CORE_ADDR addr, int len,
  733. enum target_hw_bp_type type,
  734. struct arm_linux_hw_breakpoint *p)
  735. {
  736. const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
  737. unsigned mask;
  738. gdb_assert (cap != NULL);
  739. gdb_assert (cap->max_wp_length != 0);
  740. mask = (1 << len) - 1;
  741. p->address = (unsigned int) addr;
  742. p->control = arm_hwbp_control_initialize (mask,
  743. arm_linux_get_hwbp_type (type), 1);
  744. }
  745. /* Are two break-/watch-points equal? */
  746. static int
  747. arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint *p1,
  748. const struct arm_linux_hw_breakpoint *p2)
  749. {
  750. return p1->address == p2->address && p1->control == p2->control;
  751. }
  752. /* Callback to mark a watch-/breakpoint to be updated in all threads of
  753. the current process. */
  754. static int
  755. update_registers_callback (struct lwp_info *lwp, int watch, int index)
  756. {
  757. if (lwp->arch_private == NULL)
  758. lwp->arch_private = XCNEW (struct arch_lwp_info);
  759. /* The actual update is done later just before resuming the lwp,
  760. we just mark that the registers need updating. */
  761. if (watch)
  762. lwp->arch_private->wpts_changed[index] = 1;
  763. else
  764. lwp->arch_private->bpts_changed[index] = 1;
  765. /* If the lwp isn't stopped, force it to momentarily pause, so
  766. we can update its breakpoint registers. */
  767. if (!lwp->stopped)
  768. linux_stop_lwp (lwp);
  769. return 0;
  770. }
  771. /* Insert the hardware breakpoint (WATCHPOINT = 0) or watchpoint (WATCHPOINT
  772. =1) BPT for thread TID. */
  773. static void
  774. arm_linux_insert_hw_breakpoint1 (const struct arm_linux_hw_breakpoint* bpt,
  775. int watchpoint)
  776. {
  777. int pid;
  778. ptid_t pid_ptid;
  779. gdb_byte count, i;
  780. struct arm_linux_hw_breakpoint* bpts;
  781. pid = inferior_ptid.pid ();
  782. pid_ptid = ptid_t (pid);
  783. if (watchpoint)
  784. {
  785. count = arm_linux_get_hw_watchpoint_count ();
  786. bpts = arm_linux_get_debug_reg_state (pid)->wpts;
  787. }
  788. else
  789. {
  790. count = arm_linux_get_hw_breakpoint_count ();
  791. bpts = arm_linux_get_debug_reg_state (pid)->bpts;
  792. }
  793. for (i = 0; i < count; ++i)
  794. if (!arm_hwbp_control_is_enabled (bpts[i].control))
  795. {
  796. bpts[i] = *bpt;
  797. iterate_over_lwps (pid_ptid,
  798. [=] (struct lwp_info *info)
  799. {
  800. return update_registers_callback (info, watchpoint,
  801. i);
  802. });
  803. break;
  804. }
  805. gdb_assert (i != count);
  806. }
  807. /* Remove the hardware breakpoint (WATCHPOINT = 0) or watchpoint
  808. (WATCHPOINT = 1) BPT for thread TID. */
  809. static void
  810. arm_linux_remove_hw_breakpoint1 (const struct arm_linux_hw_breakpoint *bpt,
  811. int watchpoint)
  812. {
  813. int pid;
  814. gdb_byte count, i;
  815. ptid_t pid_ptid;
  816. struct arm_linux_hw_breakpoint* bpts;
  817. pid = inferior_ptid.pid ();
  818. pid_ptid = ptid_t (pid);
  819. if (watchpoint)
  820. {
  821. count = arm_linux_get_hw_watchpoint_count ();
  822. bpts = arm_linux_get_debug_reg_state (pid)->wpts;
  823. }
  824. else
  825. {
  826. count = arm_linux_get_hw_breakpoint_count ();
  827. bpts = arm_linux_get_debug_reg_state (pid)->bpts;
  828. }
  829. for (i = 0; i < count; ++i)
  830. if (arm_linux_hw_breakpoint_equal (bpt, bpts + i))
  831. {
  832. bpts[i].control = arm_hwbp_control_disable (bpts[i].control);
  833. iterate_over_lwps (pid_ptid,
  834. [=] (struct lwp_info *info)
  835. {
  836. return update_registers_callback (info, watchpoint,
  837. i);
  838. });
  839. break;
  840. }
  841. gdb_assert (i != count);
  842. }
  843. /* Insert a Hardware breakpoint. */
  844. int
  845. arm_linux_nat_target::insert_hw_breakpoint (struct gdbarch *gdbarch,
  846. struct bp_target_info *bp_tgt)
  847. {
  848. struct arm_linux_hw_breakpoint p;
  849. if (arm_linux_get_hw_breakpoint_count () == 0)
  850. return -1;
  851. arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
  852. arm_linux_insert_hw_breakpoint1 (&p, 0);
  853. return 0;
  854. }
  855. /* Remove a hardware breakpoint. */
  856. int
  857. arm_linux_nat_target::remove_hw_breakpoint (struct gdbarch *gdbarch,
  858. struct bp_target_info *bp_tgt)
  859. {
  860. struct arm_linux_hw_breakpoint p;
  861. if (arm_linux_get_hw_breakpoint_count () == 0)
  862. return -1;
  863. arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
  864. arm_linux_remove_hw_breakpoint1 (&p, 0);
  865. return 0;
  866. }
  867. /* Are we able to use a hardware watchpoint for the LEN bytes starting at
  868. ADDR? */
  869. int
  870. arm_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
  871. {
  872. const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
  873. CORE_ADDR max_wp_length, aligned_addr;
  874. /* Can not set watchpoints for zero or negative lengths. */
  875. if (len <= 0)
  876. return 0;
  877. /* Need to be able to use the ptrace interface. */
  878. if (cap == NULL || cap->wp_count == 0)
  879. return 0;
  880. /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
  881. range covered by a watchpoint. */
  882. max_wp_length = (CORE_ADDR)cap->max_wp_length;
  883. aligned_addr = addr & ~(max_wp_length - 1);
  884. if (aligned_addr + max_wp_length < addr + len)
  885. return 0;
  886. /* The current ptrace interface can only handle watchpoints that are a
  887. power of 2. */
  888. if ((len & (len - 1)) != 0)
  889. return 0;
  890. /* All tests passed so we must be able to set a watchpoint. */
  891. return 1;
  892. }
  893. /* Insert a Hardware breakpoint. */
  894. int
  895. arm_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
  896. enum target_hw_bp_type rw,
  897. struct expression *cond)
  898. {
  899. struct arm_linux_hw_breakpoint p;
  900. if (arm_linux_get_hw_watchpoint_count () == 0)
  901. return -1;
  902. arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
  903. arm_linux_insert_hw_breakpoint1 (&p, 1);
  904. return 0;
  905. }
  906. /* Remove a hardware breakpoint. */
  907. int
  908. arm_linux_nat_target::remove_watchpoint (CORE_ADDR addr,
  909. int len, enum target_hw_bp_type rw,
  910. struct expression *cond)
  911. {
  912. struct arm_linux_hw_breakpoint p;
  913. if (arm_linux_get_hw_watchpoint_count () == 0)
  914. return -1;
  915. arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
  916. arm_linux_remove_hw_breakpoint1 (&p, 1);
  917. return 0;
  918. }
  919. /* What was the data address the target was stopped on accessing. */
  920. bool
  921. arm_linux_nat_target::stopped_data_address (CORE_ADDR *addr_p)
  922. {
  923. siginfo_t siginfo;
  924. int slot;
  925. if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
  926. return false;
  927. /* This must be a hardware breakpoint. */
  928. if (siginfo.si_signo != SIGTRAP
  929. || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
  930. return false;
  931. /* We must be able to set hardware watchpoints. */
  932. if (arm_linux_get_hw_watchpoint_count () == 0)
  933. return 0;
  934. slot = siginfo.si_errno;
  935. /* If we are in a positive slot then we're looking at a breakpoint and not
  936. a watchpoint. */
  937. if (slot >= 0)
  938. return false;
  939. *addr_p = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
  940. return true;
  941. }
  942. /* Has the target been stopped by hitting a watchpoint? */
  943. bool
  944. arm_linux_nat_target::stopped_by_watchpoint ()
  945. {
  946. CORE_ADDR addr;
  947. return stopped_data_address (&addr);
  948. }
  949. bool
  950. arm_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
  951. CORE_ADDR start,
  952. int length)
  953. {
  954. return start <= addr && start + length - 1 >= addr;
  955. }
  956. /* Handle thread creation. We need to copy the breakpoints and watchpoints
  957. in the parent thread to the child thread. */
  958. void
  959. arm_linux_nat_target::low_new_thread (struct lwp_info *lp)
  960. {
  961. int i;
  962. struct arch_lwp_info *info = XCNEW (struct arch_lwp_info);
  963. /* Mark that all the hardware breakpoint/watchpoint register pairs
  964. for this thread need to be initialized. */
  965. for (i = 0; i < MAX_BPTS; i++)
  966. {
  967. info->bpts_changed[i] = 1;
  968. info->wpts_changed[i] = 1;
  969. }
  970. lp->arch_private = info;
  971. }
  972. /* Function to call when a thread is being deleted. */
  973. void
  974. arm_linux_nat_target::low_delete_thread (struct arch_lwp_info *arch_lwp)
  975. {
  976. xfree (arch_lwp);
  977. }
  978. /* Called when resuming a thread.
  979. The hardware debug registers are updated when there is any change. */
  980. void
  981. arm_linux_nat_target::low_prepare_to_resume (struct lwp_info *lwp)
  982. {
  983. int pid, i;
  984. struct arm_linux_hw_breakpoint *bpts, *wpts;
  985. struct arch_lwp_info *arm_lwp_info = lwp->arch_private;
  986. pid = lwp->ptid.lwp ();
  987. bpts = arm_linux_get_debug_reg_state (lwp->ptid.pid ())->bpts;
  988. wpts = arm_linux_get_debug_reg_state (lwp->ptid.pid ())->wpts;
  989. /* NULL means this is the main thread still going through the shell,
  990. or, no watchpoint has been set yet. In that case, there's
  991. nothing to do. */
  992. if (arm_lwp_info == NULL)
  993. return;
  994. for (i = 0; i < arm_linux_get_hw_breakpoint_count (); i++)
  995. if (arm_lwp_info->bpts_changed[i])
  996. {
  997. errno = 0;
  998. if (arm_hwbp_control_is_enabled (bpts[i].control))
  999. if (ptrace (PTRACE_SETHBPREGS, pid,
  1000. (PTRACE_TYPE_ARG3) ((i << 1) + 1), &bpts[i].address) < 0)
  1001. perror_with_name (_("Unexpected error setting breakpoint"));
  1002. if (bpts[i].control != 0)
  1003. if (ptrace (PTRACE_SETHBPREGS, pid,
  1004. (PTRACE_TYPE_ARG3) ((i << 1) + 2), &bpts[i].control) < 0)
  1005. perror_with_name (_("Unexpected error setting breakpoint"));
  1006. arm_lwp_info->bpts_changed[i] = 0;
  1007. }
  1008. for (i = 0; i < arm_linux_get_hw_watchpoint_count (); i++)
  1009. if (arm_lwp_info->wpts_changed[i])
  1010. {
  1011. errno = 0;
  1012. if (arm_hwbp_control_is_enabled (wpts[i].control))
  1013. if (ptrace (PTRACE_SETHBPREGS, pid,
  1014. (PTRACE_TYPE_ARG3) -((i << 1) + 1), &wpts[i].address) < 0)
  1015. perror_with_name (_("Unexpected error setting watchpoint"));
  1016. if (wpts[i].control != 0)
  1017. if (ptrace (PTRACE_SETHBPREGS, pid,
  1018. (PTRACE_TYPE_ARG3) -((i << 1) + 2), &wpts[i].control) < 0)
  1019. perror_with_name (_("Unexpected error setting watchpoint"));
  1020. arm_lwp_info->wpts_changed[i] = 0;
  1021. }
  1022. }
  1023. /* linux_nat_new_fork hook. */
  1024. void
  1025. arm_linux_nat_target::low_new_fork (struct lwp_info *parent, pid_t child_pid)
  1026. {
  1027. pid_t parent_pid;
  1028. struct arm_linux_debug_reg_state *parent_state;
  1029. struct arm_linux_debug_reg_state *child_state;
  1030. /* NULL means no watchpoint has ever been set in the parent. In
  1031. that case, there's nothing to do. */
  1032. if (parent->arch_private == NULL)
  1033. return;
  1034. /* GDB core assumes the child inherits the watchpoints/hw
  1035. breakpoints of the parent, and will remove them all from the
  1036. forked off process. Copy the debug registers mirrors into the
  1037. new process so that all breakpoints and watchpoints can be
  1038. removed together. */
  1039. parent_pid = parent->ptid.pid ();
  1040. parent_state = arm_linux_get_debug_reg_state (parent_pid);
  1041. child_state = arm_linux_get_debug_reg_state (child_pid);
  1042. *child_state = *parent_state;
  1043. }
  1044. void _initialize_arm_linux_nat ();
  1045. void
  1046. _initialize_arm_linux_nat ()
  1047. {
  1048. /* Register the target. */
  1049. linux_target = &the_arm_linux_nat_target;
  1050. add_inf_child_target (&the_arm_linux_nat_target);
  1051. }