linux-low.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /* Internal interfaces for the GNU/Linux specific target code for gdbserver.
  2. Copyright (C) 2002-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. #ifndef GDBSERVER_LINUX_LOW_H
  15. #define GDBSERVER_LINUX_LOW_H
  16. #include "nat/linux-nat.h"
  17. #include "nat/gdb_thread_db.h"
  18. #include <signal.h>
  19. #include "gdbthread.h"
  20. #include "gdb_proc_service.h"
  21. /* Included for ptrace type definitions. */
  22. #include "nat/linux-ptrace.h"
  23. #include "target/waitstatus.h" /* For enum target_stop_reason. */
  24. #include "tracepoint.h"
  25. #include <list>
  26. #define PTRACE_XFER_TYPE long
  27. #ifdef HAVE_LINUX_REGSETS
  28. typedef void (*regset_fill_func) (struct regcache *, void *);
  29. typedef void (*regset_store_func) (struct regcache *, const void *);
  30. enum regset_type {
  31. GENERAL_REGS,
  32. FP_REGS,
  33. EXTENDED_REGS,
  34. OPTIONAL_REGS, /* Do not error if the regset cannot be accessed. */
  35. };
  36. /* The arch's regsets array initializer must be terminated with a NULL
  37. regset. */
  38. #define NULL_REGSET \
  39. { 0, 0, 0, -1, (enum regset_type) -1, NULL, NULL }
  40. struct regset_info
  41. {
  42. int get_request, set_request;
  43. /* If NT_TYPE isn't 0, it will be passed to ptrace as the 3rd
  44. argument and the 4th argument should be "const struct iovec *". */
  45. int nt_type;
  46. int size;
  47. enum regset_type type;
  48. regset_fill_func fill_function;
  49. regset_store_func store_function;
  50. };
  51. /* Aggregation of all the supported regsets of a given
  52. architecture/mode. */
  53. struct regsets_info
  54. {
  55. /* The regsets array. */
  56. struct regset_info *regsets;
  57. /* The number of regsets in the REGSETS array. */
  58. int num_regsets;
  59. /* If we get EIO on a regset, do not try it again. Note the set of
  60. supported regsets may depend on processor mode on biarch
  61. machines. This is a (lazily allocated) array holding one boolean
  62. byte (0/1) per regset, with each element corresponding to the
  63. regset in the REGSETS array above at the same offset. */
  64. char *disabled_regsets;
  65. };
  66. #endif
  67. /* Mapping between the general-purpose registers in `struct user'
  68. format and GDB's register array layout. */
  69. struct usrregs_info
  70. {
  71. /* The number of registers accessible. */
  72. int num_regs;
  73. /* The registers map. */
  74. int *regmap;
  75. };
  76. /* All info needed to access an architecture/mode's registers. */
  77. struct regs_info
  78. {
  79. /* Regset support bitmap: 1 for registers that are transferred as a part
  80. of a regset, 0 for ones that need to be handled individually. This
  81. can be NULL if all registers are transferred with regsets or regsets
  82. are not supported. */
  83. unsigned char *regset_bitmap;
  84. /* Info used when accessing registers with PTRACE_PEEKUSER /
  85. PTRACE_POKEUSER. This can be NULL if all registers are
  86. transferred with regsets .*/
  87. struct usrregs_info *usrregs;
  88. #ifdef HAVE_LINUX_REGSETS
  89. /* Info used when accessing registers with regsets. */
  90. struct regsets_info *regsets_info;
  91. #endif
  92. };
  93. struct process_info_private
  94. {
  95. /* Arch-specific additions. */
  96. struct arch_process_info *arch_private;
  97. /* libthread_db-specific additions. Not NULL if this process has loaded
  98. thread_db, and it is active. */
  99. struct thread_db *thread_db;
  100. /* &_r_debug. 0 if not yet determined. -1 if no PT_DYNAMIC in Phdrs. */
  101. CORE_ADDR r_debug;
  102. };
  103. struct lwp_info;
  104. /* Target ops definitions for a Linux target. */
  105. class linux_process_target : public process_stratum_target
  106. {
  107. public:
  108. int create_inferior (const char *program,
  109. const std::vector<char *> &program_args) override;
  110. void post_create_inferior () override;
  111. int attach (unsigned long pid) override;
  112. int kill (process_info *proc) override;
  113. int detach (process_info *proc) override;
  114. void mourn (process_info *proc) override;
  115. void join (int pid) override;
  116. bool thread_alive (ptid_t pid) override;
  117. void resume (thread_resume *resume_info, size_t n) override;
  118. ptid_t wait (ptid_t ptid, target_waitstatus *status,
  119. target_wait_flags options) override;
  120. void fetch_registers (regcache *regcache, int regno) override;
  121. void store_registers (regcache *regcache, int regno) override;
  122. int prepare_to_access_memory () override;
  123. void done_accessing_memory () override;
  124. int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
  125. int len) override;
  126. int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
  127. int len) override;
  128. void look_up_symbols () override;
  129. void request_interrupt () override;
  130. bool supports_read_auxv () override;
  131. int read_auxv (CORE_ADDR offset, unsigned char *myaddr,
  132. unsigned int len) override;
  133. int insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
  134. int size, raw_breakpoint *bp) override;
  135. int remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
  136. int size, raw_breakpoint *bp) override;
  137. bool stopped_by_sw_breakpoint () override;
  138. bool supports_stopped_by_sw_breakpoint () override;
  139. bool stopped_by_hw_breakpoint () override;
  140. bool supports_stopped_by_hw_breakpoint () override;
  141. bool supports_hardware_single_step () override;
  142. bool stopped_by_watchpoint () override;
  143. CORE_ADDR stopped_data_address () override;
  144. bool supports_read_offsets () override;
  145. int read_offsets (CORE_ADDR *text, CORE_ADDR *data) override;
  146. bool supports_get_tls_address () override;
  147. int get_tls_address (thread_info *thread, CORE_ADDR offset,
  148. CORE_ADDR load_module, CORE_ADDR *address) override;
  149. bool supports_qxfer_osdata () override;
  150. int qxfer_osdata (const char *annex, unsigned char *readbuf,
  151. unsigned const char *writebuf,
  152. CORE_ADDR offset, int len) override;
  153. bool supports_qxfer_siginfo () override;
  154. int qxfer_siginfo (const char *annex, unsigned char *readbuf,
  155. unsigned const char *writebuf,
  156. CORE_ADDR offset, int len) override;
  157. bool supports_non_stop () override;
  158. bool async (bool enable) override;
  159. int start_non_stop (bool enable) override;
  160. bool supports_multi_process () override;
  161. bool supports_fork_events () override;
  162. bool supports_vfork_events () override;
  163. bool supports_exec_events () override;
  164. void handle_new_gdb_connection () override;
  165. int handle_monitor_command (char *mon) override;
  166. int core_of_thread (ptid_t ptid) override;
  167. #if defined PT_GETDSBT || defined PTRACE_GETFDPIC
  168. bool supports_read_loadmap () override;
  169. int read_loadmap (const char *annex, CORE_ADDR offset,
  170. unsigned char *myaddr, unsigned int len) override;
  171. #endif
  172. CORE_ADDR read_pc (regcache *regcache) override;
  173. void write_pc (regcache *regcache, CORE_ADDR pc) override;
  174. bool supports_thread_stopped () override;
  175. bool thread_stopped (thread_info *thread) override;
  176. void pause_all (bool freeze) override;
  177. void unpause_all (bool unfreeze) override;
  178. void stabilize_threads () override;
  179. bool supports_disable_randomization () override;
  180. bool supports_qxfer_libraries_svr4 () override;
  181. int qxfer_libraries_svr4 (const char *annex,
  182. unsigned char *readbuf,
  183. unsigned const char *writebuf,
  184. CORE_ADDR offset, int len) override;
  185. bool supports_agent () override;
  186. #ifdef HAVE_LINUX_BTRACE
  187. btrace_target_info *enable_btrace (thread_info *tp,
  188. const btrace_config *conf) override;
  189. int disable_btrace (btrace_target_info *tinfo) override;
  190. int read_btrace (btrace_target_info *tinfo, buffer *buf,
  191. enum btrace_read_type type) override;
  192. int read_btrace_conf (const btrace_target_info *tinfo,
  193. buffer *buf) override;
  194. #endif
  195. bool supports_range_stepping () override;
  196. bool supports_pid_to_exec_file () override;
  197. const char *pid_to_exec_file (int pid) override;
  198. bool supports_multifs () override;
  199. int multifs_open (int pid, const char *filename, int flags,
  200. mode_t mode) override;
  201. int multifs_unlink (int pid, const char *filename) override;
  202. ssize_t multifs_readlink (int pid, const char *filename, char *buf,
  203. size_t bufsiz) override;
  204. const char *thread_name (ptid_t thread) override;
  205. #if USE_THREAD_DB
  206. bool thread_handle (ptid_t ptid, gdb_byte **handle,
  207. int *handle_len) override;
  208. #endif
  209. thread_info *thread_pending_parent (thread_info *thread) override;
  210. thread_info *thread_pending_child (thread_info *thread) override;
  211. bool supports_catch_syscall () override;
  212. /* Return the information to access registers. This has public
  213. visibility because proc-service uses it. */
  214. virtual const regs_info *get_regs_info () = 0;
  215. private:
  216. /* Handle a GNU/Linux extended wait response. If we see a clone,
  217. fork, or vfork event, we need to add the new LWP to our list
  218. (and return 0 so as not to report the trap to higher layers).
  219. If we see an exec event, we will modify ORIG_EVENT_LWP to point
  220. to a new LWP representing the new program. */
  221. int handle_extended_wait (lwp_info **orig_event_lwp, int wstat);
  222. /* Do low-level handling of the event, and check if this is an event we want
  223. to report. Is so, store it as a pending status in the lwp_info structure
  224. corresponding to LWPID. */
  225. void filter_event (int lwpid, int wstat);
  226. /* Wait for an event from child(ren) WAIT_PTID, and return any that
  227. match FILTER_PTID (leaving others pending). The PTIDs can be:
  228. minus_one_ptid, to specify any child; a pid PTID, specifying all
  229. lwps of a thread group; or a PTID representing a single lwp. Store
  230. the stop status through the status pointer WSTAT. OPTIONS is
  231. passed to the waitpid call. Return 0 if no event was found and
  232. OPTIONS contains WNOHANG. Return -1 if no unwaited-for children
  233. was found. Return the PID of the stopped child otherwise. */
  234. int wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
  235. int *wstatp, int options);
  236. /* Wait for an event from child(ren) PTID. PTIDs can be:
  237. minus_one_ptid, to specify any child; a pid PTID, specifying all
  238. lwps of a thread group; or a PTID representing a single lwp. Store
  239. the stop status through the status pointer WSTAT. OPTIONS is
  240. passed to the waitpid call. Return 0 if no event was found and
  241. OPTIONS contains WNOHANG. Return -1 if no unwaited-for children
  242. was found. Return the PID of the stopped child otherwise. */
  243. int wait_for_event (ptid_t ptid, int *wstatp, int options);
  244. /* Wait for all children to stop for the SIGSTOPs we just queued. */
  245. void wait_for_sigstop ();
  246. /* Wait for process, returns status. */
  247. ptid_t wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
  248. target_wait_flags target_options);
  249. /* Stop all lwps that aren't stopped yet, except EXCEPT, if not NULL.
  250. If SUSPEND, then also increase the suspend count of every LWP,
  251. except EXCEPT. */
  252. void stop_all_lwps (int suspend, lwp_info *except);
  253. /* Stopped LWPs that the client wanted to be running, that don't have
  254. pending statuses, are set to run again, except for EXCEPT, if not
  255. NULL. This undoes a stop_all_lwps call. */
  256. void unstop_all_lwps (int unsuspend, lwp_info *except);
  257. /* Start a step-over operation on LWP. When LWP stopped at a
  258. breakpoint, to make progress, we need to remove the breakpoint out
  259. of the way. If we let other threads run while we do that, they may
  260. pass by the breakpoint location and miss hitting it. To avoid
  261. that, a step-over momentarily stops all threads while LWP is
  262. single-stepped by either hardware or software while the breakpoint
  263. is temporarily uninserted from the inferior. When the single-step
  264. finishes, we reinsert the breakpoint, and let all threads that are
  265. supposed to be running, run again. */
  266. void start_step_over (lwp_info *lwp);
  267. /* If there's a step over in progress, wait until all threads stop
  268. (that is, until the stepping thread finishes its step), and
  269. unsuspend all lwps. The stepping thread ends with its status
  270. pending, which is processed later when we get back to processing
  271. events. */
  272. void complete_ongoing_step_over ();
  273. /* Finish a step-over. Reinsert the breakpoint we had uninserted in
  274. start_step_over, if still there, and delete any single-step
  275. breakpoints we've set, on non hardware single-step targets.
  276. Return true if step over finished. */
  277. bool finish_step_over (lwp_info *lwp);
  278. /* When we finish a step-over, set threads running again. If there's
  279. another thread that may need a step-over, now's the time to start
  280. it. Eventually, we'll move all threads past their breakpoints. */
  281. void proceed_all_lwps ();
  282. /* The reason we resume in the caller, is because we want to be able
  283. to pass lwp->status_pending as WSTAT, and we need to clear
  284. status_pending_p before resuming, otherwise, resume_one_lwp
  285. refuses to resume. */
  286. bool maybe_move_out_of_jump_pad (lwp_info *lwp, int *wstat);
  287. /* Move THREAD out of the jump pad. */
  288. void move_out_of_jump_pad (thread_info *thread);
  289. /* Call low_arch_setup on THREAD. */
  290. void arch_setup_thread (thread_info *thread);
  291. #ifdef HAVE_LINUX_USRREGS
  292. /* Fetch one register. */
  293. void fetch_register (const usrregs_info *usrregs, regcache *regcache,
  294. int regno);
  295. /* Store one register. */
  296. void store_register (const usrregs_info *usrregs, regcache *regcache,
  297. int regno);
  298. #endif
  299. /* Fetch all registers, or just one, from the child process.
  300. If REGNO is -1, do this for all registers, skipping any that are
  301. assumed to have been retrieved by regsets_fetch_inferior_registers,
  302. unless ALL is non-zero.
  303. Otherwise, REGNO specifies which register (so we can save time). */
  304. void usr_fetch_inferior_registers (const regs_info *regs_info,
  305. regcache *regcache, int regno, int all);
  306. /* Store our register values back into the inferior.
  307. If REGNO is -1, do this for all registers, skipping any that are
  308. assumed to have been saved by regsets_store_inferior_registers,
  309. unless ALL is non-zero.
  310. Otherwise, REGNO specifies which register (so we can save time). */
  311. void usr_store_inferior_registers (const regs_info *regs_info,
  312. regcache *regcache, int regno, int all);
  313. /* Return the PC as read from the regcache of LWP, without any
  314. adjustment. */
  315. CORE_ADDR get_pc (lwp_info *lwp);
  316. /* Called when the LWP stopped for a signal/trap. If it stopped for a
  317. trap check what caused it (breakpoint, watchpoint, trace, etc.),
  318. and save the result in the LWP's stop_reason field. If it stopped
  319. for a breakpoint, decrement the PC if necessary on the lwp's
  320. architecture. Returns true if we now have the LWP's stop PC. */
  321. bool save_stop_reason (lwp_info *lwp);
  322. /* Resume execution of LWP. If STEP is nonzero, single-step it. If
  323. SIGNAL is nonzero, give it that signal. */
  324. void resume_one_lwp_throw (lwp_info *lwp, int step, int signal,
  325. siginfo_t *info);
  326. /* Like resume_one_lwp_throw, but no error is thrown if the LWP
  327. disappears while we try to resume it. */
  328. void resume_one_lwp (lwp_info *lwp, int step, int signal, siginfo_t *info);
  329. /* This function is called once per thread. We check the thread's
  330. last resume request, which will tell us whether to resume, step, or
  331. leave the thread stopped. Any signal the client requested to be
  332. delivered has already been enqueued at this point.
  333. If any thread that GDB wants running is stopped at an internal
  334. breakpoint that needs stepping over, we start a step-over operation
  335. on that particular thread, and leave all others stopped. */
  336. void proceed_one_lwp (thread_info *thread, lwp_info *except);
  337. /* This function is called once per thread. We check the thread's
  338. resume request, which will tell us whether to resume, step, or
  339. leave the thread stopped; and what signal, if any, it should be
  340. sent.
  341. For threads which we aren't explicitly told otherwise, we preserve
  342. the stepping flag; this is used for stepping over gdbserver-placed
  343. breakpoints.
  344. If pending_flags was set in any thread, we queue any needed
  345. signals, since we won't actually resume. We already have a pending
  346. event to report, so we don't need to preserve any step requests;
  347. they should be re-issued if necessary. */
  348. void resume_one_thread (thread_info *thread, bool leave_all_stopped);
  349. /* Return true if this lwp has an interesting status pending. */
  350. bool status_pending_p_callback (thread_info *thread, ptid_t ptid);
  351. /* Resume LWPs that are currently stopped without any pending status
  352. to report, but are resumed from the core's perspective. */
  353. void resume_stopped_resumed_lwps (thread_info *thread);
  354. /* Unsuspend THREAD, except EXCEPT, and proceed. */
  355. void unsuspend_and_proceed_one_lwp (thread_info *thread, lwp_info *except);
  356. /* Return true if this lwp still has an interesting status pending.
  357. If not (e.g., it had stopped for a breakpoint that is gone), return
  358. false. */
  359. bool thread_still_has_status_pending (thread_info *thread);
  360. /* Return true if this lwp is to-be-resumed and has an interesting
  361. status pending. */
  362. bool resume_status_pending (thread_info *thread);
  363. /* Return true if this lwp that GDB wants running is stopped at an
  364. internal breakpoint that we need to step over. It assumes that
  365. any required STOP_PC adjustment has already been propagated to
  366. the inferior's regcache. */
  367. bool thread_needs_step_over (thread_info *thread);
  368. /* Single step via hardware or software single step.
  369. Return 1 if hardware single stepping, 0 if software single stepping
  370. or can't single step. */
  371. int single_step (lwp_info* lwp);
  372. /* Return true if THREAD is doing hardware single step. */
  373. bool maybe_hw_step (thread_info *thread);
  374. /* Install breakpoints for software single stepping. */
  375. void install_software_single_step_breakpoints (lwp_info *lwp);
  376. /* Fetch the possibly triggered data watchpoint info and store it in
  377. CHILD.
  378. On some archs, like x86, that use debug registers to set
  379. watchpoints, it's possible that the way to know which watched
  380. address trapped, is to check the register that is used to select
  381. which address to watch. Problem is, between setting the watchpoint
  382. and reading back which data address trapped, the user may change
  383. the set of watchpoints, and, as a consequence, GDB changes the
  384. debug registers in the inferior. To avoid reading back a stale
  385. stopped-data-address when that happens, we cache in LP the fact
  386. that a watchpoint trapped, and the corresponding data address, as
  387. soon as we see CHILD stop with a SIGTRAP. If GDB changes the debug
  388. registers meanwhile, we have the cached data we can rely on. */
  389. bool check_stopped_by_watchpoint (lwp_info *child);
  390. /* Convert a native/host siginfo object, into/from the siginfo in the
  391. layout of the inferiors' architecture. */
  392. void siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo,
  393. int direction);
  394. /* Add a process to the common process list, and set its private
  395. data. */
  396. process_info *add_linux_process (int pid, int attached);
  397. /* Add a new thread. */
  398. lwp_info *add_lwp (ptid_t ptid);
  399. /* Delete a thread. */
  400. void delete_lwp (lwp_info *lwp);
  401. public: /* Make this public because it's used from outside. */
  402. /* Attach to an inferior process. Returns 0 on success, ERRNO on
  403. error. */
  404. int attach_lwp (ptid_t ptid);
  405. private: /* Back to private. */
  406. /* Detach from LWP. */
  407. void detach_one_lwp (lwp_info *lwp);
  408. /* Detect zombie thread group leaders, and "exit" them. We can't
  409. reap their exits until all other threads in the group have
  410. exited. */
  411. void check_zombie_leaders ();
  412. /* Convenience function that is called when the kernel reports an exit
  413. event. This decides whether to report the event to GDB as a
  414. process exit event, a thread exit event, or to suppress the
  415. event. */
  416. ptid_t filter_exit_event (lwp_info *event_child,
  417. target_waitstatus *ourstatus);
  418. /* Returns true if THREAD is stopped in a jump pad, and we can't
  419. move it out, because we need to report the stop event to GDB. For
  420. example, if the user puts a breakpoint in the jump pad, it's
  421. because she wants to debug it. */
  422. bool stuck_in_jump_pad (thread_info *thread);
  423. /* Convenience wrapper. Returns information about LWP's fast tracepoint
  424. collection status. */
  425. fast_tpoint_collect_result linux_fast_tracepoint_collecting
  426. (lwp_info *lwp, fast_tpoint_collect_status *status);
  427. /* This function should only be called if LWP got a SYSCALL_SIGTRAP.
  428. Fill *SYSNO with the syscall nr trapped. */
  429. void get_syscall_trapinfo (lwp_info *lwp, int *sysno);
  430. /* Returns true if GDB is interested in the event_child syscall.
  431. Only to be called when stopped reason is SYSCALL_SIGTRAP. */
  432. bool gdb_catch_this_syscall (lwp_info *event_child);
  433. protected:
  434. /* The architecture-specific "low" methods are listed below. */
  435. /* Architecture-specific setup for the current thread. */
  436. virtual void low_arch_setup () = 0;
  437. /* Return false if we can fetch/store the register, true if we cannot
  438. fetch/store the register. */
  439. virtual bool low_cannot_fetch_register (int regno) = 0;
  440. virtual bool low_cannot_store_register (int regno) = 0;
  441. /* Hook to fetch a register in some non-standard way. Used for
  442. example by backends that have read-only registers with hardcoded
  443. values (e.g., IA64's gr0/fr0/fr1). Returns true if register
  444. REGNO was supplied, false if not, and we should fallback to the
  445. standard ptrace methods. */
  446. virtual bool low_fetch_register (regcache *regcache, int regno);
  447. /* Return true if breakpoints are supported. Such targets must
  448. implement the GET_PC and SET_PC methods. */
  449. virtual bool low_supports_breakpoints ();
  450. virtual CORE_ADDR low_get_pc (regcache *regcache);
  451. virtual void low_set_pc (regcache *regcache, CORE_ADDR newpc);
  452. /* Find the next possible PCs after the current instruction executes.
  453. Targets that override this method should also override
  454. 'supports_software_single_step' to return true. */
  455. virtual std::vector<CORE_ADDR> low_get_next_pcs (regcache *regcache);
  456. /* Return true if there is a breakpoint at PC. */
  457. virtual bool low_breakpoint_at (CORE_ADDR pc) = 0;
  458. /* Breakpoint and watchpoint related functions. See target.h for
  459. comments. */
  460. virtual int low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
  461. int size, raw_breakpoint *bp);
  462. virtual int low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
  463. int size, raw_breakpoint *bp);
  464. virtual bool low_stopped_by_watchpoint ();
  465. virtual CORE_ADDR low_stopped_data_address ();
  466. /* Hooks to reformat register data for PEEKUSR/POKEUSR (in particular
  467. for registers smaller than an xfer unit). */
  468. virtual void low_collect_ptrace_register (regcache *regcache, int regno,
  469. char *buf);
  470. virtual void low_supply_ptrace_register (regcache *regcache, int regno,
  471. const char *buf);
  472. /* Hook to convert from target format to ptrace format and back.
  473. Returns true if any conversion was done; false otherwise.
  474. If DIRECTION is 1, then copy from INF to NATIVE.
  475. If DIRECTION is 0, copy from NATIVE to INF. */
  476. virtual bool low_siginfo_fixup (siginfo_t *native, gdb_byte *inf,
  477. int direction);
  478. /* Hook to call when a new process is created or attached to.
  479. If extra per-process architecture-specific data is needed,
  480. allocate it here. */
  481. virtual arch_process_info *low_new_process ();
  482. /* Hook to call when a process is being deleted. If extra per-process
  483. architecture-specific data is needed, delete it here. */
  484. virtual void low_delete_process (arch_process_info *info);
  485. /* Hook to call when a new thread is detected.
  486. If extra per-thread architecture-specific data is needed,
  487. allocate it here. */
  488. virtual void low_new_thread (lwp_info *);
  489. /* Hook to call when a thread is being deleted. If extra per-thread
  490. architecture-specific data is needed, delete it here. */
  491. virtual void low_delete_thread (arch_lwp_info *);
  492. /* Hook to call, if any, when a new fork is attached. */
  493. virtual void low_new_fork (process_info *parent, process_info *child);
  494. /* Hook to call prior to resuming a thread. */
  495. virtual void low_prepare_to_resume (lwp_info *lwp);
  496. /* Fill ADDRP with the thread area address of LWPID. Returns 0 on
  497. success, -1 on failure. */
  498. virtual int low_get_thread_area (int lwpid, CORE_ADDR *addrp);
  499. /* Returns true if the low target supports range stepping. */
  500. virtual bool low_supports_range_stepping ();
  501. /* Return true if the target supports catch syscall. Such targets
  502. override the low_get_syscall_trapinfo method below. */
  503. virtual bool low_supports_catch_syscall ();
  504. /* Fill *SYSNO with the syscall nr trapped. Only to be called when
  505. inferior is stopped due to SYSCALL_SIGTRAP. */
  506. virtual void low_get_syscall_trapinfo (regcache *regcache, int *sysno);
  507. /* How many bytes the PC should be decremented after a break. */
  508. virtual int low_decr_pc_after_break ();
  509. };
  510. extern linux_process_target *the_linux_target;
  511. #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
  512. #define get_lwp_thread(lwp) ((lwp)->thread)
  513. /* Information about a signal that is to be delivered to a thread. */
  514. struct pending_signal
  515. {
  516. pending_signal (int signal)
  517. : signal {signal}
  518. {};
  519. int signal;
  520. siginfo_t info;
  521. };
  522. /* This struct is recorded in the target_data field of struct thread_info.
  523. On linux ``all_threads'' is keyed by the LWP ID, which we use as the
  524. GDB protocol representation of the thread ID. Threads also have
  525. a "process ID" (poorly named) which is (presently) the same as the
  526. LWP ID.
  527. There is also ``all_processes'' is keyed by the "overall process ID",
  528. which GNU/Linux calls tgid, "thread group ID". */
  529. struct lwp_info
  530. {
  531. /* If this LWP is a fork child that wasn't reported to GDB yet, return
  532. its parent, else nullptr. */
  533. lwp_info *pending_parent () const
  534. {
  535. if (this->fork_relative == nullptr)
  536. return nullptr;
  537. gdb_assert (this->fork_relative->fork_relative == this);
  538. /* In a fork parent/child relationship, the parent has a status pending and
  539. the child does not, and a thread can only be in one such relationship
  540. at most. So we can recognize who is the parent based on which one has
  541. a pending status. */
  542. gdb_assert (!!this->status_pending_p
  543. != !!this->fork_relative->status_pending_p);
  544. if (!this->fork_relative->status_pending_p)
  545. return nullptr;
  546. const target_waitstatus &ws
  547. = this->fork_relative->waitstatus;
  548. gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED
  549. || ws.kind () == TARGET_WAITKIND_VFORKED);
  550. return this->fork_relative;
  551. }
  552. /* If this LWP is the parent of a fork child we haven't reported to GDB yet,
  553. return that child, else nullptr. */
  554. lwp_info *pending_child () const
  555. {
  556. if (this->fork_relative == nullptr)
  557. return nullptr;
  558. gdb_assert (this->fork_relative->fork_relative == this);
  559. /* In a fork parent/child relationship, the parent has a status pending and
  560. the child does not, and a thread can only be in one such relationship
  561. at most. So we can recognize who is the parent based on which one has
  562. a pending status. */
  563. gdb_assert (!!this->status_pending_p
  564. != !!this->fork_relative->status_pending_p);
  565. if (!this->status_pending_p)
  566. return nullptr;
  567. const target_waitstatus &ws = this->waitstatus;
  568. gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED
  569. || ws.kind () == TARGET_WAITKIND_VFORKED);
  570. return this->fork_relative;
  571. }
  572. /* Backlink to the parent object. */
  573. struct thread_info *thread = nullptr;
  574. /* If this flag is set, the next SIGSTOP will be ignored (the
  575. process will be immediately resumed). This means that either we
  576. sent the SIGSTOP to it ourselves and got some other pending event
  577. (so the SIGSTOP is still pending), or that we stopped the
  578. inferior implicitly via PTRACE_ATTACH and have not waited for it
  579. yet. */
  580. int stop_expected = 0;
  581. /* When this is true, we shall not try to resume this thread, even
  582. if last_resume_kind isn't resume_stop. */
  583. int suspended = 0;
  584. /* If this flag is set, the lwp is known to be stopped right now (stop
  585. event already received in a wait()). */
  586. int stopped = 0;
  587. /* Signal whether we are in a SYSCALL_ENTRY or
  588. in a SYSCALL_RETURN event.
  589. Values:
  590. - TARGET_WAITKIND_SYSCALL_ENTRY
  591. - TARGET_WAITKIND_SYSCALL_RETURN */
  592. enum target_waitkind syscall_state = TARGET_WAITKIND_SYSCALL_ENTRY;
  593. /* When stopped is set, the last wait status recorded for this lwp. */
  594. int last_status = 0;
  595. /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for
  596. this LWP's last event, to pass to GDB without any further
  597. processing. This is used to store extended ptrace event
  598. information or exit status until it can be reported to GDB. */
  599. struct target_waitstatus waitstatus;
  600. /* A pointer to the fork child/parent relative. Valid only while
  601. the parent fork event is not reported to higher layers. Used to
  602. avoid wildcard vCont actions resuming a fork child before GDB is
  603. notified about the parent's fork event. */
  604. struct lwp_info *fork_relative = nullptr;
  605. /* When stopped is set, this is where the lwp last stopped, with
  606. decr_pc_after_break already accounted for. If the LWP is
  607. running, this is the address at which the lwp was resumed. */
  608. CORE_ADDR stop_pc = 0;
  609. /* If this flag is set, STATUS_PENDING is a waitstatus that has not yet
  610. been reported. */
  611. int status_pending_p = 0;
  612. int status_pending = 0;
  613. /* The reason the LWP last stopped, if we need to track it
  614. (breakpoint, watchpoint, etc.) */
  615. enum target_stop_reason stop_reason = TARGET_STOPPED_BY_NO_REASON;
  616. /* On architectures where it is possible to know the data address of
  617. a triggered watchpoint, STOPPED_DATA_ADDRESS is non-zero, and
  618. contains such data address. Only valid if STOPPED_BY_WATCHPOINT
  619. is true. */
  620. CORE_ADDR stopped_data_address = 0;
  621. /* If this is non-zero, it is a breakpoint to be reinserted at our next
  622. stop (SIGTRAP stops only). */
  623. CORE_ADDR bp_reinsert = 0;
  624. /* If this flag is set, the last continue operation at the ptrace
  625. level on this process was a single-step. */
  626. int stepping = 0;
  627. /* Range to single step within. This is a copy of the step range
  628. passed along the last resume request. See 'struct
  629. thread_resume'. */
  630. CORE_ADDR step_range_start = 0; /* Inclusive */
  631. CORE_ADDR step_range_end = 0; /* Exclusive */
  632. /* If this flag is set, we need to set the event request flags the
  633. next time we see this LWP stop. */
  634. int must_set_ptrace_flags = 0;
  635. /* A chain of signals that need to be delivered to this process. */
  636. std::list<pending_signal> pending_signals;
  637. /* A link used when resuming. It is initialized from the resume request,
  638. and then processed and cleared in linux_resume_one_lwp. */
  639. struct thread_resume *resume = nullptr;
  640. /* Information bout this lwp's fast tracepoint collection status (is it
  641. currently stopped in the jump pad, and if so, before or at/after the
  642. relocated instruction). Normally, we won't care about this, but we will
  643. if a signal arrives to this lwp while it is collecting. */
  644. fast_tpoint_collect_result collecting_fast_tracepoint
  645. = fast_tpoint_collect_result::not_collecting;
  646. /* A chain of signals that need to be reported to GDB. These were
  647. deferred because the thread was doing a fast tracepoint collect
  648. when they arrived. */
  649. std::list<pending_signal> pending_signals_to_report;
  650. /* When collecting_fast_tracepoint is first found to be 1, we insert
  651. a exit-jump-pad-quickly breakpoint. This is it. */
  652. struct breakpoint *exit_jump_pad_bkpt = nullptr;
  653. #ifdef USE_THREAD_DB
  654. int thread_known = 0;
  655. /* The thread handle, used for e.g. TLS access. Only valid if
  656. THREAD_KNOWN is set. */
  657. td_thrhandle_t th {};
  658. /* The pthread_t handle. */
  659. thread_t thread_handle {};
  660. #endif
  661. /* Arch-specific additions. */
  662. struct arch_lwp_info *arch_private = nullptr;
  663. };
  664. int linux_pid_exe_is_elf_64_file (int pid, unsigned int *machine);
  665. /* Attach to PTID. Returns 0 on success, non-zero otherwise (an
  666. errno). */
  667. int linux_attach_lwp (ptid_t ptid);
  668. struct lwp_info *find_lwp_pid (ptid_t ptid);
  669. /* For linux_stop_lwp see nat/linux-nat.h. */
  670. #ifdef HAVE_LINUX_REGSETS
  671. void initialize_regsets_info (struct regsets_info *regsets_info);
  672. #endif
  673. void initialize_low_arch (void);
  674. void linux_set_pc_32bit (struct regcache *regcache, CORE_ADDR pc);
  675. CORE_ADDR linux_get_pc_32bit (struct regcache *regcache);
  676. void linux_set_pc_64bit (struct regcache *regcache, CORE_ADDR pc);
  677. CORE_ADDR linux_get_pc_64bit (struct regcache *regcache);
  678. /* From thread-db.c */
  679. int thread_db_init (void);
  680. void thread_db_detach (struct process_info *);
  681. void thread_db_mourn (struct process_info *);
  682. int thread_db_handle_monitor_command (char *);
  683. int thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
  684. CORE_ADDR load_module, CORE_ADDR *address);
  685. int thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp);
  686. /* Called from linux-low.c when a clone event is detected. Upon entry,
  687. both the clone and the parent should be stopped. This function does
  688. whatever is required have the clone under thread_db's control. */
  689. void thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid);
  690. bool thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len);
  691. extern int have_ptrace_getregset;
  692. /* Search for the value with type MATCH in the auxv vector with
  693. entries of length WORDSIZE bytes. If found, store the value in
  694. *VALP and return 1. If not found or if there is an error, return
  695. 0. */
  696. int linux_get_auxv (int wordsize, CORE_ADDR match,
  697. CORE_ADDR *valp);
  698. /* Fetch the AT_HWCAP entry from the auxv vector, where entries are length
  699. WORDSIZE. If no entry was found, return zero. */
  700. CORE_ADDR linux_get_hwcap (int wordsize);
  701. /* Fetch the AT_HWCAP2 entry from the auxv vector, where entries are length
  702. WORDSIZE. If no entry was found, return zero. */
  703. CORE_ADDR linux_get_hwcap2 (int wordsize);
  704. #endif /* GDBSERVER_LINUX_LOW_H */