infrun.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* Copyright (C) 1986-2022 Free Software Foundation, Inc.
  2. This file is part of GDB.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef INFRUN_H
  14. #define INFRUN_H 1
  15. #include "gdbthread.h"
  16. #include "symtab.h"
  17. #include "gdbsupport/byte-vector.h"
  18. #include "gdbsupport/intrusive_list.h"
  19. struct target_waitstatus;
  20. struct frame_info;
  21. struct address_space;
  22. struct return_value_info;
  23. struct process_stratum_target;
  24. struct thread_info;
  25. /* True if we are debugging run control. */
  26. extern bool debug_infrun;
  27. /* Print an "infrun" debug statement. */
  28. #define infrun_debug_printf(fmt, ...) \
  29. debug_prefixed_printf_cond (debug_infrun, "infrun", fmt, ##__VA_ARGS__)
  30. /* Print "infrun" start/end debug statements. */
  31. #define INFRUN_SCOPED_DEBUG_START_END(fmt, ...) \
  32. scoped_debug_start_end (debug_infrun, "infrun", fmt, ##__VA_ARGS__)
  33. /* Print "infrun" enter/exit debug statements. */
  34. #define INFRUN_SCOPED_DEBUG_ENTER_EXIT \
  35. scoped_debug_enter_exit (debug_infrun, "infrun")
  36. /* Nonzero if we want to give control to the user when we're notified
  37. of shared library events by the dynamic linker. */
  38. extern int stop_on_solib_events;
  39. /* True if execution commands resume all threads of all processes by
  40. default; otherwise, resume only threads of the current inferior
  41. process. */
  42. extern bool sched_multi;
  43. /* When set, stop the 'step' command if we enter a function which has
  44. no line number information. The normal behavior is that we step
  45. over such function. */
  46. extern bool step_stop_if_no_debug;
  47. /* If set, the inferior should be controlled in non-stop mode. In
  48. this mode, each thread is controlled independently. Execution
  49. commands apply only to the selected thread by default, and stop
  50. events stop only the thread that had the event -- the other threads
  51. are kept running freely. */
  52. extern bool non_stop;
  53. /* When set (default), the target should attempt to disable the
  54. operating system's address space randomization feature when
  55. starting an inferior. */
  56. extern bool disable_randomization;
  57. /* Returns a unique identifier for the current stop. This can be used
  58. to tell whether a command has proceeded the inferior past the
  59. current location. */
  60. extern ULONGEST get_stop_id (void);
  61. /* Reverse execution. */
  62. enum exec_direction_kind
  63. {
  64. EXEC_FORWARD,
  65. EXEC_REVERSE
  66. };
  67. /* The current execution direction. */
  68. extern enum exec_direction_kind execution_direction;
  69. extern void start_remote (int from_tty);
  70. /* Clear out all variables saying what to do when inferior is
  71. continued or stepped. First do this, then set the ones you want,
  72. then call `proceed'. STEP indicates whether we're preparing for a
  73. step/stepi command. */
  74. extern void clear_proceed_status (int step);
  75. extern void proceed (CORE_ADDR, enum gdb_signal);
  76. /* Return a ptid representing the set of threads that we will proceed,
  77. in the perspective of the user/frontend. We may actually resume
  78. fewer threads at first, e.g., if a thread is stopped at a
  79. breakpoint that needs stepping-off, but that should not be visible
  80. to the user/frontend, and neither should the frontend/user be
  81. allowed to proceed any of the threads that happen to be stopped for
  82. internal run control handling, if a previous command wanted them
  83. resumed. */
  84. extern ptid_t user_visible_resume_ptid (int step);
  85. /* Return the process_stratum target that we will proceed, in the
  86. perspective of the user/frontend. If RESUME_PTID is
  87. MINUS_ONE_PTID, then we'll resume all threads of all targets, so
  88. the function returns NULL. Otherwise, we'll be resuming a process
  89. or thread of the current process, so we return the current
  90. inferior's process stratum target. */
  91. extern process_stratum_target *user_visible_resume_target (ptid_t resume_ptid);
  92. /* Return control to GDB when the inferior stops for real. Print
  93. appropriate messages, remove breakpoints, give terminal our modes,
  94. and run the stop hook. Returns true if the stop hook proceeded the
  95. target, false otherwise. */
  96. extern int normal_stop (void);
  97. /* Return the cached copy of the last target/ptid/waitstatus returned
  98. by target_wait(). The data is actually cached by handle_inferior_event(),
  99. which gets called immediately after target_wait(). */
  100. extern void get_last_target_status (process_stratum_target **target,
  101. ptid_t *ptid,
  102. struct target_waitstatus *status);
  103. /* Set the cached copy of the last target/ptid/waitstatus. */
  104. extern void set_last_target_status (process_stratum_target *target, ptid_t ptid,
  105. const target_waitstatus &status);
  106. /* Clear the cached copy of the last ptid/waitstatus returned by
  107. target_wait(). */
  108. extern void nullify_last_target_wait_ptid ();
  109. /* Stop all threads. Only returns after everything is halted.
  110. REASON is a string indicating the reason why we stop all threads, used in
  111. debug messages.
  112. If INF is non-nullptr, stop all threads of that inferior. Otherwise, stop
  113. all threads of all inferiors. */
  114. extern void stop_all_threads (const char *reason, inferior *inf = nullptr);
  115. extern void prepare_for_detach (void);
  116. extern void fetch_inferior_event ();
  117. extern void init_wait_for_inferior (void);
  118. extern void insert_step_resume_breakpoint_at_sal (struct gdbarch *,
  119. struct symtab_and_line ,
  120. struct frame_id);
  121. /* Returns true if we're trying to step past the instruction at
  122. ADDRESS in ASPACE. */
  123. extern int stepping_past_instruction_at (struct address_space *aspace,
  124. CORE_ADDR address);
  125. /* Returns true if thread whose thread number is THREAD is stepping
  126. over a breakpoint. */
  127. extern int thread_is_stepping_over_breakpoint (int thread);
  128. /* Returns true if we're trying to step past an instruction that
  129. triggers a non-steppable watchpoint. */
  130. extern int stepping_past_nonsteppable_watchpoint (void);
  131. /* Record in TP the frame and location we're currently stepping through. */
  132. extern void set_step_info (thread_info *tp,
  133. struct frame_info *frame,
  134. struct symtab_and_line sal);
  135. /* Several print_*_reason helper functions to print why the inferior
  136. has stopped to the passed in UIOUT. */
  137. /* Signal received, print why the inferior has stopped. */
  138. extern void print_signal_received_reason (struct ui_out *uiout,
  139. enum gdb_signal siggnal);
  140. /* Print why the inferior has stopped. We are done with a
  141. step/next/si/ni command, print why the inferior has stopped. */
  142. extern void print_end_stepping_range_reason (struct ui_out *uiout);
  143. /* The inferior was terminated by a signal, print why it stopped. */
  144. extern void print_signal_exited_reason (struct ui_out *uiout,
  145. enum gdb_signal siggnal);
  146. /* The inferior program is finished, print why it stopped. */
  147. extern void print_exited_reason (struct ui_out *uiout, int exitstatus);
  148. /* Reverse execution: target ran out of history info, print why the
  149. inferior has stopped. */
  150. extern void print_no_history_reason (struct ui_out *uiout);
  151. /* Print the result of a function at the end of a 'finish' command.
  152. RV points at an object representing the captured return value/type
  153. and its position in the value history. */
  154. extern void print_return_value (struct ui_out *uiout,
  155. struct return_value_info *rv);
  156. /* Print current location without a level number, if we have changed
  157. functions or hit a breakpoint. Print source line if we have one.
  158. If the execution command captured a return value, print it. If
  159. DISPLAYS is false, do not call 'do_displays'. */
  160. extern void print_stop_event (struct ui_out *uiout, bool displays = true);
  161. /* Pretty print the results of target_wait, for debugging purposes. */
  162. extern void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
  163. const struct target_waitstatus &ws);
  164. extern int signal_stop_state (int);
  165. extern int signal_print_state (int);
  166. extern int signal_pass_state (int);
  167. extern int signal_stop_update (int, int);
  168. extern int signal_print_update (int, int);
  169. extern int signal_pass_update (int, int);
  170. extern void update_signals_program_target (void);
  171. /* Clear the convenience variables associated with the exit of the
  172. inferior. Currently, those variables are $_exitcode and
  173. $_exitsignal. */
  174. extern void clear_exit_convenience_vars (void);
  175. /* Dump LEN bytes at BUF in hex to a string and return it. */
  176. extern std::string displaced_step_dump_bytes (const gdb_byte *buf, size_t len);
  177. extern void update_observer_mode (void);
  178. extern void signal_catch_update (const unsigned int *);
  179. /* In some circumstances we allow a command to specify a numeric
  180. signal. The idea is to keep these circumstances limited so that
  181. users (and scripts) develop portable habits. For comparison,
  182. POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
  183. numeric signal at all is obsolescent. We are slightly more lenient
  184. and allow 1-15 which should match host signal numbers on most
  185. systems. Use of symbolic signal names is strongly encouraged. */
  186. enum gdb_signal gdb_signal_from_command (int num);
  187. /* Enables/disables infrun's async event source in the event loop. */
  188. extern void infrun_async (int enable);
  189. /* Call infrun's event handler the next time through the event
  190. loop. */
  191. extern void mark_infrun_async_event_handler (void);
  192. /* The global chain of threads that need to do a step-over operation
  193. to get past e.g., a breakpoint. */
  194. extern thread_step_over_list global_thread_step_over_list;
  195. /* Remove breakpoints if possible (usually that means, if everything
  196. is stopped). On failure, print a message. */
  197. extern void maybe_remove_breakpoints (void);
  198. /* If a UI was in sync execution mode, and now isn't, restore its
  199. prompt (a synchronous execution command has finished, and we're
  200. ready for input). */
  201. extern void all_uis_check_sync_execution_done (void);
  202. /* If a UI was in sync execution mode, and hasn't displayed the prompt
  203. yet, re-disable its prompt (a synchronous execution command was
  204. started or re-started). */
  205. extern void all_uis_on_sync_execution_starting (void);
  206. /* In all-stop, restart the target if it had to be stopped to
  207. detach. */
  208. extern void restart_after_all_stop_detach (process_stratum_target *proc_target);
  209. /* RAII object to temporarily disable the requirement for target
  210. stacks to commit their resumed threads.
  211. On construction, set process_stratum_target::commit_resumed_state
  212. to false for all process_stratum targets in all target
  213. stacks.
  214. On destruction (or if reset_and_commit() is called), set
  215. process_stratum_target::commit_resumed_state to true for all
  216. process_stratum targets in all target stacks, except those that:
  217. - have no resumed threads
  218. - have a resumed thread with a pending status
  219. target_commit_resumed is not called in the destructor, because its
  220. implementations could throw, and we don't to swallow that error in
  221. a destructor. Instead, the caller should call the
  222. reset_and_commit_resumed() method so that an eventual exception can
  223. propagate. "reset" in the method name refers to the fact that this
  224. method has the same effect as the destructor, in addition to
  225. committing resumes.
  226. The creation of nested scoped_disable_commit_resumed objects is
  227. tracked, such that only the outermost instance actually does
  228. something, for cases like this:
  229. void
  230. inner_func ()
  231. {
  232. scoped_disable_commit_resumed disable;
  233. // do stuff
  234. disable.reset_and_commit ();
  235. }
  236. void
  237. outer_func ()
  238. {
  239. scoped_disable_commit_resumed disable;
  240. for (... each thread ...)
  241. inner_func ();
  242. disable.reset_and_commit ();
  243. }
  244. In this case, we don't want the `disable` destructor in
  245. `inner_func` to require targets to commit resumed threads, so that
  246. the `reset_and_commit()` call in `inner_func` doesn't actually
  247. resume threads. */
  248. struct scoped_disable_commit_resumed
  249. {
  250. explicit scoped_disable_commit_resumed (const char *reason);
  251. ~scoped_disable_commit_resumed ();
  252. DISABLE_COPY_AND_ASSIGN (scoped_disable_commit_resumed);
  253. /* Undoes the disabling done by the ctor, and calls
  254. maybe_call_commit_resumed_all_targets(). */
  255. void reset_and_commit ();
  256. private:
  257. /* Undoes the disabling done by the ctor. */
  258. void reset ();
  259. /* Whether this object has been reset. */
  260. bool m_reset = false;
  261. const char *m_reason;
  262. bool m_prev_enable_commit_resumed;
  263. };
  264. /* Call target_commit_resumed method on all target stacks whose
  265. process_stratum target layer has COMMIT_RESUME_STATE set. */
  266. extern void maybe_call_commit_resumed_all_targets ();
  267. /* RAII object to temporarily enable the requirement for target stacks
  268. to commit their resumed threads. This is the inverse of
  269. scoped_disable_commit_resumed. The constructor calls the
  270. maybe_call_commit_resumed_all_targets function itself, since it's
  271. OK to throw from a constructor. */
  272. struct scoped_enable_commit_resumed
  273. {
  274. explicit scoped_enable_commit_resumed (const char *reason);
  275. ~scoped_enable_commit_resumed ();
  276. DISABLE_COPY_AND_ASSIGN (scoped_enable_commit_resumed);
  277. private:
  278. const char *m_reason;
  279. bool m_prev_enable_commit_resumed;
  280. };
  281. #endif /* INFRUN_H */