breakpoint.h 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  1. /* Data structures associated with breakpoints in GDB.
  2. Copyright (C) 1992-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. #if !defined (BREAKPOINT_H)
  15. #define BREAKPOINT_H 1
  16. #include "frame.h"
  17. #include "value.h"
  18. #include "ax.h"
  19. #include "command.h"
  20. #include "gdbsupport/break-common.h"
  21. #include "probe.h"
  22. #include "location.h"
  23. #include <vector>
  24. #include "gdbsupport/array-view.h"
  25. #include "gdbsupport/filtered-iterator.h"
  26. #include "gdbsupport/function-view.h"
  27. #include "gdbsupport/next-iterator.h"
  28. #include "gdbsupport/iterator-range.h"
  29. #include "gdbsupport/refcounted-object.h"
  30. #include "gdbsupport/safe-iterator.h"
  31. #include "cli/cli-script.h"
  32. struct block;
  33. struct gdbpy_breakpoint_object;
  34. struct gdbscm_breakpoint_object;
  35. struct number_or_range_parser;
  36. struct thread_info;
  37. struct bpstat;
  38. struct bp_location;
  39. struct linespec_result;
  40. struct linespec_sals;
  41. struct inferior;
  42. /* Enum for exception-handling support in 'catch throw', 'catch rethrow',
  43. 'catch catch' and the MI equivalent. */
  44. enum exception_event_kind
  45. {
  46. EX_EVENT_THROW,
  47. EX_EVENT_RETHROW,
  48. EX_EVENT_CATCH
  49. };
  50. /* Why are we removing the breakpoint from the target? */
  51. enum remove_bp_reason
  52. {
  53. /* A regular remove. Remove the breakpoint and forget everything
  54. about it. */
  55. REMOVE_BREAKPOINT,
  56. /* Detach the breakpoints from a fork child. */
  57. DETACH_BREAKPOINT,
  58. };
  59. /* This is the maximum number of bytes a breakpoint instruction can
  60. take. Feel free to increase it. It's just used in a few places to
  61. size arrays that should be independent of the target
  62. architecture. */
  63. #define BREAKPOINT_MAX 16
  64. /* Type of breakpoint. */
  65. enum bptype
  66. {
  67. bp_none = 0, /* Eventpoint has been deleted */
  68. bp_breakpoint, /* Normal breakpoint */
  69. bp_hardware_breakpoint, /* Hardware assisted breakpoint */
  70. bp_single_step, /* Software single-step */
  71. bp_until, /* used by until command */
  72. bp_finish, /* used by finish command */
  73. bp_watchpoint, /* Watchpoint */
  74. bp_hardware_watchpoint, /* Hardware assisted watchpoint */
  75. bp_read_watchpoint, /* read watchpoint, (hardware assisted) */
  76. bp_access_watchpoint, /* access watchpoint, (hardware assisted) */
  77. bp_longjmp, /* secret breakpoint to find longjmp() */
  78. bp_longjmp_resume, /* secret breakpoint to escape longjmp() */
  79. /* Breakpoint placed to the same location(s) like bp_longjmp but used to
  80. protect against stale DUMMY_FRAME. Multiple bp_longjmp_call_dummy and
  81. one bp_call_dummy are chained together by related_breakpoint for each
  82. DUMMY_FRAME. */
  83. bp_longjmp_call_dummy,
  84. /* An internal breakpoint that is installed on the unwinder's
  85. debug hook. */
  86. bp_exception,
  87. /* An internal breakpoint that is set at the point where an
  88. exception will land. */
  89. bp_exception_resume,
  90. /* Used by wait_for_inferior for stepping over subroutine calls,
  91. and for skipping prologues. */
  92. bp_step_resume,
  93. /* Used by wait_for_inferior for stepping over signal
  94. handlers. */
  95. bp_hp_step_resume,
  96. /* Used to detect when a watchpoint expression has gone out of
  97. scope. These breakpoints are usually not visible to the user.
  98. This breakpoint has some interesting properties:
  99. 1) There's always a 1:1 mapping between watchpoints
  100. on local variables and watchpoint_scope breakpoints.
  101. 2) It automatically deletes itself and the watchpoint it's
  102. associated with when hit.
  103. 3) It can never be disabled. */
  104. bp_watchpoint_scope,
  105. /* The breakpoint at the end of a call dummy. See bp_longjmp_call_dummy it
  106. is chained with by related_breakpoint. */
  107. bp_call_dummy,
  108. /* A breakpoint set on std::terminate, that is used to catch
  109. otherwise uncaught exceptions thrown during an inferior call. */
  110. bp_std_terminate,
  111. /* Some dynamic linkers (HP, maybe Solaris) can arrange for special
  112. code in the inferior to run when significant events occur in the
  113. dynamic linker (for example a library is loaded or unloaded).
  114. By placing a breakpoint in this magic code GDB will get control
  115. when these significant events occur. GDB can then re-examine
  116. the dynamic linker's data structures to discover any newly loaded
  117. dynamic libraries. */
  118. bp_shlib_event,
  119. /* Some multi-threaded systems can arrange for a location in the
  120. inferior to be executed when certain thread-related events occur
  121. (such as thread creation or thread death).
  122. By placing a breakpoint at one of these locations, GDB will get
  123. control when these events occur. GDB can then update its thread
  124. lists etc. */
  125. bp_thread_event,
  126. /* On the same principal, an overlay manager can arrange to call a
  127. magic location in the inferior whenever there is an interesting
  128. change in overlay status. GDB can update its overlay tables
  129. and fiddle with breakpoints in overlays when this breakpoint
  130. is hit. */
  131. bp_overlay_event,
  132. /* Master copies of longjmp breakpoints. These are always installed
  133. as soon as an objfile containing longjmp is loaded, but they are
  134. always disabled. While necessary, temporary clones of bp_longjmp
  135. type will be created and enabled. */
  136. bp_longjmp_master,
  137. /* Master copies of std::terminate breakpoints. */
  138. bp_std_terminate_master,
  139. /* Like bp_longjmp_master, but for exceptions. */
  140. bp_exception_master,
  141. bp_catchpoint,
  142. bp_tracepoint,
  143. bp_fast_tracepoint,
  144. bp_static_tracepoint,
  145. /* A dynamic printf stops at the given location, does a formatted
  146. print, then automatically continues. (Although this is sort of
  147. like a macro packaging up standard breakpoint functionality,
  148. GDB doesn't have a way to construct types of breakpoint from
  149. elements of behavior.) */
  150. bp_dprintf,
  151. /* Event for JIT compiled code generation or deletion. */
  152. bp_jit_event,
  153. /* Breakpoint is placed at the STT_GNU_IFUNC resolver. When hit GDB
  154. inserts new bp_gnu_ifunc_resolver_return at the caller.
  155. bp_gnu_ifunc_resolver is still being kept here as a different thread
  156. may still hit it before bp_gnu_ifunc_resolver_return is hit by the
  157. original thread. */
  158. bp_gnu_ifunc_resolver,
  159. /* On its hit GDB now know the resolved address of the target
  160. STT_GNU_IFUNC function. Associated bp_gnu_ifunc_resolver can be
  161. deleted now and the breakpoint moved to the target function entry
  162. point. */
  163. bp_gnu_ifunc_resolver_return,
  164. };
  165. /* States of enablement of breakpoint. */
  166. enum enable_state
  167. {
  168. bp_disabled, /* The eventpoint is inactive, and cannot
  169. trigger. */
  170. bp_enabled, /* The eventpoint is active, and can
  171. trigger. */
  172. bp_call_disabled, /* The eventpoint has been disabled while a
  173. call into the inferior is "in flight",
  174. because some eventpoints interfere with
  175. the implementation of a call on some
  176. targets. The eventpoint will be
  177. automatically enabled and reset when the
  178. call "lands" (either completes, or stops
  179. at another eventpoint). */
  180. };
  181. /* Disposition of breakpoint. Ie: what to do after hitting it. */
  182. enum bpdisp
  183. {
  184. disp_del, /* Delete it */
  185. disp_del_at_next_stop, /* Delete at next stop,
  186. whether hit or not */
  187. disp_disable, /* Disable it */
  188. disp_donttouch /* Leave it alone */
  189. };
  190. /* Status of breakpoint conditions used when synchronizing
  191. conditions with the target. */
  192. enum condition_status
  193. {
  194. condition_unchanged = 0,
  195. condition_modified,
  196. condition_updated
  197. };
  198. /* Information used by targets to insert and remove breakpoints. */
  199. struct bp_target_info
  200. {
  201. /* Address space at which the breakpoint was placed. */
  202. struct address_space *placed_address_space;
  203. /* Address at which the breakpoint was placed. This is normally
  204. the same as REQUESTED_ADDRESS, except when adjustment happens in
  205. gdbarch_breakpoint_from_pc. The most common form of adjustment
  206. is stripping an alternate ISA marker from the PC which is used
  207. to determine the type of breakpoint to insert. */
  208. CORE_ADDR placed_address;
  209. /* Address at which the breakpoint was requested. */
  210. CORE_ADDR reqstd_address;
  211. /* If this is a ranged breakpoint, then this field contains the
  212. length of the range that will be watched for execution. */
  213. int length;
  214. /* If the breakpoint lives in memory and reading that memory would
  215. give back the breakpoint, instead of the original contents, then
  216. the original contents are cached here. Only SHADOW_LEN bytes of
  217. this buffer are valid, and only when the breakpoint is inserted. */
  218. gdb_byte shadow_contents[BREAKPOINT_MAX];
  219. /* The length of the data cached in SHADOW_CONTENTS. */
  220. int shadow_len;
  221. /* The breakpoint's kind. It is used in 'kind' parameter in Z
  222. packets. */
  223. int kind;
  224. /* Conditions the target should evaluate if it supports target-side
  225. breakpoint conditions. These are non-owning pointers. */
  226. std::vector<agent_expr *> conditions;
  227. /* Commands the target should evaluate if it supports target-side
  228. breakpoint commands. These are non-owning pointers. */
  229. std::vector<agent_expr *> tcommands;
  230. /* Flag that is true if the breakpoint should be left in place even
  231. when GDB is not connected. */
  232. int persist;
  233. };
  234. /* GDB maintains two types of information about each breakpoint (or
  235. watchpoint, or other related event). The first type corresponds
  236. to struct breakpoint; this is a relatively high-level structure
  237. which contains the source location(s), stopping conditions, user
  238. commands to execute when the breakpoint is hit, and so forth.
  239. The second type of information corresponds to struct bp_location.
  240. Each breakpoint has one or (eventually) more locations associated
  241. with it, which represent target-specific and machine-specific
  242. mechanisms for stopping the program. For instance, a watchpoint
  243. expression may require multiple hardware watchpoints in order to
  244. catch all changes in the value of the expression being watched. */
  245. enum bp_loc_type
  246. {
  247. bp_loc_software_breakpoint,
  248. bp_loc_hardware_breakpoint,
  249. bp_loc_hardware_watchpoint,
  250. bp_loc_other /* Miscellaneous... */
  251. };
  252. class bp_location : public refcounted_object
  253. {
  254. public:
  255. bp_location () = default;
  256. /* Construct a bp_location with the type inferred from OWNER's
  257. type. */
  258. explicit bp_location (breakpoint *owner);
  259. /* Construct a bp_location with type TYPE. */
  260. bp_location (breakpoint *owner, bp_loc_type type);
  261. virtual ~bp_location () = default;
  262. /* Chain pointer to the next breakpoint location for
  263. the same parent breakpoint. */
  264. bp_location *next = NULL;
  265. /* Type of this breakpoint location. */
  266. bp_loc_type loc_type {};
  267. /* Each breakpoint location must belong to exactly one higher-level
  268. breakpoint. This pointer is NULL iff this bp_location is no
  269. longer attached to a breakpoint. For example, when a breakpoint
  270. is deleted, its locations may still be found in the
  271. moribund_locations list, or if we had stopped for it, in
  272. bpstats. */
  273. breakpoint *owner = NULL;
  274. /* Conditional. Break only if this expression's value is nonzero.
  275. Unlike string form of condition, which is associated with
  276. breakpoint, this is associated with location, since if breakpoint
  277. has several locations, the evaluation of expression can be
  278. different for different locations. Only valid for real
  279. breakpoints; a watchpoint's conditional expression is stored in
  280. the owner breakpoint object. */
  281. expression_up cond;
  282. /* Conditional expression in agent expression
  283. bytecode form. This is used for stub-side breakpoint
  284. condition evaluation. */
  285. agent_expr_up cond_bytecode;
  286. /* Signals that the condition has changed since the last time
  287. we updated the global location list. This means the condition
  288. needs to be sent to the target again. This is used together
  289. with target-side breakpoint conditions.
  290. condition_unchanged: It means there has been no condition changes.
  291. condition_modified: It means this location had its condition modified.
  292. condition_updated: It means we already marked all the locations that are
  293. duplicates of this location and thus we don't need to call
  294. force_breakpoint_reinsertion (...) for this location. */
  295. condition_status condition_changed {};
  296. agent_expr_up cmd_bytecode;
  297. /* Signals that breakpoint conditions and/or commands need to be
  298. re-synced with the target. This has no use other than
  299. target-side breakpoints. */
  300. bool needs_update = false;
  301. /* This location's address is in an unloaded solib, and so this
  302. location should not be inserted. It will be automatically
  303. enabled when that solib is loaded. */
  304. bool shlib_disabled = false;
  305. /* Is this particular location enabled. */
  306. bool enabled = false;
  307. /* Is this particular location disabled because the condition
  308. expression is invalid at this location. For a location to be
  309. reported as enabled, the ENABLED field above has to be true *and*
  310. the DISABLED_BY_COND field has to be false. */
  311. bool disabled_by_cond = false;
  312. /* True if this breakpoint is now inserted. */
  313. bool inserted = false;
  314. /* True if this is a permanent breakpoint. There is a breakpoint
  315. instruction hard-wired into the target's code. Don't try to
  316. write another breakpoint instruction on top of it, or restore its
  317. value. Step over it using the architecture's
  318. gdbarch_skip_permanent_breakpoint method. */
  319. bool permanent = false;
  320. /* True if this is not the first breakpoint in the list
  321. for the given address. location of tracepoint can _never_
  322. be duplicated with other locations of tracepoints and other
  323. kinds of breakpoints, because two locations at the same
  324. address may have different actions, so both of these locations
  325. should be downloaded and so that `tfind N' always works. */
  326. bool duplicate = false;
  327. /* If we someday support real thread-specific breakpoints, then
  328. the breakpoint location will need a thread identifier. */
  329. /* Data for specific breakpoint types. These could be a union, but
  330. simplicity is more important than memory usage for breakpoints. */
  331. /* Architecture associated with this location's address. May be
  332. different from the breakpoint architecture. */
  333. struct gdbarch *gdbarch = NULL;
  334. /* The program space associated with this breakpoint location
  335. address. Note that an address space may be represented in more
  336. than one program space (e.g. each uClinux program will be given
  337. its own program space, but there will only be one address space
  338. for all of them), but we must not insert more than one location
  339. at the same address in the same address space. */
  340. program_space *pspace = NULL;
  341. /* Note that zero is a perfectly valid code address on some platforms
  342. (for example, the mn10200 (OBSOLETE) and mn10300 simulators). NULL
  343. is not a special value for this field. Valid for all types except
  344. bp_loc_other. */
  345. CORE_ADDR address = 0;
  346. /* For hardware watchpoints, the size of the memory region being
  347. watched. For hardware ranged breakpoints, the size of the
  348. breakpoint range. */
  349. int length = 0;
  350. /* Type of hardware watchpoint. */
  351. target_hw_bp_type watchpoint_type {};
  352. /* For any breakpoint type with an address, this is the section
  353. associated with the address. Used primarily for overlay
  354. debugging. */
  355. obj_section *section = NULL;
  356. /* Address at which breakpoint was requested, either by the user or
  357. by GDB for internal breakpoints. This will usually be the same
  358. as ``address'' (above) except for cases in which
  359. ADJUST_BREAKPOINT_ADDRESS has computed a different address at
  360. which to place the breakpoint in order to comply with a
  361. processor's architectual constraints. */
  362. CORE_ADDR requested_address = 0;
  363. /* An additional address assigned with this location. This is currently
  364. only used by STT_GNU_IFUNC resolver breakpoints to hold the address
  365. of the resolver function. */
  366. CORE_ADDR related_address = 0;
  367. /* If the location comes from a probe point, this is the probe associated
  368. with it. */
  369. bound_probe probe {};
  370. gdb::unique_xmalloc_ptr<char> function_name;
  371. /* Details of the placed breakpoint, when inserted. */
  372. bp_target_info target_info {};
  373. /* Similarly, for the breakpoint at an overlay's LMA, if necessary. */
  374. bp_target_info overlay_target_info {};
  375. /* In a non-stop mode, it's possible that we delete a breakpoint,
  376. but as we do that, some still running thread hits that breakpoint.
  377. For that reason, we need to keep locations belonging to deleted
  378. breakpoints for a bit, so that don't report unexpected SIGTRAP.
  379. We can't keep such locations forever, so we use a heuristic --
  380. after we process certain number of inferior events since
  381. breakpoint was deleted, we retire all locations of that breakpoint.
  382. This variable keeps a number of events still to go, when
  383. it becomes 0 this location is retired. */
  384. int events_till_retirement = 0;
  385. /* Line number which was used to place this location.
  386. Breakpoint placed into a comment keeps it's user specified line number
  387. despite ADDRESS resolves into a different line number. */
  388. int line_number = 0;
  389. /* Symtab which was used to place this location. This is used
  390. to find the corresponding source file name. */
  391. struct symtab *symtab = NULL;
  392. /* The symbol found by the location parser, if any. This may be used to
  393. ascertain when an event location was set at a different location than
  394. the one originally selected by parsing, e.g., inlined symbols. */
  395. const struct symbol *symbol = NULL;
  396. /* Similarly, the minimal symbol found by the location parser, if
  397. any. This may be used to ascertain if the location was
  398. originally set on a GNU ifunc symbol. */
  399. const minimal_symbol *msymbol = NULL;
  400. /* The objfile the symbol or minimal symbol were found in. */
  401. const struct objfile *objfile = NULL;
  402. };
  403. /* A policy class for bp_location reference counting. */
  404. struct bp_location_ref_policy
  405. {
  406. static void incref (bp_location *loc)
  407. {
  408. loc->incref ();
  409. }
  410. static void decref (bp_location *loc)
  411. {
  412. gdb_assert (loc->refcount () > 0);
  413. loc->decref ();
  414. if (loc->refcount () == 0)
  415. delete loc;
  416. }
  417. };
  418. /* A gdb::ref_ptr that has been specialized for bp_location. */
  419. typedef gdb::ref_ptr<bp_location, bp_location_ref_policy>
  420. bp_location_ref_ptr;
  421. /* The possible return values for print_bpstat, print_it_normal,
  422. print_it_done, print_it_noop. */
  423. enum print_stop_action
  424. {
  425. /* We printed nothing or we need to do some more analysis. */
  426. PRINT_UNKNOWN = -1,
  427. /* We printed something, and we *do* desire that something to be
  428. followed by a location. */
  429. PRINT_SRC_AND_LOC,
  430. /* We printed something, and we do *not* desire that something to be
  431. followed by a location. */
  432. PRINT_SRC_ONLY,
  433. /* We already printed all we needed to print, don't print anything
  434. else. */
  435. PRINT_NOTHING
  436. };
  437. /* This structure is a collection of function pointers that, if available,
  438. will be called instead of the performing the default action for this
  439. bptype. */
  440. struct breakpoint_ops
  441. {
  442. /* Allocate a location for this breakpoint. */
  443. struct bp_location * (*allocate_location) (struct breakpoint *);
  444. /* Reevaluate a breakpoint. This is necessary after symbols change
  445. (e.g., an executable or DSO was loaded, or the inferior just
  446. started). */
  447. void (*re_set) (struct breakpoint *self);
  448. /* Insert the breakpoint or watchpoint or activate the catchpoint.
  449. Return 0 for success, 1 if the breakpoint, watchpoint or
  450. catchpoint type is not supported, -1 for failure. */
  451. int (*insert_location) (struct bp_location *);
  452. /* Remove the breakpoint/catchpoint that was previously inserted
  453. with the "insert" method above. Return 0 for success, 1 if the
  454. breakpoint, watchpoint or catchpoint type is not supported,
  455. -1 for failure. */
  456. int (*remove_location) (struct bp_location *, enum remove_bp_reason reason);
  457. /* Return true if it the target has stopped due to hitting
  458. breakpoint location BL. This function does not check if we
  459. should stop, only if BL explains the stop. ASPACE is the address
  460. space in which the event occurred, BP_ADDR is the address at
  461. which the inferior stopped, and WS is the target_waitstatus
  462. describing the event. */
  463. int (*breakpoint_hit) (const struct bp_location *bl,
  464. const address_space *aspace,
  465. CORE_ADDR bp_addr,
  466. const target_waitstatus &ws);
  467. /* Check internal conditions of the breakpoint referred to by BS.
  468. If we should not stop for this breakpoint, set BS->stop to 0. */
  469. void (*check_status) (struct bpstat *bs);
  470. /* Tell how many hardware resources (debug registers) are needed
  471. for this breakpoint. If this function is not provided, then
  472. the breakpoint or watchpoint needs one debug register. */
  473. int (*resources_needed) (const struct bp_location *);
  474. /* Tell whether we can downgrade from a hardware watchpoint to a software
  475. one. If not, the user will not be able to enable the watchpoint when
  476. there are not enough hardware resources available. */
  477. int (*works_in_software_mode) (const struct breakpoint *);
  478. /* The normal print routine for this breakpoint, called when we
  479. hit it. */
  480. enum print_stop_action (*print_it) (struct bpstat *bs);
  481. /* Display information about this breakpoint, for "info
  482. breakpoints". */
  483. void (*print_one) (struct breakpoint *, struct bp_location **);
  484. /* Display extra information about this breakpoint, below the normal
  485. breakpoint description in "info breakpoints".
  486. In the example below, the "address range" line was printed
  487. by print_one_detail_ranged_breakpoint.
  488. (gdb) info breakpoints
  489. Num Type Disp Enb Address What
  490. 2 hw breakpoint keep y in main at test-watch.c:70
  491. address range: [0x10000458, 0x100004c7]
  492. */
  493. void (*print_one_detail) (const struct breakpoint *, struct ui_out *);
  494. /* Display information about this breakpoint after setting it
  495. (roughly speaking; this is called from "mention"). */
  496. void (*print_mention) (struct breakpoint *);
  497. /* Print to FP the CLI command that recreates this breakpoint. */
  498. void (*print_recreate) (struct breakpoint *, struct ui_file *fp);
  499. /* Create SALs from location, storing the result in linespec_result.
  500. For an explanation about the arguments, see the function
  501. `create_sals_from_location_default'.
  502. This function is called inside `create_breakpoint'. */
  503. void (*create_sals_from_location) (struct event_location *location,
  504. struct linespec_result *canonical,
  505. enum bptype type_wanted);
  506. /* This method will be responsible for creating a breakpoint given its SALs.
  507. Usually, it just calls `create_breakpoints_sal' (for ordinary
  508. breakpoints). However, there may be some special cases where we might
  509. need to do some tweaks, e.g., see
  510. `strace_marker_create_breakpoints_sal'.
  511. This function is called inside `create_breakpoint'. */
  512. void (*create_breakpoints_sal) (struct gdbarch *,
  513. struct linespec_result *,
  514. gdb::unique_xmalloc_ptr<char>,
  515. gdb::unique_xmalloc_ptr<char>,
  516. enum bptype, enum bpdisp, int, int,
  517. int, const struct breakpoint_ops *,
  518. int, int, int, unsigned);
  519. /* Given the location (second parameter), this method decodes it and
  520. returns the SAL locations related to it. For ordinary
  521. breakpoints, it calls `decode_line_full'. If SEARCH_PSPACE is
  522. not NULL, symbol search is restricted to just that program space.
  523. This function is called inside `location_to_sals'. */
  524. std::vector<symtab_and_line> (*decode_location)
  525. (struct breakpoint *b,
  526. struct event_location *location,
  527. struct program_space *search_pspace);
  528. /* Return true if this breakpoint explains a signal. See
  529. bpstat_explains_signal. */
  530. int (*explains_signal) (struct breakpoint *, enum gdb_signal);
  531. /* Called after evaluating the breakpoint's condition,
  532. and only if it evaluated true. */
  533. void (*after_condition_true) (struct bpstat *bs);
  534. };
  535. /* Helper for breakpoint_ops->print_recreate implementations. Prints
  536. the "thread" or "task" condition of B, and then a newline.
  537. Necessary because most breakpoint implementations accept
  538. thread/task conditions at the end of the spec line, like "break foo
  539. thread 1", which needs outputting before any breakpoint-type
  540. specific extra command necessary for B's recreation. */
  541. extern void print_recreate_thread (struct breakpoint *b, struct ui_file *fp);
  542. enum watchpoint_triggered
  543. {
  544. /* This watchpoint definitely did not trigger. */
  545. watch_triggered_no = 0,
  546. /* Some hardware watchpoint triggered, and it might have been this
  547. one, but we do not know which it was. */
  548. watch_triggered_unknown,
  549. /* This hardware watchpoint definitely did trigger. */
  550. watch_triggered_yes
  551. };
  552. /* Some targets (e.g., embedded PowerPC) need two debug registers to set
  553. a watchpoint over a memory region. If this flag is true, GDB will use
  554. only one register per watchpoint, thus assuming that all accesses that
  555. modify a memory location happen at its starting address. */
  556. extern bool target_exact_watchpoints;
  557. /* bp_location linked list range. */
  558. using bp_location_range = next_range<bp_location>;
  559. /* Note that the ->silent field is not currently used by any commands
  560. (though the code is in there if it was to be, and set_raw_breakpoint
  561. does set it to 0). I implemented it because I thought it would be
  562. useful for a hack I had to put in; I'm going to leave it in because
  563. I can see how there might be times when it would indeed be useful */
  564. /* This is for all kinds of breakpoints. */
  565. struct breakpoint
  566. {
  567. virtual ~breakpoint () = default;
  568. /* Return a range of this breakpoint's locations. */
  569. bp_location_range locations ();
  570. /* Methods associated with this breakpoint. */
  571. const breakpoint_ops *ops = NULL;
  572. breakpoint *next = NULL;
  573. /* Type of breakpoint. */
  574. bptype type = bp_none;
  575. /* Zero means disabled; remember the info but don't break here. */
  576. enum enable_state enable_state = bp_enabled;
  577. /* What to do with this breakpoint after we hit it. */
  578. bpdisp disposition = disp_del;
  579. /* Number assigned to distinguish breakpoints. */
  580. int number = 0;
  581. /* Location(s) associated with this high-level breakpoint. */
  582. bp_location *loc = NULL;
  583. /* True means a silent breakpoint (don't print frame info if we stop
  584. here). */
  585. bool silent = false;
  586. /* True means display ADDR_STRING to the user verbatim. */
  587. bool display_canonical = false;
  588. /* Number of stops at this breakpoint that should be continued
  589. automatically before really stopping. */
  590. int ignore_count = 0;
  591. /* Number of stops at this breakpoint before it will be
  592. disabled. */
  593. int enable_count = 0;
  594. /* Chain of command lines to execute when this breakpoint is
  595. hit. */
  596. counted_command_line commands;
  597. /* Stack depth (address of frame). If nonzero, break only if fp
  598. equals this. */
  599. struct frame_id frame_id = null_frame_id;
  600. /* The program space used to set the breakpoint. This is only set
  601. for breakpoints which are specific to a program space; for
  602. non-thread-specific ordinary breakpoints this is NULL. */
  603. program_space *pspace = NULL;
  604. /* Location we used to set the breakpoint. */
  605. event_location_up location;
  606. /* The filter that should be passed to decode_line_full when
  607. re-setting this breakpoint. This may be NULL. */
  608. gdb::unique_xmalloc_ptr<char> filter;
  609. /* For a ranged breakpoint, the location we used to find the end of
  610. the range. */
  611. event_location_up location_range_end;
  612. /* Architecture we used to set the breakpoint. */
  613. struct gdbarch *gdbarch = NULL;
  614. /* Language we used to set the breakpoint. */
  615. enum language language = language_unknown;
  616. /* Input radix we used to set the breakpoint. */
  617. int input_radix = 0;
  618. /* String form of the breakpoint condition (malloc'd), or NULL if
  619. there is no condition. */
  620. gdb::unique_xmalloc_ptr<char> cond_string;
  621. /* String form of extra parameters, or NULL if there are none.
  622. Malloc'd. */
  623. gdb::unique_xmalloc_ptr<char> extra_string;
  624. /* Holds the address of the related watchpoint_scope breakpoint when
  625. using watchpoints on local variables (might the concept of a
  626. related breakpoint be useful elsewhere, if not just call it the
  627. watchpoint_scope breakpoint or something like that. FIXME). */
  628. breakpoint *related_breakpoint = NULL;
  629. /* Thread number for thread-specific breakpoint, or -1 if don't
  630. care. */
  631. int thread = -1;
  632. /* Ada task number for task-specific breakpoint, or 0 if don't
  633. care. */
  634. int task = 0;
  635. /* Count of the number of times this breakpoint was taken, dumped
  636. with the info, but not used for anything else. Useful for seeing
  637. how many times you hit a break prior to the program aborting, so
  638. you can back up to just before the abort. */
  639. int hit_count = 0;
  640. /* Is breakpoint's condition not yet parsed because we found no
  641. location initially so had no context to parse the condition
  642. in. */
  643. int condition_not_parsed = 0;
  644. /* With a Python scripting enabled GDB, store a reference to the
  645. Python object that has been associated with this breakpoint.
  646. This is always NULL for a GDB that is not script enabled. It can
  647. sometimes be NULL for enabled GDBs as not all breakpoint types
  648. are tracked by the scripting language API. */
  649. gdbpy_breakpoint_object *py_bp_object = NULL;
  650. /* Same as py_bp_object, but for Scheme. */
  651. gdbscm_breakpoint_object *scm_bp_object = NULL;
  652. };
  653. /* An instance of this type is used to represent a watchpoint. */
  654. struct watchpoint : public breakpoint
  655. {
  656. /* String form of exp to use for displaying to the user (malloc'd),
  657. or NULL if none. */
  658. gdb::unique_xmalloc_ptr<char> exp_string;
  659. /* String form to use for reparsing of EXP (malloc'd) or NULL. */
  660. gdb::unique_xmalloc_ptr<char> exp_string_reparse;
  661. /* The expression we are watching, or NULL if not a watchpoint. */
  662. expression_up exp;
  663. /* The largest block within which it is valid, or NULL if it is
  664. valid anywhere (e.g. consists just of global symbols). */
  665. const struct block *exp_valid_block;
  666. /* The conditional expression if any. */
  667. expression_up cond_exp;
  668. /* The largest block within which it is valid, or NULL if it is
  669. valid anywhere (e.g. consists just of global symbols). */
  670. const struct block *cond_exp_valid_block;
  671. /* Value of the watchpoint the last time we checked it, or NULL when
  672. we do not know the value yet or the value was not readable. VAL
  673. is never lazy. */
  674. value_ref_ptr val;
  675. /* True if VAL is valid. If VAL_VALID is set but VAL is NULL,
  676. then an error occurred reading the value. */
  677. bool val_valid;
  678. /* When watching the location of a bitfield, contains the offset and size of
  679. the bitfield. Otherwise contains 0. */
  680. int val_bitpos;
  681. int val_bitsize;
  682. /* Holds the frame address which identifies the frame this
  683. watchpoint should be evaluated in, or `null' if the watchpoint
  684. should be evaluated on the outermost frame. */
  685. struct frame_id watchpoint_frame;
  686. /* Holds the thread which identifies the frame this watchpoint
  687. should be considered in scope for, or `null_ptid' if the
  688. watchpoint should be evaluated in all threads. */
  689. ptid_t watchpoint_thread;
  690. /* For hardware watchpoints, the triggered status according to the
  691. hardware. */
  692. enum watchpoint_triggered watchpoint_triggered;
  693. /* Whether this watchpoint is exact (see
  694. target_exact_watchpoints). */
  695. int exact;
  696. /* The mask address for a masked hardware watchpoint. */
  697. CORE_ADDR hw_wp_mask;
  698. };
  699. /* Return true if BPT is either a software breakpoint or a hardware
  700. breakpoint. */
  701. extern bool is_breakpoint (const struct breakpoint *bpt);
  702. /* Return true if BPT is of any watchpoint kind, hardware or
  703. software. */
  704. extern bool is_watchpoint (const struct breakpoint *bpt);
  705. /* Return true if BPT is a C++ exception catchpoint (catch
  706. catch/throw/rethrow). */
  707. extern bool is_exception_catchpoint (breakpoint *bp);
  708. /* An instance of this type is used to represent all kinds of
  709. tracepoints. */
  710. struct tracepoint : public breakpoint
  711. {
  712. /* Number of times this tracepoint should single-step and collect
  713. additional data. */
  714. long step_count;
  715. /* Number of times this tracepoint should be hit before
  716. disabling/ending. */
  717. int pass_count;
  718. /* The number of the tracepoint on the target. */
  719. int number_on_target;
  720. /* The total space taken by all the trace frames for this
  721. tracepoint. */
  722. ULONGEST traceframe_usage;
  723. /* The static tracepoint marker id, if known. */
  724. std::string static_trace_marker_id;
  725. /* LTTng/UST allow more than one marker with the same ID string,
  726. although it unadvised because it confuses tools. When setting
  727. static tracepoints by marker ID, this will record the index in
  728. the array of markers we found for the given marker ID for which
  729. this static tracepoint corresponds. When resetting breakpoints,
  730. we will use this index to try to find the same marker again. */
  731. int static_trace_marker_id_idx;
  732. };
  733. /* The following stuff is an abstract data type "bpstat" ("breakpoint
  734. status"). This provides the ability to determine whether we have
  735. stopped at a breakpoint, and what we should do about it. */
  736. /* Clears a chain of bpstat, freeing storage
  737. of each. */
  738. extern void bpstat_clear (bpstat **);
  739. /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
  740. is part of the bpstat is copied as well. */
  741. extern bpstat *bpstat_copy (bpstat *);
  742. /* Build the (raw) bpstat chain for the stop information given by ASPACE,
  743. BP_ADDR, and WS. Returns the head of the bpstat chain. */
  744. extern bpstat *build_bpstat_chain (const address_space *aspace,
  745. CORE_ADDR bp_addr,
  746. const target_waitstatus &ws);
  747. /* Get a bpstat associated with having just stopped at address
  748. BP_ADDR in thread PTID. STOP_CHAIN may be supplied as a previously
  749. computed stop chain or NULL, in which case the stop chain will be
  750. computed using build_bpstat_chain.
  751. Determine whether we stopped at a breakpoint, etc, or whether we
  752. don't understand this stop. Result is a chain of bpstat's such
  753. that:
  754. if we don't understand the stop, the result is a null pointer.
  755. if we understand why we stopped, the result is not null.
  756. Each element of the chain refers to a particular breakpoint or
  757. watchpoint at which we have stopped. (We may have stopped for
  758. several reasons concurrently.)
  759. Each element of the chain has valid next, breakpoint_at,
  760. commands, FIXME??? fields.
  761. watchpoints_triggered must be called beforehand to set up each
  762. watchpoint's watchpoint_triggered value.
  763. */
  764. extern bpstat *bpstat_stop_status (const address_space *aspace,
  765. CORE_ADDR pc, thread_info *thread,
  766. const target_waitstatus &ws,
  767. bpstat *stop_chain = nullptr);
  768. /* Like bpstat_stop_status, but clears all watchpoints'
  769. watchpoint_triggered flag. Unlike with bpstat_stop_status, there's
  770. no need to call watchpoint_triggered beforehand. You'll typically
  771. use this variant when handling a known-non-watchpoint event, like a
  772. fork or exec event. */
  773. extern bpstat *bpstat_stop_status_nowatch (const address_space *aspace,
  774. CORE_ADDR bp_addr,
  775. thread_info *thread,
  776. const target_waitstatus &ws);
  777. /* This bpstat_what stuff tells wait_for_inferior what to do with a
  778. breakpoint (a challenging task).
  779. The enum values order defines priority-like order of the actions.
  780. Once you've decided that some action is appropriate, you'll never
  781. go back and decide something of a lower priority is better. Each
  782. of these actions is mutually exclusive with the others. That
  783. means, that if you find yourself adding a new action class here and
  784. wanting to tell GDB that you have two simultaneous actions to
  785. handle, something is wrong, and you probably don't actually need a
  786. new action type.
  787. Note that a step resume breakpoint overrides another breakpoint of
  788. signal handling (see comment in wait_for_inferior at where we set
  789. the step_resume breakpoint). */
  790. enum bpstat_what_main_action
  791. {
  792. /* Perform various other tests; that is, this bpstat does not
  793. say to perform any action (e.g. failed watchpoint and nothing
  794. else). */
  795. BPSTAT_WHAT_KEEP_CHECKING,
  796. /* Remove breakpoints, single step once, then put them back in and
  797. go back to what we were doing. It's possible that this should
  798. be removed from the main_action and put into a separate field,
  799. to more cleanly handle
  800. BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE. */
  801. BPSTAT_WHAT_SINGLE,
  802. /* Set longjmp_resume breakpoint, remove all other breakpoints,
  803. and continue. The "remove all other breakpoints" part is
  804. required if we are also stepping over another breakpoint as
  805. well as doing the longjmp handling. */
  806. BPSTAT_WHAT_SET_LONGJMP_RESUME,
  807. /* Clear longjmp_resume breakpoint, then handle as
  808. BPSTAT_WHAT_KEEP_CHECKING. */
  809. BPSTAT_WHAT_CLEAR_LONGJMP_RESUME,
  810. /* Clear step resume breakpoint, and keep checking. */
  811. BPSTAT_WHAT_STEP_RESUME,
  812. /* Rather than distinguish between noisy and silent stops here, it
  813. might be cleaner to have bpstat_print make that decision (also
  814. taking into account stop_print_frame and source_only). But the
  815. implications are a bit scary (interaction with auto-displays,
  816. etc.), so I won't try it. */
  817. /* Stop silently. */
  818. BPSTAT_WHAT_STOP_SILENT,
  819. /* Stop and print. */
  820. BPSTAT_WHAT_STOP_NOISY,
  821. /* Clear step resume breakpoint, and keep checking. High-priority
  822. step-resume breakpoints are used when even if there's a user
  823. breakpoint at the current PC when we set the step-resume
  824. breakpoint, we don't want to re-handle any breakpoint other
  825. than the step-resume when it's hit; instead we want to move
  826. past the breakpoint. This is used in the case of skipping
  827. signal handlers. */
  828. BPSTAT_WHAT_HP_STEP_RESUME,
  829. };
  830. /* An enum indicating the kind of "stack dummy" stop. This is a bit
  831. of a misnomer because only one kind of truly a stack dummy. */
  832. enum stop_stack_kind
  833. {
  834. /* We didn't stop at a stack dummy breakpoint. */
  835. STOP_NONE = 0,
  836. /* Stopped at a stack dummy. */
  837. STOP_STACK_DUMMY,
  838. /* Stopped at std::terminate. */
  839. STOP_STD_TERMINATE
  840. };
  841. struct bpstat_what
  842. {
  843. enum bpstat_what_main_action main_action;
  844. /* Did we hit a call dummy breakpoint? This only goes with a
  845. main_action of BPSTAT_WHAT_STOP_SILENT or
  846. BPSTAT_WHAT_STOP_NOISY (the concept of continuing from a call
  847. dummy without popping the frame is not a useful one). */
  848. enum stop_stack_kind call_dummy;
  849. /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME and
  850. BPSTAT_WHAT_CLEAR_LONGJMP_RESUME. True if we are handling a
  851. longjmp, false if we are handling an exception. */
  852. bool is_longjmp;
  853. };
  854. /* Tell what to do about this bpstat. */
  855. struct bpstat_what bpstat_what (bpstat *);
  856. /* Run breakpoint event callbacks associated with the breakpoints that
  857. triggered. */
  858. extern void bpstat_run_callbacks (bpstat *bs_head);
  859. /* Find the bpstat associated with a breakpoint. NULL otherwise. */
  860. bpstat *bpstat_find_breakpoint (bpstat *, struct breakpoint *);
  861. /* True if a signal that we got in target_wait() was due to
  862. circumstances explained by the bpstat; the signal is therefore not
  863. random. */
  864. extern bool bpstat_explains_signal (bpstat *, enum gdb_signal);
  865. /* True if this bpstat causes a stop. */
  866. extern bool bpstat_causes_stop (bpstat *);
  867. /* True if we should step constantly (e.g. watchpoints on machines
  868. without hardware support). This isn't related to a specific bpstat,
  869. just to things like whether watchpoints are set. */
  870. extern bool bpstat_should_step ();
  871. /* Print a message indicating what happened. Returns nonzero to
  872. say that only the source line should be printed after this (zero
  873. return means print the frame as well as the source line). */
  874. extern enum print_stop_action bpstat_print (bpstat *, int);
  875. /* Put in *NUM the breakpoint number of the first breakpoint we are
  876. stopped at. *BSP upon return is a bpstat which points to the
  877. remaining breakpoints stopped at (but which is not guaranteed to be
  878. good for anything but further calls to bpstat_num).
  879. Return 0 if passed a bpstat which does not indicate any breakpoints.
  880. Return -1 if stopped at a breakpoint that has been deleted since
  881. we set it.
  882. Return 1 otherwise. */
  883. extern int bpstat_num (bpstat **, int *);
  884. /* Perform actions associated with the stopped inferior. Actually, we
  885. just use this for breakpoint commands. Perhaps other actions will
  886. go here later, but this is executed at a late time (from the
  887. command loop). */
  888. extern void bpstat_do_actions (void);
  889. /* Modify all entries of STOP_BPSTAT of INFERIOR_PTID so that the actions will
  890. not be performed. */
  891. extern void bpstat_clear_actions (void);
  892. /* Implementation: */
  893. /* Values used to tell the printing routine how to behave for this
  894. bpstat. */
  895. enum bp_print_how
  896. {
  897. /* This is used when we want to do a normal printing of the reason
  898. for stopping. The output will depend on the type of eventpoint
  899. we are dealing with. This is the default value, most commonly
  900. used. */
  901. print_it_normal,
  902. /* This is used when nothing should be printed for this bpstat
  903. entry. */
  904. print_it_noop,
  905. /* This is used when everything which needs to be printed has
  906. already been printed. But we still want to print the frame. */
  907. print_it_done
  908. };
  909. struct bpstat
  910. {
  911. bpstat ();
  912. bpstat (struct bp_location *bl, bpstat ***bs_link_pointer);
  913. bpstat (const bpstat &);
  914. bpstat &operator= (const bpstat &) = delete;
  915. /* Linked list because there can be more than one breakpoint at
  916. the same place, and a bpstat reflects the fact that all have
  917. been hit. */
  918. bpstat *next;
  919. /* Location that caused the stop. Locations are refcounted, so
  920. this will never be NULL. Note that this location may end up
  921. detached from a breakpoint, but that does not necessary mean
  922. that the struct breakpoint is gone. E.g., consider a
  923. watchpoint with a condition that involves an inferior function
  924. call. Watchpoint locations are recreated often (on resumes,
  925. hence on infcalls too). Between creating the bpstat and after
  926. evaluating the watchpoint condition, this location may hence
  927. end up detached from its original owner watchpoint, even though
  928. the watchpoint is still listed. If it's condition evaluates as
  929. true, we still want this location to cause a stop, and we will
  930. still need to know which watchpoint it was originally attached.
  931. What this means is that we should not (in most cases) follow
  932. the `bpstat->bp_location->owner' link, but instead use the
  933. `breakpoint_at' field below. */
  934. bp_location_ref_ptr bp_location_at;
  935. /* Breakpoint that caused the stop. This is nullified if the
  936. breakpoint ends up being deleted. See comments on
  937. `bp_location_at' above for why do we need this field instead of
  938. following the location's owner. */
  939. struct breakpoint *breakpoint_at;
  940. /* The associated command list. */
  941. counted_command_line commands;
  942. /* Old value associated with a watchpoint. */
  943. value_ref_ptr old_val;
  944. /* Nonzero if this breakpoint tells us to print the frame. */
  945. char print;
  946. /* Nonzero if this breakpoint tells us to stop. */
  947. char stop;
  948. /* Tell bpstat_print and print_bp_stop_message how to print stuff
  949. associated with this element of the bpstat chain. */
  950. enum bp_print_how print_it;
  951. };
  952. enum inf_context
  953. {
  954. inf_starting,
  955. inf_running,
  956. inf_exited,
  957. inf_execd
  958. };
  959. /* The possible return values for breakpoint_here_p.
  960. We guarantee that zero always means "no breakpoint here". */
  961. enum breakpoint_here
  962. {
  963. no_breakpoint_here = 0,
  964. ordinary_breakpoint_here,
  965. permanent_breakpoint_here
  966. };
  967. /* Prototypes for breakpoint-related functions. */
  968. extern enum breakpoint_here breakpoint_here_p (const address_space *,
  969. CORE_ADDR);
  970. /* Return true if an enabled breakpoint exists in the range defined by
  971. ADDR and LEN, in ASPACE. */
  972. extern int breakpoint_in_range_p (const address_space *aspace,
  973. CORE_ADDR addr, ULONGEST len);
  974. extern int moribund_breakpoint_here_p (const address_space *, CORE_ADDR);
  975. extern int breakpoint_inserted_here_p (const address_space *,
  976. CORE_ADDR);
  977. extern int software_breakpoint_inserted_here_p (const address_space *,
  978. CORE_ADDR);
  979. /* Return non-zero iff there is a hardware breakpoint inserted at
  980. PC. */
  981. extern int hardware_breakpoint_inserted_here_p (const address_space *,
  982. CORE_ADDR);
  983. /* Check whether any location of BP is inserted at PC. */
  984. extern int breakpoint_has_location_inserted_here (struct breakpoint *bp,
  985. const address_space *aspace,
  986. CORE_ADDR pc);
  987. extern int single_step_breakpoint_inserted_here_p (const address_space *,
  988. CORE_ADDR);
  989. /* Returns true if there's a hardware watchpoint or access watchpoint
  990. inserted in the range defined by ADDR and LEN. */
  991. extern int hardware_watchpoint_inserted_in_range (const address_space *,
  992. CORE_ADDR addr,
  993. ULONGEST len);
  994. /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
  995. same breakpoint location. In most targets, this can only be true
  996. if ASPACE1 matches ASPACE2. On targets that have global
  997. breakpoints, the address space doesn't really matter. */
  998. extern int breakpoint_address_match (const address_space *aspace1,
  999. CORE_ADDR addr1,
  1000. const address_space *aspace2,
  1001. CORE_ADDR addr2);
  1002. extern void until_break_command (const char *, int, int);
  1003. /* Initialize a struct bp_location. */
  1004. extern void update_breakpoint_locations
  1005. (struct breakpoint *b,
  1006. struct program_space *filter_pspace,
  1007. gdb::array_view<const symtab_and_line> sals,
  1008. gdb::array_view<const symtab_and_line> sals_end);
  1009. extern void breakpoint_re_set (void);
  1010. extern void breakpoint_re_set_thread (struct breakpoint *);
  1011. extern void delete_breakpoint (struct breakpoint *);
  1012. struct breakpoint_deleter
  1013. {
  1014. void operator() (struct breakpoint *b) const
  1015. {
  1016. delete_breakpoint (b);
  1017. }
  1018. };
  1019. typedef std::unique_ptr<struct breakpoint, breakpoint_deleter> breakpoint_up;
  1020. extern breakpoint_up set_momentary_breakpoint
  1021. (struct gdbarch *, struct symtab_and_line, struct frame_id, enum bptype);
  1022. extern breakpoint_up set_momentary_breakpoint_at_pc
  1023. (struct gdbarch *, CORE_ADDR pc, enum bptype type);
  1024. extern struct breakpoint *clone_momentary_breakpoint (struct breakpoint *bpkt);
  1025. extern void set_ignore_count (int, int, int);
  1026. extern void breakpoint_init_inferior (enum inf_context);
  1027. extern void breakpoint_auto_delete (bpstat *);
  1028. /* Return the chain of command lines to execute when this breakpoint
  1029. is hit. */
  1030. extern struct command_line *breakpoint_commands (struct breakpoint *b);
  1031. /* Return a string image of DISP. The string is static, and thus should
  1032. NOT be deallocated after use. */
  1033. const char *bpdisp_text (enum bpdisp disp);
  1034. extern void break_command (const char *, int);
  1035. extern void watch_command_wrapper (const char *, int, bool);
  1036. extern void awatch_command_wrapper (const char *, int, bool);
  1037. extern void rwatch_command_wrapper (const char *, int, bool);
  1038. extern void tbreak_command (const char *, int);
  1039. extern struct breakpoint_ops base_breakpoint_ops;
  1040. extern struct breakpoint_ops bkpt_breakpoint_ops;
  1041. extern struct breakpoint_ops tracepoint_breakpoint_ops;
  1042. extern struct breakpoint_ops dprintf_breakpoint_ops;
  1043. extern void initialize_breakpoint_ops (void);
  1044. /* Arguments to pass as context to some catch command handlers. */
  1045. #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
  1046. #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
  1047. /* Like add_cmd, but add the command to both the "catch" and "tcatch"
  1048. lists, and pass some additional user data to the command
  1049. function. */
  1050. extern void
  1051. add_catch_command (const char *name, const char *docstring,
  1052. cmd_func_ftype *func,
  1053. completer_ftype *completer,
  1054. void *user_data_catch,
  1055. void *user_data_tcatch);
  1056. /* Initialize a breakpoint struct for Ada exception catchpoints. */
  1057. extern void
  1058. init_ada_exception_breakpoint (struct breakpoint *b,
  1059. struct gdbarch *gdbarch,
  1060. struct symtab_and_line sal,
  1061. const char *addr_string,
  1062. const struct breakpoint_ops *ops,
  1063. int tempflag,
  1064. int enabled,
  1065. int from_tty);
  1066. /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMP
  1067. is true, then make the breakpoint temporary. If COND_STRING is
  1068. not NULL, then store it in the breakpoint. OPS, if not NULL, is
  1069. the breakpoint_ops structure associated to the catchpoint. */
  1070. extern void init_catchpoint (struct breakpoint *b,
  1071. struct gdbarch *gdbarch, bool temp,
  1072. const char *cond_string,
  1073. const struct breakpoint_ops *ops);
  1074. /* Add breakpoint B on the breakpoint list, and notify the user, the
  1075. target and breakpoint_created observers of its existence. If
  1076. INTERNAL is non-zero, the breakpoint number will be allocated from
  1077. the internal breakpoint count. If UPDATE_GLL is non-zero,
  1078. update_global_location_list will be called. */
  1079. extern void install_breakpoint (int internal, std::unique_ptr<breakpoint> &&b,
  1080. int update_gll);
  1081. /* Returns the breakpoint ops appropriate for use with with LOCATION and
  1082. according to IS_TRACEPOINT. Use this to ensure, for example, that you pass
  1083. the correct ops to create_breakpoint for probe locations. If LOCATION is
  1084. NULL, returns bkpt_breakpoint_ops (or tracepoint_breakpoint_ops, if
  1085. IS_TRACEPOINT is true). */
  1086. extern const struct breakpoint_ops *breakpoint_ops_for_event_location
  1087. (const struct event_location *location, bool is_tracepoint);
  1088. /* Flags that can be passed down to create_breakpoint, etc., to affect
  1089. breakpoint creation in several ways. */
  1090. enum breakpoint_create_flags
  1091. {
  1092. /* We're adding a breakpoint to our tables that is already
  1093. inserted in the target. */
  1094. CREATE_BREAKPOINT_FLAGS_INSERTED = 1 << 0
  1095. };
  1096. /* Set a breakpoint. This function is shared between CLI and MI functions
  1097. for setting a breakpoint at LOCATION.
  1098. This function has two major modes of operations, selected by the
  1099. PARSE_EXTRA parameter.
  1100. If PARSE_EXTRA is zero, LOCATION is just the breakpoint's location,
  1101. with condition, thread, and extra string specified by the COND_STRING,
  1102. THREAD, and EXTRA_STRING parameters.
  1103. If PARSE_EXTRA is non-zero, this function will attempt to extract
  1104. the condition, thread, and extra string from EXTRA_STRING, ignoring
  1105. the similarly named parameters.
  1106. If FORCE_CONDITION is true, the condition is accepted even when it is
  1107. invalid at all of the locations. However, if PARSE_EXTRA is non-zero,
  1108. the FORCE_CONDITION parameter is ignored and the corresponding argument
  1109. is parsed from EXTRA_STRING.
  1110. If INTERNAL is non-zero, the breakpoint number will be allocated
  1111. from the internal breakpoint count.
  1112. Returns true if any breakpoint was created; false otherwise. */
  1113. extern int create_breakpoint (struct gdbarch *gdbarch,
  1114. struct event_location *location,
  1115. const char *cond_string, int thread,
  1116. const char *extra_string,
  1117. bool force_condition,
  1118. int parse_extra,
  1119. int tempflag, enum bptype wanted_type,
  1120. int ignore_count,
  1121. enum auto_boolean pending_break_support,
  1122. const struct breakpoint_ops *ops,
  1123. int from_tty,
  1124. int enabled,
  1125. int internal, unsigned flags);
  1126. extern void insert_breakpoints (void);
  1127. extern int remove_breakpoints (void);
  1128. /* Remove breakpoints of inferior INF. */
  1129. extern void remove_breakpoints_inf (inferior *inf);
  1130. /* This function can be used to update the breakpoint package's state
  1131. after an exec() system call has been executed.
  1132. This function causes the following:
  1133. - All eventpoints are marked "not inserted".
  1134. - All eventpoints with a symbolic address are reset such that
  1135. the symbolic address must be reevaluated before the eventpoints
  1136. can be reinserted.
  1137. - The solib breakpoints are explicitly removed from the breakpoint
  1138. list.
  1139. - A step-resume breakpoint, if any, is explicitly removed from the
  1140. breakpoint list.
  1141. - All eventpoints without a symbolic address are removed from the
  1142. breakpoint list. */
  1143. extern void update_breakpoints_after_exec (void);
  1144. /* This function can be used to physically remove hardware breakpoints
  1145. and watchpoints from the specified traced inferior process, without
  1146. modifying the breakpoint package's state. This can be useful for
  1147. those targets which support following the processes of a fork() or
  1148. vfork() system call, when one of the resulting two processes is to
  1149. be detached and allowed to run free.
  1150. It is an error to use this function on the process whose id is
  1151. inferior_ptid. */
  1152. extern int detach_breakpoints (ptid_t ptid);
  1153. /* This function is called when program space PSPACE is about to be
  1154. deleted. It takes care of updating breakpoints to not reference
  1155. this PSPACE anymore. */
  1156. extern void breakpoint_program_space_exit (struct program_space *pspace);
  1157. extern void set_longjmp_breakpoint (struct thread_info *tp,
  1158. struct frame_id frame);
  1159. extern void delete_longjmp_breakpoint (int thread);
  1160. /* Mark all longjmp breakpoints from THREAD for later deletion. */
  1161. extern void delete_longjmp_breakpoint_at_next_stop (int thread);
  1162. extern struct breakpoint *set_longjmp_breakpoint_for_call_dummy (void);
  1163. extern void check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp);
  1164. extern void enable_overlay_breakpoints (void);
  1165. extern void disable_overlay_breakpoints (void);
  1166. extern void set_std_terminate_breakpoint (void);
  1167. extern void delete_std_terminate_breakpoint (void);
  1168. /* These functions respectively disable or reenable all currently
  1169. enabled watchpoints. When disabled, the watchpoints are marked
  1170. call_disabled. When re-enabled, they are marked enabled.
  1171. The intended client of these functions is call_function_by_hand.
  1172. The inferior must be stopped, and all breakpoints removed, when
  1173. these functions are used.
  1174. The need for these functions is that on some targets (e.g., HP-UX),
  1175. gdb is unable to unwind through the dummy frame that is pushed as
  1176. part of the implementation of a call command. Watchpoints can
  1177. cause the inferior to stop in places where this frame is visible,
  1178. and that can cause execution control to become very confused.
  1179. Note that if a user sets breakpoints in an interactively called
  1180. function, the call_disabled watchpoints will have been re-enabled
  1181. when the first such breakpoint is reached. However, on targets
  1182. that are unable to unwind through the call dummy frame, watches
  1183. of stack-based storage may then be deleted, because gdb will
  1184. believe that their watched storage is out of scope. (Sigh.) */
  1185. extern void disable_watchpoints_before_interactive_call_start (void);
  1186. extern void enable_watchpoints_after_interactive_call_stop (void);
  1187. /* These functions disable and re-enable all breakpoints during
  1188. inferior startup. They are intended to be called from solib
  1189. code where necessary. This is needed on platforms where the
  1190. main executable is relocated at some point during startup
  1191. processing, making breakpoint addresses invalid.
  1192. If additional breakpoints are created after the routine
  1193. disable_breakpoints_before_startup but before the routine
  1194. enable_breakpoints_after_startup was called, they will also
  1195. be marked as disabled. */
  1196. extern void disable_breakpoints_before_startup (void);
  1197. extern void enable_breakpoints_after_startup (void);
  1198. /* For script interpreters that need to define breakpoint commands
  1199. after they've already read the commands into a struct
  1200. command_line. */
  1201. extern enum command_control_type commands_from_control_command
  1202. (const char *arg, struct command_line *cmd);
  1203. extern void clear_breakpoint_hit_counts (void);
  1204. extern struct breakpoint *get_breakpoint (int num);
  1205. /* The following are for displays, which aren't really breakpoints,
  1206. but here is as good a place as any for them. */
  1207. extern void disable_current_display (void);
  1208. extern void do_displays (void);
  1209. extern void disable_display (int);
  1210. extern void clear_displays (void);
  1211. extern void disable_breakpoint (struct breakpoint *);
  1212. extern void enable_breakpoint (struct breakpoint *);
  1213. extern void breakpoint_set_commands (struct breakpoint *b,
  1214. counted_command_line &&commands);
  1215. extern void breakpoint_set_silent (struct breakpoint *b, int silent);
  1216. extern void breakpoint_set_thread (struct breakpoint *b, int thread);
  1217. extern void breakpoint_set_task (struct breakpoint *b, int task);
  1218. /* Clear the "inserted" flag in all breakpoints. */
  1219. extern void mark_breakpoints_out (void);
  1220. extern struct breakpoint *create_jit_event_breakpoint (struct gdbarch *,
  1221. CORE_ADDR);
  1222. extern struct breakpoint *create_solib_event_breakpoint (struct gdbarch *,
  1223. CORE_ADDR);
  1224. /* Create an solib event breakpoint at ADDRESS in the current program
  1225. space, and immediately try to insert it. Returns a pointer to the
  1226. breakpoint on success. Deletes the new breakpoint and returns NULL
  1227. if inserting the breakpoint fails. */
  1228. extern struct breakpoint *create_and_insert_solib_event_breakpoint
  1229. (struct gdbarch *gdbarch, CORE_ADDR address);
  1230. extern struct breakpoint *create_thread_event_breakpoint (struct gdbarch *,
  1231. CORE_ADDR);
  1232. extern void remove_jit_event_breakpoints (void);
  1233. extern void remove_solib_event_breakpoints (void);
  1234. /* Mark solib event breakpoints of the current program space with
  1235. delete at next stop disposition. */
  1236. extern void remove_solib_event_breakpoints_at_next_stop (void);
  1237. extern void disable_breakpoints_in_shlibs (void);
  1238. /* This function returns true if B is a catchpoint. */
  1239. extern bool is_catchpoint (struct breakpoint *b);
  1240. /* Shared helper function (MI and CLI) for creating and installing
  1241. a shared object event catchpoint. If IS_LOAD is true then
  1242. the events to be caught are load events, otherwise they are
  1243. unload events. If IS_TEMP is true the catchpoint is a
  1244. temporary one. If ENABLED is true the catchpoint is
  1245. created in an enabled state. */
  1246. extern void add_solib_catchpoint (const char *arg, bool is_load, bool is_temp,
  1247. bool enabled);
  1248. /* Create and insert a new software single step breakpoint for the
  1249. current thread. May be called multiple times; each time will add a
  1250. new location to the set of potential addresses the next instruction
  1251. is at. */
  1252. extern void insert_single_step_breakpoint (struct gdbarch *,
  1253. const address_space *,
  1254. CORE_ADDR);
  1255. /* Insert all software single step breakpoints for the current frame.
  1256. Return true if any software single step breakpoints are inserted,
  1257. otherwise, return false. */
  1258. extern int insert_single_step_breakpoints (struct gdbarch *);
  1259. /* Check whether any hardware watchpoints have triggered or not,
  1260. according to the target, and record it in each watchpoint's
  1261. 'watchpoint_triggered' field. */
  1262. int watchpoints_triggered (const target_waitstatus &);
  1263. /* Helper for transparent breakpoint hiding for memory read and write
  1264. routines.
  1265. Update one of READBUF or WRITEBUF with either the shadows
  1266. (READBUF), or the breakpoint instructions (WRITEBUF) of inserted
  1267. breakpoints at the memory range defined by MEMADDR and extending
  1268. for LEN bytes. If writing, then WRITEBUF is a copy of WRITEBUF_ORG
  1269. on entry.*/
  1270. extern void breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
  1271. const gdb_byte *writebuf_org,
  1272. ULONGEST memaddr, LONGEST len);
  1273. /* Return true if breakpoints should be inserted now. That'll be the
  1274. case if either:
  1275. - the target has global breakpoints.
  1276. - "breakpoint always-inserted" is on, and the target has
  1277. execution.
  1278. - threads are executing.
  1279. */
  1280. extern int breakpoints_should_be_inserted_now (void);
  1281. /* Called each time new event from target is processed.
  1282. Retires previously deleted breakpoint locations that
  1283. in our opinion won't ever trigger. */
  1284. extern void breakpoint_retire_moribund (void);
  1285. /* Set break condition of breakpoint B to EXP.
  1286. If FORCE, define the condition even if it is invalid in
  1287. all of the breakpoint locations. */
  1288. extern void set_breakpoint_condition (struct breakpoint *b, const char *exp,
  1289. int from_tty, bool force);
  1290. /* Set break condition for the breakpoint with number BPNUM to EXP.
  1291. Raise an error if no breakpoint with the given number is found.
  1292. Also raise an error if the breakpoint already has stop conditions.
  1293. If FORCE, define the condition even if it is invalid in
  1294. all of the breakpoint locations. */
  1295. extern void set_breakpoint_condition (int bpnum, const char *exp,
  1296. int from_tty, bool force);
  1297. /* Checks if we are catching syscalls or not.
  1298. Returns 0 if not, greater than 0 if we are. */
  1299. extern int catch_syscall_enabled (void);
  1300. /* Checks if we are catching syscalls with the specific
  1301. syscall_number. Used for "filtering" the catchpoints.
  1302. Returns false if not, true if we are. */
  1303. extern bool catching_syscall_number (int syscall_number);
  1304. /* Return a tracepoint with the given number if found. */
  1305. extern struct tracepoint *get_tracepoint (int num);
  1306. extern struct tracepoint *get_tracepoint_by_number_on_target (int num);
  1307. /* Find a tracepoint by parsing a number in the supplied string. */
  1308. extern struct tracepoint *
  1309. get_tracepoint_by_number (const char **arg,
  1310. number_or_range_parser *parser);
  1311. /* Return true if B is of tracepoint kind. */
  1312. extern bool is_tracepoint (const struct breakpoint *b);
  1313. /* Return a vector of all static tracepoints defined at ADDR. */
  1314. extern std::vector<breakpoint *> static_tracepoints_here (CORE_ADDR addr);
  1315. /* Create an instance of this to start registering breakpoint numbers
  1316. for a later "commands" command. */
  1317. class scoped_rbreak_breakpoints
  1318. {
  1319. public:
  1320. scoped_rbreak_breakpoints ();
  1321. ~scoped_rbreak_breakpoints ();
  1322. DISABLE_COPY_AND_ASSIGN (scoped_rbreak_breakpoints);
  1323. };
  1324. /* Breakpoint linked list iterator. */
  1325. using breakpoint_iterator = next_iterator<breakpoint>;
  1326. /* Breakpoint linked list range. */
  1327. using breakpoint_range = iterator_range<breakpoint_iterator>;
  1328. /* Return a range to iterate over all breakpoints. */
  1329. breakpoint_range all_breakpoints ();
  1330. /* Breakpoint linked list range, safe against deletion of the current
  1331. breakpoint while iterating. */
  1332. using breakpoint_safe_range = basic_safe_range<breakpoint_range>;
  1333. /* Return a range to iterate over all breakpoints. This range is safe against
  1334. deletion of the current breakpoint while iterating. */
  1335. breakpoint_safe_range all_breakpoints_safe ();
  1336. /* Breakpoint filter to only keep tracepoints. */
  1337. struct tracepoint_filter
  1338. {
  1339. bool operator() (breakpoint *b)
  1340. { return is_tracepoint (b); }
  1341. };
  1342. /* Breakpoint linked list iterator, filtering to only keep tracepoints. */
  1343. using tracepoint_iterator
  1344. = filtered_iterator<breakpoint_iterator, tracepoint_filter>;
  1345. /* Breakpoint linked list range, filtering to only keep tracepoints. */
  1346. using tracepoint_range = iterator_range<tracepoint_iterator>;
  1347. /* Return a range to iterate over all tracepoints. */
  1348. tracepoint_range all_tracepoints ();
  1349. /* Return a range to iterate over all breakpoint locations. */
  1350. const std::vector<bp_location *> &all_bp_locations ();
  1351. /* Nonzero if the specified PC cannot be a location where functions
  1352. have been inlined. */
  1353. extern int pc_at_non_inline_function (const address_space *aspace,
  1354. CORE_ADDR pc,
  1355. const target_waitstatus &ws);
  1356. extern int user_breakpoint_p (struct breakpoint *);
  1357. /* Return true if this breakpoint is pending, false if not. */
  1358. extern int pending_breakpoint_p (struct breakpoint *);
  1359. /* Attempt to determine architecture of location identified by SAL. */
  1360. extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
  1361. extern void breakpoint_free_objfile (struct objfile *objfile);
  1362. extern const char *ep_parse_optional_if_clause (const char **arg);
  1363. /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" to
  1364. UIOUT iff debugging multiple threads. */
  1365. extern void maybe_print_thread_hit_breakpoint (struct ui_out *uiout);
  1366. /* Print the specified breakpoint. */
  1367. extern void print_breakpoint (breakpoint *bp);
  1368. /* Command element for the 'commands' command. */
  1369. extern cmd_list_element *commands_cmd_element;
  1370. /* Whether to use the fixed output when printing information about a
  1371. multi-location breakpoint (see PR 9659). */
  1372. extern bool fix_multi_location_breakpoint_output_globally;
  1373. /* Deal with "catch catch", "catch throw", and "catch rethrow" commands and
  1374. the MI equivalents. Sets up to catch events of type EX_EVENT. When
  1375. TEMPFLAG is true only the next matching event is caught after which the
  1376. catch-point is deleted. If REGEX is not NULL then only exceptions whose
  1377. type name matches REGEX will trigger the event. */
  1378. extern void catch_exception_event (enum exception_event_kind ex_event,
  1379. const char *regex, bool tempflag,
  1380. int from_tty);
  1381. #endif /* !defined (BREAKPOINT_H) */