frame.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /* Definitions for dealing with stack frames, for GDB, the GNU debugger.
  2. Copyright (C) 1986-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 (FRAME_H)
  15. #define FRAME_H 1
  16. /* The following is the intended naming schema for frame functions.
  17. It isn't 100% consistent, but it is approaching that. Frame naming
  18. schema:
  19. Prefixes:
  20. get_frame_WHAT...(): Get WHAT from the THIS frame (functionally
  21. equivalent to THIS->next->unwind->what)
  22. frame_unwind_WHAT...(): Unwind THIS frame's WHAT from the NEXT
  23. frame.
  24. frame_unwind_caller_WHAT...(): Unwind WHAT for NEXT stack frame's
  25. real caller. Any inlined functions in NEXT's stack frame are
  26. skipped. Use these to ignore any potentially inlined functions,
  27. e.g. inlined into the first instruction of a library trampoline.
  28. get_stack_frame_WHAT...(): Get WHAT for THIS frame, but if THIS is
  29. inlined, skip to the containing stack frame.
  30. put_frame_WHAT...(): Put a value into this frame (unsafe, need to
  31. invalidate the frame / regcache afterwards) (better name more
  32. strongly hinting at its unsafeness)
  33. safe_....(): Safer version of various functions, doesn't throw an
  34. error (leave this for later?). Returns true / non-NULL if the request
  35. succeeds, false / NULL otherwise.
  36. Suffixes:
  37. void /frame/_WHAT(): Read WHAT's value into the buffer parameter.
  38. ULONGEST /frame/_WHAT_unsigned(): Return an unsigned value (the
  39. alternative is *frame_unsigned_WHAT).
  40. LONGEST /frame/_WHAT_signed(): Return WHAT signed value.
  41. What:
  42. /frame/_memory* (frame, coreaddr, len [, buf]): Extract/return
  43. *memory.
  44. /frame/_register* (frame, regnum [, buf]): extract/return register.
  45. CORE_ADDR /frame/_{pc,sp,...} (frame): Resume address, innner most
  46. stack *address, ...
  47. */
  48. #include "language.h"
  49. #include "cli/cli-option.h"
  50. #include "gdbsupport/common-debug.h"
  51. struct symtab_and_line;
  52. struct frame_unwind;
  53. struct frame_base;
  54. struct block;
  55. struct gdbarch;
  56. struct ui_file;
  57. struct ui_out;
  58. struct frame_print_options;
  59. /* Status of a given frame's stack. */
  60. enum frame_id_stack_status
  61. {
  62. /* Stack address is invalid. */
  63. FID_STACK_INVALID = 0,
  64. /* Stack address is valid, and is found in the stack_addr field. */
  65. FID_STACK_VALID = 1,
  66. /* Sentinel frame. */
  67. FID_STACK_SENTINEL = 2,
  68. /* Outer frame. Since a frame's stack address is typically defined as the
  69. value the stack pointer had prior to the activation of the frame, an outer
  70. frame doesn't have a stack address. The frame ids of frames inlined in the
  71. outer frame are also of this type. */
  72. FID_STACK_OUTER = 3,
  73. /* Stack address is unavailable. I.e., there's a valid stack, but
  74. we don't know where it is (because memory or registers we'd
  75. compute it from were not collected). */
  76. FID_STACK_UNAVAILABLE = -1
  77. };
  78. /* The frame object. */
  79. struct frame_info;
  80. /* The frame object's ID. This provides a per-frame unique identifier
  81. that can be used to relocate a `struct frame_info' after a target
  82. resume or a frame cache destruct. It of course assumes that the
  83. inferior hasn't unwound the stack past that frame. */
  84. struct frame_id
  85. {
  86. /* The frame's stack address. This shall be constant through out
  87. the lifetime of a frame. Note that this requirement applies to
  88. not just the function body, but also the prologue and (in theory
  89. at least) the epilogue. Since that value needs to fall either on
  90. the boundary, or within the frame's address range, the frame's
  91. outer-most address (the inner-most address of the previous frame)
  92. is used. Watch out for all the legacy targets that still use the
  93. function pointer register or stack pointer register. They are
  94. wrong.
  95. This field is valid only if frame_id.stack_status is
  96. FID_STACK_VALID. It will be 0 for other
  97. FID_STACK_... statuses. */
  98. CORE_ADDR stack_addr;
  99. /* The frame's code address. This shall be constant through out the
  100. lifetime of the frame. While the PC (a.k.a. resume address)
  101. changes as the function is executed, this code address cannot.
  102. Typically, it is set to the address of the entry point of the
  103. frame's function (as returned by get_frame_func).
  104. For inlined functions (INLINE_DEPTH != 0), this is the address of
  105. the first executed instruction in the block corresponding to the
  106. inlined function.
  107. This field is valid only if code_addr_p is true. Otherwise, this
  108. frame is considered to have a wildcard code address, i.e. one that
  109. matches every address value in frame comparisons. */
  110. CORE_ADDR code_addr;
  111. /* The frame's special address. This shall be constant through out the
  112. lifetime of the frame. This is used for architectures that may have
  113. frames that do not change the stack but are still distinct and have
  114. some form of distinct identifier (e.g. the ia64 which uses a 2nd
  115. stack for registers). This field is treated as unordered - i.e. will
  116. not be used in frame ordering comparisons.
  117. This field is valid only if special_addr_p is true. Otherwise, this
  118. frame is considered to have a wildcard special address, i.e. one that
  119. matches every address value in frame comparisons. */
  120. CORE_ADDR special_addr;
  121. /* Flags to indicate the above fields have valid contents. */
  122. ENUM_BITFIELD(frame_id_stack_status) stack_status : 3;
  123. unsigned int code_addr_p : 1;
  124. unsigned int special_addr_p : 1;
  125. /* It is non-zero for a frame made up by GDB without stack data
  126. representation in inferior, such as INLINE_FRAME or TAILCALL_FRAME.
  127. Caller of inlined function will have it zero, each more inner called frame
  128. will have it increasingly one, two etc. Similarly for TAILCALL_FRAME. */
  129. int artificial_depth;
  130. /* Return a string representation of this frame id. */
  131. std::string to_string () const;
  132. };
  133. /* Save and restore the currently selected frame. */
  134. class scoped_restore_selected_frame
  135. {
  136. public:
  137. /* Save the currently selected frame. */
  138. scoped_restore_selected_frame ();
  139. /* Restore the currently selected frame. */
  140. ~scoped_restore_selected_frame ();
  141. DISABLE_COPY_AND_ASSIGN (scoped_restore_selected_frame);
  142. private:
  143. /* The ID and level of the previously selected frame. */
  144. struct frame_id m_fid;
  145. int m_level;
  146. /* Save/restore the language as well, because selecting a frame
  147. changes the current language to the frame's language if "set
  148. language auto". */
  149. enum language m_lang;
  150. };
  151. /* Methods for constructing and comparing Frame IDs. */
  152. /* For convenience. All fields are zero. This means "there is no frame". */
  153. extern const struct frame_id null_frame_id;
  154. /* Sentinel frame. */
  155. extern const struct frame_id sentinel_frame_id;
  156. /* This means "there is no frame ID, but there is a frame". It should be
  157. replaced by best-effort frame IDs for the outermost frame, somehow.
  158. The implementation is only special_addr_p set. */
  159. extern const struct frame_id outer_frame_id;
  160. /* Flag to control debugging. */
  161. extern bool frame_debug;
  162. /* Print a "frame" debug statement. */
  163. #define frame_debug_printf(fmt, ...) \
  164. debug_prefixed_printf_cond (frame_debug, "frame", fmt, ##__VA_ARGS__)
  165. /* Print "frame" enter/exit debug statements. */
  166. #define FRAME_SCOPED_DEBUG_ENTER_EXIT \
  167. scoped_debug_enter_exit (frame_debug, "frame")
  168. /* Construct a frame ID. The first parameter is the frame's constant
  169. stack address (typically the outer-bound), and the second the
  170. frame's constant code address (typically the entry point).
  171. The special identifier address is set to indicate a wild card. */
  172. extern struct frame_id frame_id_build (CORE_ADDR stack_addr,
  173. CORE_ADDR code_addr);
  174. /* Construct a special frame ID. The first parameter is the frame's constant
  175. stack address (typically the outer-bound), the second is the
  176. frame's constant code address (typically the entry point),
  177. and the third parameter is the frame's special identifier address. */
  178. extern struct frame_id frame_id_build_special (CORE_ADDR stack_addr,
  179. CORE_ADDR code_addr,
  180. CORE_ADDR special_addr);
  181. /* Construct a frame ID representing a frame where the stack address
  182. exists, but is unavailable. CODE_ADDR is the frame's constant code
  183. address (typically the entry point). The special identifier
  184. address is set to indicate a wild card. */
  185. extern struct frame_id frame_id_build_unavailable_stack (CORE_ADDR code_addr);
  186. /* Construct a frame ID representing a frame where the stack address
  187. exists, but is unavailable. CODE_ADDR is the frame's constant code
  188. address (typically the entry point). SPECIAL_ADDR is the special
  189. identifier address. */
  190. extern struct frame_id
  191. frame_id_build_unavailable_stack_special (CORE_ADDR code_addr,
  192. CORE_ADDR special_addr);
  193. /* Construct a wild card frame ID. The parameter is the frame's constant
  194. stack address (typically the outer-bound). The code address as well
  195. as the special identifier address are set to indicate wild cards. */
  196. extern struct frame_id frame_id_build_wild (CORE_ADDR stack_addr);
  197. /* Returns true when L is a valid frame. */
  198. extern bool frame_id_p (frame_id l);
  199. /* Returns true when L is a valid frame representing a frame made up by GDB
  200. without stack data representation in inferior, such as INLINE_FRAME or
  201. TAILCALL_FRAME. */
  202. extern bool frame_id_artificial_p (frame_id l);
  203. /* Returns true when L and R identify the same frame. */
  204. extern bool frame_id_eq (frame_id l, frame_id r);
  205. /* Frame types. Some are real, some are signal trampolines, and some
  206. are completely artificial (dummy). */
  207. enum frame_type
  208. {
  209. /* A true stack frame, created by the target program during normal
  210. execution. */
  211. NORMAL_FRAME,
  212. /* A fake frame, created by GDB when performing an inferior function
  213. call. */
  214. DUMMY_FRAME,
  215. /* A frame representing an inlined function, associated with an
  216. upcoming (prev, outer, older) NORMAL_FRAME. */
  217. INLINE_FRAME,
  218. /* A virtual frame of a tail call - see dwarf2_tailcall_frame_unwind. */
  219. TAILCALL_FRAME,
  220. /* In a signal handler, various OSs handle this in various ways.
  221. The main thing is that the frame may be far from normal. */
  222. SIGTRAMP_FRAME,
  223. /* Fake frame representing a cross-architecture call. */
  224. ARCH_FRAME,
  225. /* Sentinel or registers frame. This frame obtains register values
  226. direct from the inferior's registers. */
  227. SENTINEL_FRAME
  228. };
  229. /* For every stopped thread, GDB tracks two frames: current and
  230. selected. Current frame is the inner most frame of the selected
  231. thread. Selected frame is the one being examined by the GDB
  232. CLI (selected using `up', `down', ...). The frames are created
  233. on-demand (via get_prev_frame()) and then held in a frame cache. */
  234. /* FIXME: cagney/2002-11-28: Er, there is a lie here. If you do the
  235. sequence: `thread 1; up; thread 2; thread 1' you lose thread 1's
  236. selected frame. At present GDB only tracks the selected frame of
  237. the current thread. But be warned, that might change. */
  238. /* FIXME: cagney/2002-11-14: At any time, only one thread's selected
  239. and current frame can be active. Switching threads causes gdb to
  240. discard all that cached frame information. Ulgh! Instead, current
  241. and selected frame should be bound to a thread. */
  242. /* On demand, create the inner most frame using information found in
  243. the inferior. If the inner most frame can't be created, throw an
  244. error. */
  245. extern struct frame_info *get_current_frame (void);
  246. /* Does the current target interface have enough state to be able to
  247. query the current inferior for frame info, and is the inferior in a
  248. state where that is possible? */
  249. extern bool has_stack_frames ();
  250. /* Invalidates the frame cache (this function should have been called
  251. invalidate_cached_frames).
  252. FIXME: cagney/2002-11-28: There should be two methods: one that
  253. reverts the thread's selected frame back to current frame (for when
  254. the inferior resumes) and one that does not (for when the user
  255. modifies the target invalidating the frame cache). */
  256. extern void reinit_frame_cache (void);
  257. /* Return the selected frame. Always returns non-NULL. If there
  258. isn't an inferior sufficient for creating a frame, an error is
  259. thrown. When MESSAGE is non-NULL, use it for the error message,
  260. otherwise use a generic error message. */
  261. /* FIXME: cagney/2002-11-28: At present, when there is no selected
  262. frame, this function always returns the current (inner most) frame.
  263. It should instead, when a thread has previously had its frame
  264. selected (but not resumed) and the frame cache invalidated, find
  265. and then return that thread's previously selected frame. */
  266. extern struct frame_info *get_selected_frame (const char *message = nullptr);
  267. /* Select a specific frame. NULL implies re-select the inner most
  268. frame. */
  269. extern void select_frame (struct frame_info *);
  270. /* Save the frame ID and frame level of the selected frame in FRAME_ID
  271. and FRAME_LEVEL, to be restored later with restore_selected_frame.
  272. This is preferred over getting the same info out of
  273. get_selected_frame directly because this function does not create
  274. the selected-frame's frame_info object if it hasn't been created
  275. yet, and thus is more efficient and doesn't throw. */
  276. extern void save_selected_frame (frame_id *frame_id, int *frame_level)
  277. noexcept;
  278. /* Restore selected frame as saved with save_selected_frame.
  279. Does not try to find the corresponding frame_info object. Instead
  280. the next call to get_selected_frame will look it up and cache the
  281. result.
  282. This function does not throw. It is designed to be safe to called
  283. from the destructors of RAII types. */
  284. extern void restore_selected_frame (frame_id frame_id, int frame_level)
  285. noexcept;
  286. /* Lookup the frame_info object for the selected frame FRAME_ID /
  287. FRAME_LEVEL and cache the result.
  288. If FRAME_LEVEL > 0 and the originally selected frame isn't found,
  289. warn and select the innermost (current) frame. */
  290. extern void lookup_selected_frame (frame_id frame_id, int frame_level);
  291. /* Given a FRAME, return the next (more inner, younger) or previous
  292. (more outer, older) frame. */
  293. extern struct frame_info *get_prev_frame (struct frame_info *);
  294. extern struct frame_info *get_next_frame (struct frame_info *);
  295. /* Like get_next_frame(), but allows return of the sentinel frame. NULL
  296. is never returned. */
  297. extern struct frame_info *get_next_frame_sentinel_okay (struct frame_info *);
  298. /* Return a "struct frame_info" corresponding to the frame that called
  299. THIS_FRAME. Returns NULL if there is no such frame.
  300. Unlike get_prev_frame, this function always tries to unwind the
  301. frame. */
  302. extern struct frame_info *get_prev_frame_always (struct frame_info *);
  303. /* Given a frame's ID, relocate the frame. Returns NULL if the frame
  304. is not found. */
  305. extern struct frame_info *frame_find_by_id (struct frame_id id);
  306. /* Base attributes of a frame: */
  307. /* The frame's `resume' address. Where the program will resume in
  308. this frame.
  309. This replaced: frame->pc; */
  310. extern CORE_ADDR get_frame_pc (struct frame_info *);
  311. /* Same as get_frame_pc, but return a boolean indication of whether
  312. the PC is actually available, instead of throwing an error. */
  313. extern bool get_frame_pc_if_available (frame_info *frame, CORE_ADDR *pc);
  314. /* An address (not necessarily aligned to an instruction boundary)
  315. that falls within THIS frame's code block.
  316. When a function call is the last statement in a block, the return
  317. address for the call may land at the start of the next block.
  318. Similarly, if a no-return function call is the last statement in
  319. the function, the return address may end up pointing beyond the
  320. function, and possibly at the start of the next function.
  321. These methods make an allowance for this. For call frames, this
  322. function returns the frame's PC-1 which "should" be an address in
  323. the frame's block. */
  324. extern CORE_ADDR get_frame_address_in_block (struct frame_info *this_frame);
  325. /* Same as get_frame_address_in_block, but returns a boolean
  326. indication of whether the frame address is determinable (when the
  327. PC is unavailable, it will not be), instead of possibly throwing an
  328. error trying to read an unavailable PC. */
  329. extern bool get_frame_address_in_block_if_available (frame_info *this_frame,
  330. CORE_ADDR *pc);
  331. /* The frame's inner-most bound. AKA the stack-pointer. Confusingly
  332. known as top-of-stack. */
  333. extern CORE_ADDR get_frame_sp (struct frame_info *);
  334. /* Following on from the `resume' address. Return the entry point
  335. address of the function containing that resume address, or zero if
  336. that function isn't known. */
  337. extern CORE_ADDR get_frame_func (struct frame_info *fi);
  338. /* Same as get_frame_func, but returns a boolean indication of whether
  339. the frame function is determinable (when the PC is unavailable, it
  340. will not be), instead of possibly throwing an error trying to read
  341. an unavailable PC. */
  342. extern bool get_frame_func_if_available (frame_info *fi, CORE_ADDR *);
  343. /* Closely related to the resume address, various symbol table
  344. attributes that are determined by the PC. Note that for a normal
  345. frame, the PC refers to the resume address after the return, and
  346. not the call instruction. In such a case, the address is adjusted
  347. so that it (approximately) identifies the call site (and not the
  348. return site).
  349. NOTE: cagney/2002-11-28: The frame cache could be used to cache the
  350. computed value. Working on the assumption that the bottle-neck is
  351. in the single step code, and that code causes the frame cache to be
  352. constantly flushed, caching things in a frame is probably of little
  353. benefit. As they say `show us the numbers'.
  354. NOTE: cagney/2002-11-28: Plenty more where this one came from:
  355. find_frame_block(), find_frame_partial_function(),
  356. find_frame_symtab(), find_frame_function(). Each will need to be
  357. carefully considered to determine if the real intent was for it to
  358. apply to the PC or the adjusted PC. */
  359. extern symtab_and_line find_frame_sal (frame_info *frame);
  360. /* Set the current source and line to the location given by frame
  361. FRAME, if possible. */
  362. void set_current_sal_from_frame (struct frame_info *);
  363. /* Return the frame base (what ever that is) (DEPRECATED).
  364. Old code was trying to use this single method for two conflicting
  365. purposes. Such code needs to be updated to use either of:
  366. get_frame_id: A low level frame unique identifier, that consists of
  367. both a stack and a function address, that can be used to uniquely
  368. identify a frame. This value is determined by the frame's
  369. low-level unwinder, the stack part [typically] being the
  370. top-of-stack of the previous frame, and the function part being the
  371. function's start address. Since the correct identification of a
  372. frameless function requires both a stack and function address,
  373. the old get_frame_base method was not sufficient.
  374. get_frame_base_address: get_frame_locals_address:
  375. get_frame_args_address: A set of high-level debug-info dependant
  376. addresses that fall within the frame. These addresses almost
  377. certainly will not match the stack address part of a frame ID (as
  378. returned by get_frame_base).
  379. This replaced: frame->frame; */
  380. extern CORE_ADDR get_frame_base (struct frame_info *);
  381. /* Return the per-frame unique identifer. Can be used to relocate a
  382. frame after a frame cache flush (and other similar operations). If
  383. FI is NULL, return the null_frame_id.
  384. NOTE: kettenis/20040508: These functions return a structure. On
  385. platforms where structures are returned in static storage (vax,
  386. m68k), this may trigger compiler bugs in code like:
  387. if (frame_id_eq (get_frame_id (l), get_frame_id (r)))
  388. where the return value from the first get_frame_id (l) gets
  389. overwritten by the second get_frame_id (r). Please avoid writing
  390. code like this. Use code like:
  391. struct frame_id id = get_frame_id (l);
  392. if (frame_id_eq (id, get_frame_id (r)))
  393. instead, since that avoids the bug. */
  394. extern struct frame_id get_frame_id (struct frame_info *fi);
  395. extern struct frame_id get_stack_frame_id (struct frame_info *fi);
  396. extern struct frame_id frame_unwind_caller_id (struct frame_info *next_frame);
  397. /* Assuming that a frame is `normal', return its base-address, or 0 if
  398. the information isn't available. NOTE: This address is really only
  399. meaningful to the frame's high-level debug info. */
  400. extern CORE_ADDR get_frame_base_address (struct frame_info *);
  401. /* Assuming that a frame is `normal', return the base-address of the
  402. local variables, or 0 if the information isn't available. NOTE:
  403. This address is really only meaningful to the frame's high-level
  404. debug info. Typically, the argument and locals share a single
  405. base-address. */
  406. extern CORE_ADDR get_frame_locals_address (struct frame_info *);
  407. /* Assuming that a frame is `normal', return the base-address of the
  408. parameter list, or 0 if that information isn't available. NOTE:
  409. This address is really only meaningful to the frame's high-level
  410. debug info. Typically, the argument and locals share a single
  411. base-address. */
  412. extern CORE_ADDR get_frame_args_address (struct frame_info *);
  413. /* The frame's level: 0 for innermost, 1 for its caller, ...; or -1
  414. for an invalid frame). */
  415. extern int frame_relative_level (struct frame_info *fi);
  416. /* Return the frame's type. */
  417. extern enum frame_type get_frame_type (struct frame_info *);
  418. /* Return the frame's program space. */
  419. extern struct program_space *get_frame_program_space (struct frame_info *);
  420. /* Unwind THIS frame's program space from the NEXT frame. */
  421. extern struct program_space *frame_unwind_program_space (struct frame_info *);
  422. class address_space;
  423. /* Return the frame's address space. */
  424. extern const address_space *get_frame_address_space (struct frame_info *);
  425. /* For frames where we can not unwind further, describe why. */
  426. enum unwind_stop_reason
  427. {
  428. #define SET(name, description) name,
  429. #define FIRST_ENTRY(name) UNWIND_FIRST = name,
  430. #define LAST_ENTRY(name) UNWIND_LAST = name,
  431. #define FIRST_ERROR(name) UNWIND_FIRST_ERROR = name,
  432. #include "unwind_stop_reasons.def"
  433. #undef SET
  434. #undef FIRST_ENTRY
  435. #undef LAST_ENTRY
  436. #undef FIRST_ERROR
  437. };
  438. /* Return the reason why we can't unwind past this frame. */
  439. enum unwind_stop_reason get_frame_unwind_stop_reason (struct frame_info *);
  440. /* Translate a reason code to an informative string. This converts the
  441. generic stop reason codes into a generic string describing the code.
  442. For a possibly frame specific string explaining the stop reason, use
  443. FRAME_STOP_REASON_STRING instead. */
  444. const char *unwind_stop_reason_to_string (enum unwind_stop_reason);
  445. /* Return a possibly frame specific string explaining why the unwind
  446. stopped here. E.g., if unwinding tripped on a memory error, this
  447. will return the error description string, which includes the address
  448. that we failed to access. If there's no specific reason stored for
  449. a frame then a generic reason string will be returned.
  450. Should only be called for frames that don't have a previous frame. */
  451. const char *frame_stop_reason_string (struct frame_info *);
  452. /* Unwind the stack frame so that the value of REGNUM, in the previous
  453. (up, older) frame is returned. If VALUEP is NULL, don't
  454. fetch/compute the value. Instead just return the location of the
  455. value. */
  456. extern void frame_register_unwind (frame_info *frame, int regnum,
  457. int *optimizedp, int *unavailablep,
  458. enum lval_type *lvalp,
  459. CORE_ADDR *addrp, int *realnump,
  460. gdb_byte *valuep);
  461. /* Fetch a register from this, or unwind a register from the next
  462. frame. Note that the get_frame methods are wrappers to
  463. frame->next->unwind. They all [potentially] throw an error if the
  464. fetch fails. The value methods never return NULL, but usually
  465. do return a lazy value. */
  466. extern void frame_unwind_register (frame_info *next_frame,
  467. int regnum, gdb_byte *buf);
  468. extern void get_frame_register (struct frame_info *frame,
  469. int regnum, gdb_byte *buf);
  470. struct value *frame_unwind_register_value (frame_info *next_frame,
  471. int regnum);
  472. struct value *get_frame_register_value (struct frame_info *frame,
  473. int regnum);
  474. extern LONGEST frame_unwind_register_signed (frame_info *next_frame,
  475. int regnum);
  476. extern LONGEST get_frame_register_signed (struct frame_info *frame,
  477. int regnum);
  478. extern ULONGEST frame_unwind_register_unsigned (frame_info *frame,
  479. int regnum);
  480. extern ULONGEST get_frame_register_unsigned (struct frame_info *frame,
  481. int regnum);
  482. /* Read a register from this, or unwind a register from the next
  483. frame. Note that the read_frame methods are wrappers to
  484. get_frame_register_value, that do not throw if the result is
  485. optimized out or unavailable. */
  486. extern bool read_frame_register_unsigned (frame_info *frame,
  487. int regnum, ULONGEST *val);
  488. /* Get the value of the register that belongs to this FRAME. This
  489. function is a wrapper to the call sequence ``frame_register_unwind
  490. (get_next_frame (FRAME))''. As per frame_register_unwind(), if
  491. VALUEP is NULL, the registers value is not fetched/computed. */
  492. extern void frame_register (struct frame_info *frame, int regnum,
  493. int *optimizedp, int *unavailablep,
  494. enum lval_type *lvalp,
  495. CORE_ADDR *addrp, int *realnump,
  496. gdb_byte *valuep);
  497. /* The reverse. Store a register value relative to the specified
  498. frame. Note: this call makes the frame's state undefined. The
  499. register and frame caches must be flushed. */
  500. extern void put_frame_register (struct frame_info *frame, int regnum,
  501. const gdb_byte *buf);
  502. /* Read LEN bytes from one or multiple registers starting with REGNUM
  503. in frame FRAME, starting at OFFSET, into BUF. If the register
  504. contents are optimized out or unavailable, set *OPTIMIZEDP,
  505. *UNAVAILABLEP accordingly. */
  506. extern bool get_frame_register_bytes (frame_info *frame, int regnum,
  507. CORE_ADDR offset,
  508. gdb::array_view<gdb_byte> buffer,
  509. int *optimizedp, int *unavailablep);
  510. /* Write bytes from BUFFER to one or multiple registers starting with REGNUM
  511. in frame FRAME, starting at OFFSET. */
  512. extern void put_frame_register_bytes (struct frame_info *frame, int regnum,
  513. CORE_ADDR offset,
  514. gdb::array_view<const gdb_byte> buffer);
  515. /* Unwind the PC. Strictly speaking return the resume address of the
  516. calling frame. For GDB, `pc' is the resume address and not a
  517. specific register. */
  518. extern CORE_ADDR frame_unwind_caller_pc (struct frame_info *frame);
  519. /* Discard the specified frame. Restoring the registers to the state
  520. of the caller. */
  521. extern void frame_pop (struct frame_info *frame);
  522. /* Return memory from the specified frame. A frame knows its thread /
  523. LWP and hence can find its way down to a target. The assumption
  524. here is that the current and previous frame share a common address
  525. space.
  526. If the memory read fails, these methods throw an error.
  527. NOTE: cagney/2003-06-03: Should there be unwind versions of these
  528. methods? That isn't clear. Can code, for instance, assume that
  529. this and the previous frame's memory or architecture are identical?
  530. If architecture / memory changes are always separated by special
  531. adaptor frames this should be ok. */
  532. extern void get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr,
  533. gdb::array_view<gdb_byte> buffer);
  534. extern LONGEST get_frame_memory_signed (struct frame_info *this_frame,
  535. CORE_ADDR memaddr, int len);
  536. extern ULONGEST get_frame_memory_unsigned (struct frame_info *this_frame,
  537. CORE_ADDR memaddr, int len);
  538. /* Same as above, but return true zero when the entire memory read
  539. succeeds, false otherwise. */
  540. extern bool safe_frame_unwind_memory (frame_info *this_frame, CORE_ADDR addr,
  541. gdb::array_view<gdb_byte> buffer);
  542. /* Return this frame's architecture. */
  543. extern struct gdbarch *get_frame_arch (struct frame_info *this_frame);
  544. /* Return the previous frame's architecture. */
  545. extern struct gdbarch *frame_unwind_arch (frame_info *next_frame);
  546. /* Return the previous frame's architecture, skipping inline functions. */
  547. extern struct gdbarch *frame_unwind_caller_arch (struct frame_info *frame);
  548. /* Values for the source flag to be used in print_frame_info ().
  549. For all the cases below, the address is never printed if
  550. 'set print address' is off. When 'set print address' is on,
  551. the address is printed if the program counter is not at the
  552. beginning of the source line of the frame
  553. and PRINT_WHAT is != LOC_AND_ADDRESS. */
  554. enum print_what
  555. {
  556. /* Print only the address, source line, like in stepi. */
  557. SRC_LINE = -1,
  558. /* Print only the location, i.e. level, address,
  559. function, args (as controlled by 'set print frame-arguments'),
  560. file, line, line num. */
  561. LOCATION,
  562. /* Print both of the above. */
  563. SRC_AND_LOC,
  564. /* Print location only, print the address even if the program counter
  565. is at the beginning of the source line. */
  566. LOC_AND_ADDRESS,
  567. /* Print only level and function,
  568. i.e. location only, without address, file, line, line num. */
  569. SHORT_LOCATION
  570. };
  571. /* Allocate zero initialized memory from the frame cache obstack.
  572. Appendices to the frame info (such as the unwind cache) should
  573. allocate memory using this method. */
  574. extern void *frame_obstack_zalloc (unsigned long size);
  575. #define FRAME_OBSTACK_ZALLOC(TYPE) \
  576. ((TYPE *) frame_obstack_zalloc (sizeof (TYPE)))
  577. #define FRAME_OBSTACK_CALLOC(NUMBER,TYPE) \
  578. ((TYPE *) frame_obstack_zalloc ((NUMBER) * sizeof (TYPE)))
  579. class readonly_detached_regcache;
  580. /* Create a regcache, and copy the frame's registers into it. */
  581. std::unique_ptr<readonly_detached_regcache> frame_save_as_regcache
  582. (struct frame_info *this_frame);
  583. extern const struct block *get_frame_block (struct frame_info *,
  584. CORE_ADDR *addr_in_block);
  585. /* Return the `struct block' that belongs to the selected thread's
  586. selected frame. If the inferior has no state, return NULL.
  587. NOTE: cagney/2002-11-29:
  588. No state? Does the inferior have any execution state (a core file
  589. does, an executable does not). At present the code tests
  590. `target_has_stack' but I'm left wondering if it should test
  591. `target_has_registers' or, even, a merged target_has_state.
  592. Should it look at the most recently specified SAL? If the target
  593. has no state, should this function try to extract a block from the
  594. most recently selected SAL? That way `list foo' would give it some
  595. sort of reference point. Then again, perhaps that would confuse
  596. things.
  597. Calls to this function can be broken down into two categories: Code
  598. that uses the selected block as an additional, but optional, data
  599. point; Code that uses the selected block as a prop, when it should
  600. have the relevant frame/block/pc explicitly passed in.
  601. The latter can be eliminated by correctly parameterizing the code,
  602. the former though is more interesting. Per the "address" command,
  603. it occurs in the CLI code and makes it possible for commands to
  604. work, even when the inferior has no state. */
  605. extern const struct block *get_selected_block (CORE_ADDR *addr_in_block);
  606. extern struct symbol *get_frame_function (struct frame_info *);
  607. extern CORE_ADDR get_pc_function_start (CORE_ADDR);
  608. extern struct frame_info *find_relative_frame (struct frame_info *, int *);
  609. /* Wrapper over print_stack_frame modifying current_uiout with UIOUT for
  610. the function call. */
  611. extern void print_stack_frame_to_uiout (struct ui_out *uiout,
  612. struct frame_info *, int print_level,
  613. enum print_what print_what,
  614. int set_current_sal);
  615. extern void print_stack_frame (struct frame_info *, int print_level,
  616. enum print_what print_what,
  617. int set_current_sal);
  618. extern void print_frame_info (const frame_print_options &fp_opts,
  619. struct frame_info *, int print_level,
  620. enum print_what print_what, int args,
  621. int set_current_sal);
  622. extern struct frame_info *block_innermost_frame (const struct block *);
  623. extern bool deprecated_frame_register_read (frame_info *frame, int regnum,
  624. gdb_byte *buf);
  625. /* From stack.c. */
  626. /* The possible choices of "set print frame-arguments". */
  627. extern const char print_frame_arguments_all[];
  628. extern const char print_frame_arguments_scalars[];
  629. extern const char print_frame_arguments_none[];
  630. /* The possible choices of "set print frame-info". */
  631. extern const char print_frame_info_auto[];
  632. extern const char print_frame_info_source_line[];
  633. extern const char print_frame_info_location[];
  634. extern const char print_frame_info_source_and_location[];
  635. extern const char print_frame_info_location_and_address[];
  636. extern const char print_frame_info_short_location[];
  637. /* The possible choices of "set print entry-values". */
  638. extern const char print_entry_values_no[];
  639. extern const char print_entry_values_only[];
  640. extern const char print_entry_values_preferred[];
  641. extern const char print_entry_values_if_needed[];
  642. extern const char print_entry_values_both[];
  643. extern const char print_entry_values_compact[];
  644. extern const char print_entry_values_default[];
  645. /* Data for the frame-printing "set print" settings exposed as command
  646. options. */
  647. struct frame_print_options
  648. {
  649. const char *print_frame_arguments = print_frame_arguments_scalars;
  650. const char *print_frame_info = print_frame_info_auto;
  651. const char *print_entry_values = print_entry_values_default;
  652. /* If true, don't invoke pretty-printers for frame
  653. arguments. */
  654. bool print_raw_frame_arguments;
  655. };
  656. /* The values behind the global "set print ..." settings. */
  657. extern frame_print_options user_frame_print_options;
  658. /* Inferior function parameter value read in from a frame. */
  659. struct frame_arg
  660. {
  661. /* Symbol for this parameter used for example for its name. */
  662. struct symbol *sym = nullptr;
  663. /* Value of the parameter. It is NULL if ERROR is not NULL; if both VAL and
  664. ERROR are NULL this parameter's value should not be printed. */
  665. struct value *val = nullptr;
  666. /* String containing the error message, it is more usually NULL indicating no
  667. error occured reading this parameter. */
  668. gdb::unique_xmalloc_ptr<char> error;
  669. /* One of the print_entry_values_* entries as appropriate specifically for
  670. this frame_arg. It will be different from print_entry_values. With
  671. print_entry_values_no this frame_arg should be printed as a normal
  672. parameter. print_entry_values_only says it should be printed as entry
  673. value parameter. print_entry_values_compact says it should be printed as
  674. both as a normal parameter and entry values parameter having the same
  675. value - print_entry_values_compact is not permitted fi ui_out_is_mi_like_p
  676. (in such case print_entry_values_no and print_entry_values_only is used
  677. for each parameter kind specifically. */
  678. const char *entry_kind = nullptr;
  679. };
  680. extern void read_frame_arg (const frame_print_options &fp_opts,
  681. symbol *sym, frame_info *frame,
  682. struct frame_arg *argp,
  683. struct frame_arg *entryargp);
  684. extern void read_frame_local (struct symbol *sym, struct frame_info *frame,
  685. struct frame_arg *argp);
  686. extern void info_args_command (const char *, int);
  687. extern void info_locals_command (const char *, int);
  688. extern void return_command (const char *, int);
  689. /* Set FRAME's unwinder temporarily, so that we can call a sniffer.
  690. If sniffing fails, the caller should be sure to call
  691. frame_cleanup_after_sniffer. */
  692. extern void frame_prepare_for_sniffer (struct frame_info *frame,
  693. const struct frame_unwind *unwind);
  694. /* Clean up after a failed (wrong unwinder) attempt to unwind past
  695. FRAME. */
  696. extern void frame_cleanup_after_sniffer (struct frame_info *frame);
  697. /* Notes (cagney/2002-11-27, drow/2003-09-06):
  698. You might think that calls to this function can simply be replaced by a
  699. call to get_selected_frame().
  700. Unfortunately, it isn't that easy.
  701. The relevant code needs to be audited to determine if it is
  702. possible (or practical) to instead pass the applicable frame in as a
  703. parameter. For instance, DEPRECATED_DO_REGISTERS_INFO() relied on
  704. the deprecated_selected_frame global, while its replacement,
  705. PRINT_REGISTERS_INFO(), is parameterized with the selected frame.
  706. The only real exceptions occur at the edge (in the CLI code) where
  707. user commands need to pick up the selected frame before proceeding.
  708. There are also some functions called with a NULL frame meaning either "the
  709. program is not running" or "use the selected frame".
  710. This is important. GDB is trying to stamp out the hack:
  711. saved_frame = deprecated_safe_get_selected_frame ();
  712. select_frame (...);
  713. hack_using_global_selected_frame ();
  714. select_frame (saved_frame);
  715. Take care!
  716. This function calls get_selected_frame if the inferior should have a
  717. frame, or returns NULL otherwise. */
  718. extern struct frame_info *deprecated_safe_get_selected_frame (void);
  719. /* Create a frame using the specified BASE and PC. */
  720. extern struct frame_info *create_new_frame (CORE_ADDR base, CORE_ADDR pc);
  721. /* Return true if the frame unwinder for frame FI is UNWINDER; false
  722. otherwise. */
  723. extern bool frame_unwinder_is (frame_info *fi, const frame_unwind *unwinder);
  724. /* Return the language of FRAME. */
  725. extern enum language get_frame_language (struct frame_info *frame);
  726. /* Return the first non-tailcall frame above FRAME or FRAME if it is not a
  727. tailcall frame. Return NULL if FRAME is the start of a tailcall-only
  728. chain. */
  729. extern struct frame_info *skip_tailcall_frames (struct frame_info *frame);
  730. /* Return the first frame above FRAME or FRAME of which the code is
  731. writable. */
  732. extern struct frame_info *skip_unwritable_frames (struct frame_info *frame);
  733. /* Data for the "set backtrace" settings. */
  734. struct set_backtrace_options
  735. {
  736. /* Flag to indicate whether backtraces should continue past
  737. main. */
  738. bool backtrace_past_main = false;
  739. /* Flag to indicate whether backtraces should continue past
  740. entry. */
  741. bool backtrace_past_entry = false;
  742. /* Upper bound on the number of backtrace levels. Note this is not
  743. exposed as a command option, because "backtrace" and "frame
  744. apply" already have other means to set a frame count limit. */
  745. unsigned int backtrace_limit = UINT_MAX;
  746. };
  747. /* The corresponding option definitions. */
  748. extern const gdb::option::option_def set_backtrace_option_defs[2];
  749. /* The values behind the global "set backtrace ..." settings. */
  750. extern set_backtrace_options user_set_backtrace_options;
  751. /* Get the number of calls to reinit_frame_cache. */
  752. unsigned int get_frame_cache_generation ();
  753. /* Mark that the PC value is masked for the previous frame. */
  754. extern void set_frame_previous_pc_masked (struct frame_info *frame);
  755. /* Get whether the PC value is masked for the given frame. */
  756. extern bool get_frame_pc_masked (const struct frame_info *frame);
  757. #endif /* !defined (FRAME_H) */