]>
| Commit | Line | Data |
|---|---|---|
| c906108c | 1 | /* Definitions for dealing with stack frames, for GDB, the GNU debugger. |
| 7cc19214 | 2 | |
| d01e8234 | 3 | Copyright (C) 1986-2025 Free Software Foundation, Inc. |
| c906108c | 4 | |
| c5aa993b | 5 | This file is part of GDB. |
| c906108c | 6 | |
| c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by | |
| a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
| c5aa993b | 10 | (at your option) any later version. |
| c906108c | 11 | |
| c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | GNU General Public License for more details. | |
| c906108c | 16 | |
| c5aa993b | 17 | You should have received a copy of the GNU General Public License |
| a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| c906108c | 19 | |
| cc709640 TT |
20 | #ifndef GDB_FRAME_H |
| 21 | #define GDB_FRAME_H | |
| c906108c | 22 | |
| f0e7d0e8 | 23 | /* The following is the intended naming schema for frame functions. |
| 30baf67b | 24 | It isn't 100% consistent, but it is approaching that. Frame naming |
| f0e7d0e8 AC |
25 | schema: |
| 26 | ||
| 27 | Prefixes: | |
| 28 | ||
| 0ee6c332 | 29 | get_frame_WHAT...(): Get WHAT from the THIS frame (functionally |
| f0e7d0e8 AC |
30 | equivalent to THIS->next->unwind->what) |
| 31 | ||
| 32 | frame_unwind_WHAT...(): Unwind THIS frame's WHAT from the NEXT | |
| 33 | frame. | |
| 34 | ||
| c7ce8faa DJ |
35 | frame_unwind_caller_WHAT...(): Unwind WHAT for NEXT stack frame's |
| 36 | real caller. Any inlined functions in NEXT's stack frame are | |
| 37 | skipped. Use these to ignore any potentially inlined functions, | |
| 38 | e.g. inlined into the first instruction of a library trampoline. | |
| 39 | ||
| edb3359d DJ |
40 | get_stack_frame_WHAT...(): Get WHAT for THIS frame, but if THIS is |
| 41 | inlined, skip to the containing stack frame. | |
| 42 | ||
| f0e7d0e8 AC |
43 | put_frame_WHAT...(): Put a value into this frame (unsafe, need to |
| 44 | invalidate the frame / regcache afterwards) (better name more | |
| 45 | strongly hinting at its unsafeness) | |
| 46 | ||
| 47 | safe_....(): Safer version of various functions, doesn't throw an | |
| 97916bfe SM |
48 | error (leave this for later?). Returns true / non-NULL if the request |
| 49 | succeeds, false / NULL otherwise. | |
| f0e7d0e8 AC |
50 | |
| 51 | Suffixes: | |
| 52 | ||
| 53 | void /frame/_WHAT(): Read WHAT's value into the buffer parameter. | |
| 54 | ||
| 55 | ULONGEST /frame/_WHAT_unsigned(): Return an unsigned value (the | |
| 56 | alternative is *frame_unsigned_WHAT). | |
| 57 | ||
| 58 | LONGEST /frame/_WHAT_signed(): Return WHAT signed value. | |
| 59 | ||
| 60 | What: | |
| 61 | ||
| 62 | /frame/_memory* (frame, coreaddr, len [, buf]): Extract/return | |
| 63 | *memory. | |
| 64 | ||
| 65 | /frame/_register* (frame, regnum [, buf]): extract/return register. | |
| 66 | ||
| 67 | CORE_ADDR /frame/_{pc,sp,...} (frame): Resume address, innner most | |
| 68 | stack *address, ... | |
| 69 | ||
| 70 | */ | |
| 71 | ||
| d4c16835 | 72 | #include "cli/cli-option.h" |
| 43e8c9ce | 73 | #include "frame-id.h" |
| fe67a58f | 74 | #include "gdbsupport/common-debug.h" |
| 43e8c9ce | 75 | #include "gdbsupport/intrusive_list.h" |
| 06096720 | 76 | |
| 1058bca7 | 77 | struct symtab_and_line; |
| 494cca16 | 78 | struct frame_unwind; |
| da62e633 | 79 | struct frame_base; |
| fe898f56 | 80 | struct block; |
| cd983b5c | 81 | struct gdbarch; |
| 30e221b4 | 82 | struct ui_file; |
| d73f9c4b | 83 | struct ui_out; |
| d4c16835 | 84 | struct frame_print_options; |
| 494cca16 | 85 | |
| c97eb5d9 AC |
86 | /* The frame object. */ |
| 87 | ||
| c97eb5d9 | 88 | |
| 45f25d6c AB |
89 | /* Save and restore the currently selected frame. */ |
| 90 | ||
| 91 | class scoped_restore_selected_frame | |
| 92 | { | |
| 93 | public: | |
| 94 | /* Save the currently selected frame. */ | |
| 95 | scoped_restore_selected_frame (); | |
| 96 | ||
| 97 | /* Restore the currently selected frame. */ | |
| 98 | ~scoped_restore_selected_frame (); | |
| 99 | ||
| 100 | DISABLE_COPY_AND_ASSIGN (scoped_restore_selected_frame); | |
| 101 | ||
| 102 | private: | |
| 103 | ||
| 79952e69 | 104 | /* The ID and level of the previously selected frame. */ |
| 45f25d6c | 105 | struct frame_id m_fid; |
| 79952e69 PA |
106 | int m_level; |
| 107 | ||
| 108 | /* Save/restore the language as well, because selecting a frame | |
| 109 | changes the current language to the frame's language if "set | |
| 110 | language auto". */ | |
| 111 | enum language m_lang; | |
| 45f25d6c AB |
112 | }; |
| 113 | ||
| 669fac23 DJ |
114 | /* Flag to control debugging. */ |
| 115 | ||
| dd4f75f2 | 116 | extern bool frame_debug; |
| 669fac23 | 117 | |
| a05a883f SM |
118 | /* Print a "frame" debug statement. */ |
| 119 | ||
| 120 | #define frame_debug_printf(fmt, ...) \ | |
| 121 | debug_prefixed_printf_cond (frame_debug, "frame", fmt, ##__VA_ARGS__) | |
| 122 | ||
| fe67a58f SM |
123 | /* Print "frame" enter/exit debug statements. */ |
| 124 | ||
| 125 | #define FRAME_SCOPED_DEBUG_ENTER_EXIT \ | |
| 126 | scoped_debug_enter_exit (frame_debug, "frame") | |
| 127 | ||
| d0a55772 AC |
128 | /* Construct a frame ID. The first parameter is the frame's constant |
| 129 | stack address (typically the outer-bound), and the second the | |
| 12b0b6de UW |
130 | frame's constant code address (typically the entry point). |
| 131 | The special identifier address is set to indicate a wild card. */ | |
| d0a55772 AC |
132 | extern struct frame_id frame_id_build (CORE_ADDR stack_addr, |
| 133 | CORE_ADDR code_addr); | |
| 7a424e99 | 134 | |
| 48c66725 JJ |
135 | /* Construct a special frame ID. The first parameter is the frame's constant |
| 136 | stack address (typically the outer-bound), the second is the | |
| 12b0b6de | 137 | frame's constant code address (typically the entry point), |
| 0963b4bd | 138 | and the third parameter is the frame's special identifier address. */ |
| 48c66725 JJ |
139 | extern struct frame_id frame_id_build_special (CORE_ADDR stack_addr, |
| 140 | CORE_ADDR code_addr, | |
| 141 | CORE_ADDR special_addr); | |
| 142 | ||
| 5ce0145d PA |
143 | /* Construct a frame ID representing a frame where the stack address |
| 144 | exists, but is unavailable. CODE_ADDR is the frame's constant code | |
| 145 | address (typically the entry point). The special identifier | |
| 146 | address is set to indicate a wild card. */ | |
| 147 | extern struct frame_id frame_id_build_unavailable_stack (CORE_ADDR code_addr); | |
| 148 | ||
| 8372a7cb MM |
149 | /* Construct a frame ID representing a frame where the stack address |
| 150 | exists, but is unavailable. CODE_ADDR is the frame's constant code | |
| 151 | address (typically the entry point). SPECIAL_ADDR is the special | |
| 152 | identifier address. */ | |
| 153 | extern struct frame_id | |
| 154 | frame_id_build_unavailable_stack_special (CORE_ADDR code_addr, | |
| 155 | CORE_ADDR special_addr); | |
| 156 | ||
| 12b0b6de UW |
157 | /* Construct a wild card frame ID. The parameter is the frame's constant |
| 158 | stack address (typically the outer-bound). The code address as well | |
| 159 | as the special identifier address are set to indicate wild cards. */ | |
| 160 | extern struct frame_id frame_id_build_wild (CORE_ADDR stack_addr); | |
| 161 | ||
| 19f98835 SM |
162 | /* Construct a frame ID for a sentinel frame. |
| 163 | ||
| 164 | If either STACK_ADDR or CODE_ADDR is not 0, the ID represents a sentinel | |
| 165 | frame for a user-created frame. STACK_ADDR and CODE_ADDR are the addresses | |
| 166 | used to create the frame. | |
| 167 | ||
| 168 | If STACK_ADDR and CODE_ADDR are both 0, the ID represents a regular sentinel | |
| 169 | frame (i.e. the "next" frame of the target's current frame). */ | |
| 170 | extern frame_id frame_id_build_sentinel (CORE_ADDR stack_addr, CORE_ADDR code_addr); | |
| 171 | ||
| 97916bfe SM |
172 | /* Returns true when L is a valid frame. */ |
| 173 | extern bool frame_id_p (frame_id l); | |
| 7a424e99 | 174 | |
| 97916bfe | 175 | /* Returns true when L is a valid frame representing a frame made up by GDB |
| 193facb3 JK |
176 | without stack data representation in inferior, such as INLINE_FRAME or |
| 177 | TAILCALL_FRAME. */ | |
| 97916bfe | 178 | extern bool frame_id_artificial_p (frame_id l); |
| edb3359d | 179 | |
| 93d42b30 DJ |
180 | /* Frame types. Some are real, some are signal trampolines, and some |
| 181 | are completely artificial (dummy). */ | |
| 182 | ||
| 183 | enum frame_type | |
| 184 | { | |
| 185 | /* A true stack frame, created by the target program during normal | |
| 186 | execution. */ | |
| 187 | NORMAL_FRAME, | |
| 188 | /* A fake frame, created by GDB when performing an inferior function | |
| 189 | call. */ | |
| 190 | DUMMY_FRAME, | |
| edb3359d | 191 | /* A frame representing an inlined function, associated with an |
| ccfc3d6e | 192 | upcoming (prev, outer, older) NORMAL_FRAME. */ |
| edb3359d | 193 | INLINE_FRAME, |
| 111c6489 JK |
194 | /* A virtual frame of a tail call - see dwarf2_tailcall_frame_unwind. */ |
| 195 | TAILCALL_FRAME, | |
| 93d42b30 DJ |
196 | /* In a signal handler, various OSs handle this in various ways. |
| 197 | The main thing is that the frame may be far from normal. */ | |
| 198 | SIGTRAMP_FRAME, | |
| 36f15f55 UW |
199 | /* Fake frame representing a cross-architecture call. */ |
| 200 | ARCH_FRAME, | |
| 93d42b30 DJ |
201 | /* Sentinel or registers frame. This frame obtains register values |
| 202 | direct from the inferior's registers. */ | |
| 203 | SENTINEL_FRAME | |
| 204 | }; | |
| 205 | ||
| be016879 TV |
206 | /* Return a string representation of TYPE. */ |
| 207 | ||
| 208 | extern const char *frame_type_str (frame_type type); | |
| 209 | ||
| 43e8c9ce SM |
210 | /* A wrapper for "frame_info *". frame_info objects are invalidated |
| 211 | whenever reinit_frame_cache is called. This class arranges to | |
| 212 | invalidate the pointer when appropriate. This is done to help | |
| 213 | detect a GDB bug that was relatively common. | |
| 214 | ||
| 215 | A small amount of code must still operate on raw pointers, so a | |
| 216 | "get" method is provided. However, you should normally not use | |
| 217 | this in new code. */ | |
| 218 | ||
| 219 | class frame_info_ptr : public intrusive_list_node<frame_info_ptr> | |
| 220 | { | |
| 221 | public: | |
| 222 | /* Create a frame_info_ptr from a raw pointer. */ | |
| 93e39555 | 223 | explicit frame_info_ptr (struct frame_info *ptr); |
| 43e8c9ce SM |
224 | |
| 225 | /* Create a null frame_info_ptr. */ | |
| 226 | frame_info_ptr () | |
| 227 | { | |
| 228 | frame_list.push_back (*this); | |
| 229 | } | |
| 230 | ||
| 231 | frame_info_ptr (std::nullptr_t) | |
| 232 | { | |
| 233 | frame_list.push_back (*this); | |
| 234 | } | |
| 235 | ||
| 236 | frame_info_ptr (const frame_info_ptr &other) | |
| 237 | : m_ptr (other.m_ptr), | |
| 238 | m_cached_id (other.m_cached_id), | |
| 239 | m_cached_level (other.m_cached_level) | |
| 240 | { | |
| 241 | frame_list.push_back (*this); | |
| 242 | } | |
| 243 | ||
| 244 | frame_info_ptr (frame_info_ptr &&other) | |
| 245 | : m_ptr (other.m_ptr), | |
| 246 | m_cached_id (other.m_cached_id), | |
| 247 | m_cached_level (other.m_cached_level) | |
| 248 | { | |
| 249 | other.m_ptr = nullptr; | |
| 250 | other.m_cached_id = null_frame_id; | |
| 251 | other.m_cached_level = invalid_level; | |
| 252 | frame_list.push_back (*this); | |
| 253 | } | |
| 254 | ||
| 255 | ~frame_info_ptr () | |
| 256 | { | |
| 751c7c72 TV |
257 | /* If this node has static storage, it should be be deleted before |
| 258 | frame_list. */ | |
| 259 | frame_list.erase (frame_list.iterator_to (*this)); | |
| 43e8c9ce SM |
260 | } |
| 261 | ||
| 262 | frame_info_ptr &operator= (const frame_info_ptr &other) | |
| 263 | { | |
| 264 | m_ptr = other.m_ptr; | |
| 265 | m_cached_id = other.m_cached_id; | |
| 266 | m_cached_level = other.m_cached_level; | |
| 267 | return *this; | |
| 268 | } | |
| 269 | ||
| 270 | frame_info_ptr &operator= (std::nullptr_t) | |
| 271 | { | |
| 272 | m_ptr = nullptr; | |
| 273 | m_cached_id = null_frame_id; | |
| 274 | m_cached_level = invalid_level; | |
| 275 | return *this; | |
| 276 | } | |
| 277 | ||
| 278 | frame_info_ptr &operator= (frame_info_ptr &&other) | |
| 279 | { | |
| 280 | m_ptr = other.m_ptr; | |
| 281 | m_cached_id = other.m_cached_id; | |
| 282 | m_cached_level = other.m_cached_level; | |
| 283 | other.m_ptr = nullptr; | |
| 284 | other.m_cached_id = null_frame_id; | |
| 285 | other.m_cached_level = invalid_level; | |
| 286 | return *this; | |
| 287 | } | |
| 288 | ||
| 289 | frame_info *operator-> () const | |
| 908de5e6 | 290 | { return this->reinflate (); } |
| 43e8c9ce SM |
291 | |
| 292 | /* Fetch the underlying pointer. Note that new code should | |
| 293 | generally not use this -- avoid it if at all possible. */ | |
| 294 | frame_info *get () const | |
| 295 | { | |
| 908de5e6 SM |
296 | if (this->is_null ()) |
| 297 | return nullptr; | |
| 298 | ||
| 299 | return this->reinflate (); | |
| 43e8c9ce SM |
300 | } |
| 301 | ||
| 908de5e6 SM |
302 | /* Return true if this object is empty (does not wrap a frame_info |
| 303 | object). */ | |
| 304 | ||
| 305 | bool is_null () const | |
| 306 | { | |
| 307 | return m_cached_level == this->invalid_level; | |
| 308 | }; | |
| 309 | ||
| 43e8c9ce SM |
310 | /* This exists for compatibility with pre-existing code that checked |
| 311 | a "frame_info *" using "!". */ | |
| 312 | bool operator! () const | |
| 313 | { | |
| 908de5e6 | 314 | return this->is_null (); |
| 43e8c9ce SM |
315 | } |
| 316 | ||
| 317 | /* This exists for compatibility with pre-existing code that checked | |
| 318 | a "frame_info *" like "if (ptr)". */ | |
| 319 | explicit operator bool () const | |
| 320 | { | |
| 908de5e6 | 321 | return !this->is_null (); |
| 43e8c9ce SM |
322 | } |
| 323 | ||
| 324 | /* Invalidate this pointer. */ | |
| 325 | void invalidate () | |
| 326 | { | |
| 327 | m_ptr = nullptr; | |
| 328 | } | |
| 329 | ||
| 43e8c9ce SM |
330 | private: |
| 331 | /* We sometimes need to construct frame_info_ptr objects around the | |
| 332 | sentinel_frame, which has level -1. Therefore, make the invalid frame | |
| 333 | level value -2. */ | |
| 334 | static constexpr int invalid_level = -2; | |
| 335 | ||
| 908de5e6 SM |
336 | /* Use the cached frame level and id to reinflate the pointer, and return |
| 337 | it. */ | |
| 338 | frame_info *reinflate () const; | |
| 339 | ||
| 43e8c9ce | 340 | /* The underlying pointer. */ |
| 908de5e6 | 341 | mutable frame_info *m_ptr = nullptr; |
| 43e8c9ce | 342 | |
| 836a8d37 SM |
343 | /* The frame_id of the underlying pointer. |
| 344 | ||
| 345 | For the current target frames (frames with level 0, obtained through | |
| 346 | get_current_frame), we don't save the frame id, we leave it at | |
| 347 | null_frame_id. For user-created frames (also with level 0, but created | |
| 348 | with create_new_frame), we do save the id. */ | |
| 43e8c9ce SM |
349 | frame_id m_cached_id = null_frame_id; |
| 350 | ||
| 351 | /* The frame level of the underlying pointer. */ | |
| 352 | int m_cached_level = invalid_level; | |
| 353 | ||
| 354 | /* All frame_info_ptr objects are kept on an intrusive list. | |
| 355 | This keeps their construction and destruction costs | |
| 356 | reasonably small. */ | |
| 357 | static intrusive_list<frame_info_ptr> frame_list; | |
| 358 | ||
| 359 | /* A friend so it can invalidate the pointers. */ | |
| 360 | friend void reinit_frame_cache (); | |
| 361 | }; | |
| 362 | ||
| 363 | static inline bool | |
| 364 | operator== (const frame_info *self, const frame_info_ptr &other) | |
| 365 | { | |
| 908de5e6 SM |
366 | if (self == nullptr || other.is_null ()) |
| 367 | return self == nullptr && other.is_null (); | |
| 368 | ||
| 43e8c9ce SM |
369 | return self == other.get (); |
| 370 | } | |
| 371 | ||
| 372 | static inline bool | |
| 373 | operator== (const frame_info_ptr &self, const frame_info_ptr &other) | |
| 374 | { | |
| 908de5e6 SM |
375 | if (self.is_null () || other.is_null ()) |
| 376 | return self.is_null () && other.is_null (); | |
| 377 | ||
| 43e8c9ce SM |
378 | return self.get () == other.get (); |
| 379 | } | |
| 380 | ||
| 381 | static inline bool | |
| 382 | operator== (const frame_info_ptr &self, const frame_info *other) | |
| 383 | { | |
| 908de5e6 SM |
384 | if (self.is_null () || other == nullptr) |
| 385 | return self.is_null () && other == nullptr; | |
| 386 | ||
| 43e8c9ce SM |
387 | return self.get () == other; |
| 388 | } | |
| 389 | ||
| 390 | static inline bool | |
| 391 | operator!= (const frame_info *self, const frame_info_ptr &other) | |
| 392 | { | |
| 908de5e6 | 393 | return !(self == other); |
| 43e8c9ce SM |
394 | } |
| 395 | ||
| 396 | static inline bool | |
| 397 | operator!= (const frame_info_ptr &self, const frame_info_ptr &other) | |
| 398 | { | |
| 908de5e6 | 399 | return !(self == other); |
| 43e8c9ce SM |
400 | } |
| 401 | ||
| 402 | static inline bool | |
| 403 | operator!= (const frame_info_ptr &self, const frame_info *other) | |
| 404 | { | |
| 908de5e6 | 405 | return !(self == other); |
| 43e8c9ce SM |
406 | } |
| 407 | ||
| c97eb5d9 AC |
408 | /* For every stopped thread, GDB tracks two frames: current and |
| 409 | selected. Current frame is the inner most frame of the selected | |
| b021a221 | 410 | thread. Selected frame is the one being examined by the GDB |
| abc0af47 AC |
411 | CLI (selected using `up', `down', ...). The frames are created |
| 412 | on-demand (via get_prev_frame()) and then held in a frame cache. */ | |
| 413 | /* FIXME: cagney/2002-11-28: Er, there is a lie here. If you do the | |
| 4a0e2f88 | 414 | sequence: `thread 1; up; thread 2; thread 1' you lose thread 1's |
| abc0af47 AC |
415 | selected frame. At present GDB only tracks the selected frame of |
| 416 | the current thread. But be warned, that might change. */ | |
| c97eb5d9 AC |
417 | /* FIXME: cagney/2002-11-14: At any time, only one thread's selected |
| 418 | and current frame can be active. Switching threads causes gdb to | |
| 419 | discard all that cached frame information. Ulgh! Instead, current | |
| 420 | and selected frame should be bound to a thread. */ | |
| 421 | ||
| abc0af47 AC |
422 | /* On demand, create the inner most frame using information found in |
| 423 | the inferior. If the inner most frame can't be created, throw an | |
| 424 | error. */ | |
| bd2b40ac | 425 | extern frame_info_ptr get_current_frame (void); |
| c97eb5d9 | 426 | |
| 9d49bdc2 PA |
427 | /* Does the current target interface have enough state to be able to |
| 428 | query the current inferior for frame info, and is the inferior in a | |
| 429 | state where that is possible? */ | |
| 97916bfe | 430 | extern bool has_stack_frames (); |
| 9d49bdc2 | 431 | |
| abc0af47 AC |
432 | /* Invalidates the frame cache (this function should have been called |
| 433 | invalidate_cached_frames). | |
| 434 | ||
| 35f196d9 DJ |
435 | FIXME: cagney/2002-11-28: There should be two methods: one that |
| 436 | reverts the thread's selected frame back to current frame (for when | |
| 437 | the inferior resumes) and one that does not (for when the user | |
| 438 | modifies the target invalidating the frame cache). */ | |
| c97eb5d9 AC |
439 | extern void reinit_frame_cache (void); |
| 440 | ||
| 79952e69 PA |
441 | /* Return the selected frame. Always returns non-NULL. If there |
| 442 | isn't an inferior sufficient for creating a frame, an error is | |
| 443 | thrown. When MESSAGE is non-NULL, use it for the error message, | |
| 97916bfe | 444 | otherwise use a generic error message. */ |
| 6e7f8b9c AC |
445 | /* FIXME: cagney/2002-11-28: At present, when there is no selected |
| 446 | frame, this function always returns the current (inner most) frame. | |
| 447 | It should instead, when a thread has previously had its frame | |
| 448 | selected (but not resumed) and the frame cache invalidated, find | |
| 449 | and then return that thread's previously selected frame. */ | |
| bd2b40ac | 450 | extern frame_info_ptr get_selected_frame (const char *message = nullptr); |
| eb8c0621 | 451 | |
| 1de4b515 | 452 | /* Select a specific frame. */ |
| 8480a37e | 453 | extern void select_frame (const frame_info_ptr &); |
| abc0af47 | 454 | |
| 79952e69 PA |
455 | /* Save the frame ID and frame level of the selected frame in FRAME_ID |
| 456 | and FRAME_LEVEL, to be restored later with restore_selected_frame. | |
| 457 | ||
| 458 | This is preferred over getting the same info out of | |
| 459 | get_selected_frame directly because this function does not create | |
| 460 | the selected-frame's frame_info object if it hasn't been created | |
| 461 | yet, and thus is more efficient and doesn't throw. */ | |
| 462 | extern void save_selected_frame (frame_id *frame_id, int *frame_level) | |
| 463 | noexcept; | |
| 464 | ||
| 465 | /* Restore selected frame as saved with save_selected_frame. | |
| 466 | ||
| 467 | Does not try to find the corresponding frame_info object. Instead | |
| 468 | the next call to get_selected_frame will look it up and cache the | |
| 469 | result. | |
| 470 | ||
| 471 | This function does not throw. It is designed to be safe to called | |
| 472 | from the destructors of RAII types. */ | |
| 473 | extern void restore_selected_frame (frame_id frame_id, int frame_level) | |
| 474 | noexcept; | |
| 475 | ||
| c97eb5d9 AC |
476 | /* Given a FRAME, return the next (more inner, younger) or previous |
| 477 | (more outer, older) frame. */ | |
| 8480a37e SM |
478 | extern frame_info_ptr get_prev_frame (const frame_info_ptr &); |
| 479 | extern frame_info_ptr get_next_frame (const frame_info_ptr &); | |
| c97eb5d9 | 480 | |
| df433d31 KB |
481 | /* Like get_next_frame(), but allows return of the sentinel frame. NULL |
| 482 | is never returned. */ | |
| 8480a37e | 483 | extern frame_info_ptr get_next_frame_sentinel_okay (const frame_info_ptr &); |
| df433d31 | 484 | |
| 51d48146 PA |
485 | /* Return a "struct frame_info" corresponding to the frame that called |
| 486 | THIS_FRAME. Returns NULL if there is no such frame. | |
| 487 | ||
| 488 | Unlike get_prev_frame, this function always tries to unwind the | |
| 489 | frame. */ | |
| 8480a37e | 490 | extern frame_info_ptr get_prev_frame_always (const frame_info_ptr &); |
| 51d48146 | 491 | |
| 04e2ac7b SM |
492 | /* Given a frame's ID, relocate the frame. Returns NULL if the frame |
| 493 | is not found. */ | |
| 494 | extern frame_info_ptr frame_find_by_id (frame_id id); | |
| 495 | ||
| c97eb5d9 AC |
496 | /* Base attributes of a frame: */ |
| 497 | ||
| 498 | /* The frame's `resume' address. Where the program will resume in | |
| ef6e7e13 AC |
499 | this frame. |
| 500 | ||
| 501 | This replaced: frame->pc; */ | |
| 8480a37e | 502 | extern CORE_ADDR get_frame_pc (const frame_info_ptr &); |
| c97eb5d9 | 503 | |
| e3eebbd7 PA |
504 | /* Same as get_frame_pc, but return a boolean indication of whether |
| 505 | the PC is actually available, instead of throwing an error. */ | |
| 506 | ||
| a1be365e GL |
507 | extern std::optional<CORE_ADDR> get_frame_pc_if_available |
| 508 | (const frame_info_ptr &frame); | |
| e3eebbd7 | 509 | |
| 4a0e2f88 | 510 | /* An address (not necessarily aligned to an instruction boundary) |
| 8edd5d01 AC |
511 | that falls within THIS frame's code block. |
| 512 | ||
| 513 | When a function call is the last statement in a block, the return | |
| 514 | address for the call may land at the start of the next block. | |
| 515 | Similarly, if a no-return function call is the last statement in | |
| 516 | the function, the return address may end up pointing beyond the | |
| 517 | function, and possibly at the start of the next function. | |
| 518 | ||
| 519 | These methods make an allowance for this. For call frames, this | |
| 520 | function returns the frame's PC-1 which "should" be an address in | |
| 521 | the frame's block. */ | |
| 522 | ||
| 8480a37e | 523 | extern CORE_ADDR get_frame_address_in_block (const frame_info_ptr &this_frame); |
| 93d42b30 | 524 | |
| e3eebbd7 PA |
525 | /* Same as get_frame_address_in_block, but returns a boolean |
| 526 | indication of whether the frame address is determinable (when the | |
| 527 | PC is unavailable, it will not be), instead of possibly throwing an | |
| 528 | error trying to read an unavailable PC. */ | |
| 529 | ||
| 8480a37e | 530 | extern bool get_frame_address_in_block_if_available (const frame_info_ptr &this_frame, |
| 97916bfe | 531 | CORE_ADDR *pc); |
| e3eebbd7 | 532 | |
| a9e5fdc2 AC |
533 | /* The frame's inner-most bound. AKA the stack-pointer. Confusingly |
| 534 | known as top-of-stack. */ | |
| 535 | ||
| 8480a37e | 536 | extern CORE_ADDR get_frame_sp (const frame_info_ptr &); |
| a9e5fdc2 | 537 | |
| be41e9f4 AC |
538 | /* Following on from the `resume' address. Return the entry point |
| 539 | address of the function containing that resume address, or zero if | |
| 540 | that function isn't known. */ | |
| 8480a37e | 541 | extern CORE_ADDR get_frame_func (const frame_info_ptr &fi); |
| be41e9f4 | 542 | |
| e3eebbd7 PA |
543 | /* Same as get_frame_func, but returns a boolean indication of whether |
| 544 | the frame function is determinable (when the PC is unavailable, it | |
| 545 | will not be), instead of possibly throwing an error trying to read | |
| 546 | an unavailable PC. */ | |
| 547 | ||
| 8480a37e | 548 | extern bool get_frame_func_if_available (const frame_info_ptr &fi, CORE_ADDR *); |
| e3eebbd7 | 549 | |
| 1058bca7 AC |
550 | /* Closely related to the resume address, various symbol table |
| 551 | attributes that are determined by the PC. Note that for a normal | |
| 552 | frame, the PC refers to the resume address after the return, and | |
| 553 | not the call instruction. In such a case, the address is adjusted | |
| 4a0e2f88 JM |
554 | so that it (approximately) identifies the call site (and not the |
| 555 | return site). | |
| 1058bca7 AC |
556 | |
| 557 | NOTE: cagney/2002-11-28: The frame cache could be used to cache the | |
| 558 | computed value. Working on the assumption that the bottle-neck is | |
| 559 | in the single step code, and that code causes the frame cache to be | |
| 560 | constantly flushed, caching things in a frame is probably of little | |
| 561 | benefit. As they say `show us the numbers'. | |
| 562 | ||
| 563 | NOTE: cagney/2002-11-28: Plenty more where this one came from: | |
| 564 | find_frame_block(), find_frame_partial_function(), | |
| 565 | find_frame_symtab(), find_frame_function(). Each will need to be | |
| 566 | carefully considered to determine if the real intent was for it to | |
| 567 | apply to the PC or the adjusted PC. */ | |
| 8480a37e | 568 | extern symtab_and_line find_frame_sal (const frame_info_ptr &frame); |
| 1058bca7 | 569 | |
| 7abfe014 | 570 | /* Set the current source and line to the location given by frame |
| 5166082f | 571 | FRAME, if possible. */ |
| 7abfe014 | 572 | |
| 8480a37e | 573 | void set_current_sal_from_frame (const frame_info_ptr &); |
| 7abfe014 | 574 | |
| da62e633 AC |
575 | /* Return the frame base (what ever that is) (DEPRECATED). |
| 576 | ||
| 577 | Old code was trying to use this single method for two conflicting | |
| 578 | purposes. Such code needs to be updated to use either of: | |
| 579 | ||
| 580 | get_frame_id: A low level frame unique identifier, that consists of | |
| 581 | both a stack and a function address, that can be used to uniquely | |
| 582 | identify a frame. This value is determined by the frame's | |
| 583 | low-level unwinder, the stack part [typically] being the | |
| 584 | top-of-stack of the previous frame, and the function part being the | |
| 585 | function's start address. Since the correct identification of a | |
| 766062f6 | 586 | frameless function requires both a stack and function address, |
| da62e633 AC |
587 | the old get_frame_base method was not sufficient. |
| 588 | ||
| 589 | get_frame_base_address: get_frame_locals_address: | |
| 973c5759 | 590 | get_frame_args_address: A set of high-level debug-info dependent |
| da62e633 AC |
591 | addresses that fall within the frame. These addresses almost |
| 592 | certainly will not match the stack address part of a frame ID (as | |
| ef6e7e13 AC |
593 | returned by get_frame_base). |
| 594 | ||
| 595 | This replaced: frame->frame; */ | |
| c193f6ac | 596 | |
| 8480a37e | 597 | extern CORE_ADDR get_frame_base (const frame_info_ptr &); |
| c193f6ac | 598 | |
| 33b5899f | 599 | /* Return the per-frame unique identifier. Can be used to relocate a |
| 7a424e99 | 600 | frame after a frame cache flush (and other similar operations). If |
| a0cbd650 | 601 | FI is NULL, return the null_frame_id. */ |
| 8480a37e SM |
602 | extern frame_id get_frame_id (const frame_info_ptr &fi); |
| 603 | extern frame_id get_stack_frame_id (const frame_info_ptr &fi); | |
| 604 | extern frame_id frame_unwind_caller_id (const frame_info_ptr &next_frame); | |
| c97eb5d9 | 605 | |
| da62e633 AC |
606 | /* Assuming that a frame is `normal', return its base-address, or 0 if |
| 607 | the information isn't available. NOTE: This address is really only | |
| 608 | meaningful to the frame's high-level debug info. */ | |
| 8480a37e | 609 | extern CORE_ADDR get_frame_base_address (const frame_info_ptr &); |
| da62e633 | 610 | |
| 6bfb3e36 AC |
611 | /* Assuming that a frame is `normal', return the base-address of the |
| 612 | local variables, or 0 if the information isn't available. NOTE: | |
| da62e633 AC |
613 | This address is really only meaningful to the frame's high-level |
| 614 | debug info. Typically, the argument and locals share a single | |
| 615 | base-address. */ | |
| 8480a37e | 616 | extern CORE_ADDR get_frame_locals_address (const frame_info_ptr &); |
| da62e633 | 617 | |
| 6bfb3e36 AC |
618 | /* Assuming that a frame is `normal', return the base-address of the |
| 619 | parameter list, or 0 if that information isn't available. NOTE: | |
| 620 | This address is really only meaningful to the frame's high-level | |
| 621 | debug info. Typically, the argument and locals share a single | |
| da62e633 | 622 | base-address. */ |
| 8480a37e | 623 | extern CORE_ADDR get_frame_args_address (const frame_info_ptr &); |
| da62e633 | 624 | |
| c97eb5d9 AC |
625 | /* The frame's level: 0 for innermost, 1 for its caller, ...; or -1 |
| 626 | for an invalid frame). */ | |
| 8480a37e | 627 | extern int frame_relative_level (const frame_info_ptr &fi); |
| c97eb5d9 | 628 | |
| 93d42b30 | 629 | /* Return the frame's type. */ |
| 5a203e44 | 630 | |
| 8480a37e | 631 | extern enum frame_type get_frame_type (const frame_info_ptr &); |
| 6c95b8df PA |
632 | |
| 633 | /* Return the frame's program space. */ | |
| 8480a37e | 634 | extern struct program_space *get_frame_program_space (const frame_info_ptr &); |
| 6c95b8df PA |
635 | |
| 636 | /* Unwind THIS frame's program space from the NEXT frame. */ | |
| 8480a37e | 637 | extern struct program_space *frame_unwind_program_space (const frame_info_ptr &); |
| 6c95b8df | 638 | |
| 8b86c959 YQ |
639 | class address_space; |
| 640 | ||
| 6c95b8df | 641 | /* Return the frame's address space. */ |
| 8480a37e | 642 | extern const address_space *get_frame_address_space (const frame_info_ptr &); |
| 5a203e44 | 643 | |
| 19b83d5c TT |
644 | /* A frame may have a "static link". That is, in some languages, a |
| 645 | nested function may have access to variables from the enclosing | |
| 646 | block and frame. This function looks for a frame's static link. | |
| 647 | If found, returns the corresponding frame; otherwise, returns a | |
| 648 | null frame_info_ptr. */ | |
| 8480a37e | 649 | extern frame_info_ptr frame_follow_static_link (const frame_info_ptr &frame); |
| 19b83d5c | 650 | |
| 55feb689 DJ |
651 | /* For frames where we can not unwind further, describe why. */ |
| 652 | ||
| 653 | enum unwind_stop_reason | |
| 654 | { | |
| 2231f1fb KP |
655 | #define SET(name, description) name, |
| 656 | #define FIRST_ENTRY(name) UNWIND_FIRST = name, | |
| 657 | #define LAST_ENTRY(name) UNWIND_LAST = name, | |
| 658 | #define FIRST_ERROR(name) UNWIND_FIRST_ERROR = name, | |
| 659 | ||
| 660 | #include "unwind_stop_reasons.def" | |
| 661 | #undef SET | |
| 662 | #undef FIRST_ENTRY | |
| 663 | #undef LAST_ENTRY | |
| 664 | #undef FIRST_ERROR | |
| 55feb689 DJ |
665 | }; |
| 666 | ||
| 667 | /* Return the reason why we can't unwind past this frame. */ | |
| 668 | ||
| 8480a37e | 669 | enum unwind_stop_reason get_frame_unwind_stop_reason (const frame_info_ptr &); |
| 55feb689 | 670 | |
| 53e8a631 AB |
671 | /* Translate a reason code to an informative string. This converts the |
| 672 | generic stop reason codes into a generic string describing the code. | |
| 673 | For a possibly frame specific string explaining the stop reason, use | |
| 674 | FRAME_STOP_REASON_STRING instead. */ | |
| 55feb689 | 675 | |
| 70e38b8e | 676 | const char *unwind_stop_reason_to_string (enum unwind_stop_reason); |
| 55feb689 | 677 | |
| 53e8a631 AB |
678 | /* Return a possibly frame specific string explaining why the unwind |
| 679 | stopped here. E.g., if unwinding tripped on a memory error, this | |
| 680 | will return the error description string, which includes the address | |
| 681 | that we failed to access. If there's no specific reason stored for | |
| 682 | a frame then a generic reason string will be returned. | |
| 683 | ||
| 684 | Should only be called for frames that don't have a previous frame. */ | |
| 685 | ||
| 8480a37e | 686 | const char *frame_stop_reason_string (const frame_info_ptr &); |
| 53e8a631 | 687 | |
| c97eb5d9 | 688 | /* Unwind the stack frame so that the value of REGNUM, in the previous |
| 7fcdec02 | 689 | (up, older) frame is returned. If VALUE is zero-sized, don't |
| c97eb5d9 AC |
690 | fetch/compute the value. Instead just return the location of the |
| 691 | value. */ | |
| 8480a37e | 692 | extern void frame_register_unwind (const frame_info_ptr &frame, int regnum, |
| 0fdb4f18 PA |
693 | int *optimizedp, int *unavailablep, |
| 694 | enum lval_type *lvalp, | |
| c97eb5d9 | 695 | CORE_ADDR *addrp, int *realnump, |
| 7fcdec02 | 696 | gdb::array_view<gdb_byte> value = {}); |
| c97eb5d9 | 697 | |
| f0e7d0e8 AC |
698 | /* Fetch a register from this, or unwind a register from the next |
| 699 | frame. Note that the get_frame methods are wrappers to | |
| 700 | frame->next->unwind. They all [potentially] throw an error if the | |
| 669fac23 DJ |
701 | fetch fails. The value methods never return NULL, but usually |
| 702 | do return a lazy value. */ | |
| c97eb5d9 | 703 | |
| 8480a37e | 704 | extern void frame_unwind_register (const frame_info_ptr &next_frame, |
| 7fcdec02 | 705 | int regnum, gdb::array_view<gdb_byte> buf); |
| 8480a37e | 706 | extern void get_frame_register (const frame_info_ptr &frame, |
| 7fcdec02 | 707 | int regnum, gdb::array_view<gdb_byte> buf); |
| f0e7d0e8 | 708 | |
| 8480a37e | 709 | struct value *frame_unwind_register_value (const frame_info_ptr &next_frame, |
| 669fac23 | 710 | int regnum); |
| 8480a37e | 711 | struct value *get_frame_register_value (const frame_info_ptr &frame, |
| 669fac23 DJ |
712 | int regnum); |
| 713 | ||
| 8480a37e | 714 | extern LONGEST frame_unwind_register_signed (const frame_info_ptr &next_frame, |
| f0e7d0e8 | 715 | int regnum); |
| 8480a37e | 716 | extern LONGEST get_frame_register_signed (const frame_info_ptr &frame, |
| f0e7d0e8 | 717 | int regnum); |
| 8480a37e SM |
718 | extern ULONGEST frame_unwind_register_unsigned |
| 719 | (const frame_info_ptr &next_frame, int regnum); | |
| 720 | extern ULONGEST get_frame_register_unsigned (const frame_info_ptr &frame, | |
| f0e7d0e8 AC |
721 | int regnum); |
| 722 | ||
| 263689d8 | 723 | /* Read a register from this, or unwind a register from the next |
| ad5f7d6e PA |
724 | frame. Note that the read_frame methods are wrappers to |
| 725 | get_frame_register_value, that do not throw if the result is | |
| 726 | optimized out or unavailable. */ | |
| 727 | ||
| 8480a37e | 728 | extern bool read_frame_register_unsigned (const frame_info_ptr &frame, |
| 97916bfe | 729 | int regnum, ULONGEST *val); |
| 5b181d62 | 730 | |
| 584468de SM |
731 | /* The reverse. Store a register value relative to NEXT_FRAME's previous frame. |
| 732 | Note: this call makes the frame's state undefined. The register and frame | |
| 733 | caches must be flushed. */ | |
| 8480a37e | 734 | extern void put_frame_register (const frame_info_ptr &next_frame, int regnum, |
| f6e3d557 | 735 | gdb::array_view<const gdb_byte> buf); |
| ff2e87ac | 736 | |
| 9fc79b42 SM |
737 | /* Read LEN bytes from one or multiple registers starting with REGNUM in |
| 738 | NEXT_FRAME's previous frame, starting at OFFSET, into BUF. If the register | |
| 739 | contents are optimized out or unavailable, set *OPTIMIZEDP, *UNAVAILABLEP | |
| 740 | accordingly. */ | |
| 8480a37e SM |
741 | extern bool get_frame_register_bytes (const frame_info_ptr &next_frame, |
| 742 | int regnum, CORE_ADDR offset, | |
| bdec2917 | 743 | gdb::array_view<gdb_byte> buffer, |
| 97916bfe | 744 | int *optimizedp, int *unavailablep); |
| 00fa51f6 | 745 | |
| bdec2917 | 746 | /* Write bytes from BUFFER to one or multiple registers starting with REGNUM |
| 534dcbcb | 747 | in NEXT_FRAME's previous frame, starting at OFFSET. */ |
| 8480a37e SM |
748 | extern void put_frame_register_bytes (const frame_info_ptr &next_frame, |
| 749 | int regnum, CORE_ADDR offset, | |
| bdec2917 | 750 | gdb::array_view<const gdb_byte> buffer); |
| 00fa51f6 | 751 | |
| f18c5a73 AC |
752 | /* Unwind the PC. Strictly speaking return the resume address of the |
| 753 | calling frame. For GDB, `pc' is the resume address and not a | |
| 754 | specific register. */ | |
| 755 | ||
| 8480a37e | 756 | extern CORE_ADDR frame_unwind_caller_pc (const frame_info_ptr &next_frame); |
| f18c5a73 | 757 | |
| dbe9fe58 AC |
758 | /* Discard the specified frame. Restoring the registers to the state |
| 759 | of the caller. */ | |
| 8480a37e | 760 | extern void frame_pop (const frame_info_ptr &frame); |
| dbe9fe58 | 761 | |
| ae1e7417 AC |
762 | /* Return memory from the specified frame. A frame knows its thread / |
| 763 | LWP and hence can find its way down to a target. The assumption | |
| 764 | here is that the current and previous frame share a common address | |
| 765 | space. | |
| 766 | ||
| 767 | If the memory read fails, these methods throw an error. | |
| 768 | ||
| 769 | NOTE: cagney/2003-06-03: Should there be unwind versions of these | |
| 770 | methods? That isn't clear. Can code, for instance, assume that | |
| 771 | this and the previous frame's memory or architecture are identical? | |
| 772 | If architecture / memory changes are always separated by special | |
| 773 | adaptor frames this should be ok. */ | |
| 774 | ||
| 8480a37e | 775 | extern void get_frame_memory (const frame_info_ptr &this_frame, CORE_ADDR addr, |
| bdec2917 | 776 | gdb::array_view<gdb_byte> buffer); |
| 8480a37e | 777 | extern LONGEST get_frame_memory_signed (const frame_info_ptr &this_frame, |
| ae1e7417 | 778 | CORE_ADDR memaddr, int len); |
| 8480a37e | 779 | extern ULONGEST get_frame_memory_unsigned (const frame_info_ptr &this_frame, |
| ae1e7417 AC |
780 | CORE_ADDR memaddr, int len); |
| 781 | ||
| 97916bfe SM |
782 | /* Same as above, but return true zero when the entire memory read |
| 783 | succeeds, false otherwise. */ | |
| 8480a37e | 784 | extern bool safe_frame_unwind_memory (const frame_info_ptr &this_frame, CORE_ADDR addr, |
| bdec2917 | 785 | gdb::array_view<gdb_byte> buffer); |
| 304396fb | 786 | |
| ae1e7417 | 787 | /* Return this frame's architecture. */ |
| 8480a37e | 788 | extern gdbarch *get_frame_arch (const frame_info_ptr &this_frame); |
| ae1e7417 | 789 | |
| 36f15f55 | 790 | /* Return the previous frame's architecture. */ |
| 8480a37e | 791 | extern gdbarch *frame_unwind_arch (const frame_info_ptr &next_frame); |
| 36f15f55 UW |
792 | |
| 793 | /* Return the previous frame's architecture, skipping inline functions. */ | |
| 8480a37e | 794 | extern gdbarch *frame_unwind_caller_arch (const frame_info_ptr &next_frame); |
| 36f15f55 | 795 | |
| ae1e7417 | 796 | |
| 4b5e8d19 PW |
797 | /* Values for the source flag to be used in print_frame_info (). |
| 798 | For all the cases below, the address is never printed if | |
| 799 | 'set print address' is off. When 'set print address' is on, | |
| 800 | the address is printed if the program counter is not at the | |
| 801 | beginning of the source line of the frame | |
| 802 | and PRINT_WHAT is != LOC_AND_ADDRESS. */ | |
| c5394b80 | 803 | enum print_what |
| 4b5e8d19 PW |
804 | { |
| 805 | /* Print only the address, source line, like in stepi. */ | |
| 806 | SRC_LINE = -1, | |
| 807 | /* Print only the location, i.e. level, address, | |
| 808 | function, args (as controlled by 'set print frame-arguments'), | |
| 809 | file, line, line num. */ | |
| c5394b80 | 810 | LOCATION, |
| 0963b4bd | 811 | /* Print both of the above. */ |
| 4b5e8d19 PW |
812 | SRC_AND_LOC, |
| 813 | /* Print location only, print the address even if the program counter | |
| 814 | is at the beginning of the source line. */ | |
| 815 | LOC_AND_ADDRESS, | |
| 816 | /* Print only level and function, | |
| 817 | i.e. location only, without address, file, line, line num. */ | |
| 818 | SHORT_LOCATION | |
| c5394b80 JM |
819 | }; |
| 820 | ||
| 479ab5a0 AC |
821 | /* Allocate zero initialized memory from the frame cache obstack. |
| 822 | Appendices to the frame info (such as the unwind cache) should | |
| 823 | allocate memory using this method. */ | |
| 824 | ||
| 825 | extern void *frame_obstack_zalloc (unsigned long size); | |
| ab591bad SM |
826 | |
| 827 | /* Allocate one instance of T using frame_obstack_zalloc. */ | |
| 828 | ||
| 829 | template <typename T> | |
| 830 | T * | |
| 831 | frame_obstack_zalloc () | |
| 832 | { | |
| 833 | return static_cast<T *> (frame_obstack_zalloc (sizeof (T))); | |
| 834 | } | |
| 835 | ||
| 836 | /* Allocate N instances of T using frame_obstack_zalloc. */ | |
| 837 | ||
| 838 | template <typename T> | |
| 839 | T * | |
| 840 | frame_obstack_calloc (int n) | |
| 841 | { | |
| 842 | return static_cast<T *> (frame_obstack_zalloc (n * sizeof (T))); | |
| 843 | } | |
| c906108c | 844 | |
| daf6667d | 845 | class readonly_detached_regcache; |
| a81dcb05 | 846 | /* Create a regcache, and copy the frame's registers into it. */ |
| daf6667d | 847 | std::unique_ptr<readonly_detached_regcache> frame_save_as_regcache |
| 8480a37e | 848 | (const frame_info_ptr &this_frame); |
| a81dcb05 | 849 | |
| 8480a37e | 850 | extern const struct block *get_frame_block (const frame_info_ptr &, |
| 3977b71f | 851 | CORE_ADDR *addr_in_block); |
| c906108c | 852 | |
| 805e2818 AC |
853 | /* Return the `struct block' that belongs to the selected thread's |
| 854 | selected frame. If the inferior has no state, return NULL. | |
| 855 | ||
| 856 | NOTE: cagney/2002-11-29: | |
| 857 | ||
| 858 | No state? Does the inferior have any execution state (a core file | |
| 859 | does, an executable does not). At present the code tests | |
| 860 | `target_has_stack' but I'm left wondering if it should test | |
| 861 | `target_has_registers' or, even, a merged target_has_state. | |
| 862 | ||
| 863 | Should it look at the most recently specified SAL? If the target | |
| 864 | has no state, should this function try to extract a block from the | |
| 865 | most recently selected SAL? That way `list foo' would give it some | |
| 4a0e2f88 | 866 | sort of reference point. Then again, perhaps that would confuse |
| 805e2818 AC |
867 | things. |
| 868 | ||
| 869 | Calls to this function can be broken down into two categories: Code | |
| 870 | that uses the selected block as an additional, but optional, data | |
| 871 | point; Code that uses the selected block as a prop, when it should | |
| 872 | have the relevant frame/block/pc explicitly passed in. | |
| 873 | ||
| 874 | The latter can be eliminated by correctly parameterizing the code, | |
| 875 | the former though is more interesting. Per the "address" command, | |
| 4a0e2f88 | 876 | it occurs in the CLI code and makes it possible for commands to |
| 805e2818 AC |
877 | work, even when the inferior has no state. */ |
| 878 | ||
| 3977b71f | 879 | extern const struct block *get_selected_block (CORE_ADDR *addr_in_block); |
| c906108c | 880 | |
| 8480a37e | 881 | extern struct symbol *get_frame_function (const frame_info_ptr &); |
| c906108c | 882 | |
| a14ed312 | 883 | extern CORE_ADDR get_pc_function_start (CORE_ADDR); |
| c906108c | 884 | |
| 9efe17a3 | 885 | extern frame_info_ptr find_relative_frame (frame_info_ptr, int *); |
| c906108c | 886 | |
| 4034d0ff AT |
887 | /* Wrapper over print_stack_frame modifying current_uiout with UIOUT for |
| 888 | the function call. */ | |
| 889 | ||
| 890 | extern void print_stack_frame_to_uiout (struct ui_out *uiout, | |
| 8480a37e | 891 | const frame_info_ptr &, int print_level, |
| 4034d0ff AT |
892 | enum print_what print_what, |
| 893 | int set_current_sal); | |
| 894 | ||
| 8480a37e | 895 | extern void print_stack_frame (const frame_info_ptr &, int print_level, |
| 08d72866 PA |
896 | enum print_what print_what, |
| 897 | int set_current_sal); | |
| c906108c | 898 | |
| d4c16835 | 899 | extern void print_frame_info (const frame_print_options &fp_opts, |
| 8480a37e | 900 | const frame_info_ptr &, int print_level, |
| 08d72866 PA |
901 | enum print_what print_what, int args, |
| 902 | int set_current_sal); | |
| c906108c | 903 | |
| bd2b40ac | 904 | extern frame_info_ptr block_innermost_frame (const struct block *); |
| c906108c | 905 | |
| 8480a37e | 906 | extern bool deprecated_frame_register_read (const frame_info_ptr &frame, int regnum, |
| 7fcdec02 | 907 | gdb::array_view<gdb_byte> buf); |
| cda5a58a | 908 | |
| 36dc181b | 909 | /* From stack.c. */ |
| 93d86cef | 910 | |
| d4c16835 PA |
911 | /* The possible choices of "set print frame-arguments". */ |
| 912 | extern const char print_frame_arguments_all[]; | |
| 913 | extern const char print_frame_arguments_scalars[]; | |
| 914 | extern const char print_frame_arguments_none[]; | |
| 915 | ||
| 4b5e8d19 PW |
916 | /* The possible choices of "set print frame-info". */ |
| 917 | extern const char print_frame_info_auto[]; | |
| 918 | extern const char print_frame_info_source_line[]; | |
| 919 | extern const char print_frame_info_location[]; | |
| 920 | extern const char print_frame_info_source_and_location[]; | |
| 921 | extern const char print_frame_info_location_and_address[]; | |
| 922 | extern const char print_frame_info_short_location[]; | |
| 923 | ||
| d4c16835 | 924 | /* The possible choices of "set print entry-values". */ |
| e18b2753 JK |
925 | extern const char print_entry_values_no[]; |
| 926 | extern const char print_entry_values_only[]; | |
| 927 | extern const char print_entry_values_preferred[]; | |
| 928 | extern const char print_entry_values_if_needed[]; | |
| 929 | extern const char print_entry_values_both[]; | |
| 930 | extern const char print_entry_values_compact[]; | |
| 931 | extern const char print_entry_values_default[]; | |
| d4c16835 PA |
932 | |
| 933 | /* Data for the frame-printing "set print" settings exposed as command | |
| 934 | options. */ | |
| 935 | ||
| 936 | struct frame_print_options | |
| 937 | { | |
| 938 | const char *print_frame_arguments = print_frame_arguments_scalars; | |
| 4b5e8d19 | 939 | const char *print_frame_info = print_frame_info_auto; |
| d4c16835 PA |
940 | const char *print_entry_values = print_entry_values_default; |
| 941 | ||
| 491144b5 | 942 | /* If true, don't invoke pretty-printers for frame |
| d4c16835 | 943 | arguments. */ |
| 491144b5 | 944 | bool print_raw_frame_arguments; |
| d4c16835 PA |
945 | }; |
| 946 | ||
| 947 | /* The values behind the global "set print ..." settings. */ | |
| 948 | extern frame_print_options user_frame_print_options; | |
| e18b2753 | 949 | |
| 93d86cef JK |
950 | /* Inferior function parameter value read in from a frame. */ |
| 951 | ||
| 952 | struct frame_arg | |
| 953 | { | |
| 954 | /* Symbol for this parameter used for example for its name. */ | |
| 123cd851 | 955 | struct symbol *sym = nullptr; |
| 93d86cef JK |
956 | |
| 957 | /* Value of the parameter. It is NULL if ERROR is not NULL; if both VAL and | |
| 958 | ERROR are NULL this parameter's value should not be printed. */ | |
| 123cd851 | 959 | struct value *val = nullptr; |
| 93d86cef JK |
960 | |
| 961 | /* String containing the error message, it is more usually NULL indicating no | |
| 33b5899f | 962 | error occurred reading this parameter. */ |
| 123cd851 | 963 | gdb::unique_xmalloc_ptr<char> error; |
| e18b2753 JK |
964 | |
| 965 | /* One of the print_entry_values_* entries as appropriate specifically for | |
| 966 | this frame_arg. It will be different from print_entry_values. With | |
| 967 | print_entry_values_no this frame_arg should be printed as a normal | |
| 968 | parameter. print_entry_values_only says it should be printed as entry | |
| 969 | value parameter. print_entry_values_compact says it should be printed as | |
| 970 | both as a normal parameter and entry values parameter having the same | |
| 971 | value - print_entry_values_compact is not permitted fi ui_out_is_mi_like_p | |
| 972 | (in such case print_entry_values_no and print_entry_values_only is used | |
| 973 | for each parameter kind specifically. */ | |
| 123cd851 | 974 | const char *entry_kind = nullptr; |
| 93d86cef JK |
975 | }; |
| 976 | ||
| d4c16835 | 977 | extern void read_frame_arg (const frame_print_options &fp_opts, |
| 8480a37e | 978 | symbol *sym, const frame_info_ptr &frame, |
| e18b2753 JK |
979 | struct frame_arg *argp, |
| 980 | struct frame_arg *entryargp); | |
| 8480a37e | 981 | extern void read_frame_local (struct symbol *sym, const frame_info_ptr &frame, |
| 82a0a75f | 982 | struct frame_arg *argp); |
| 93d86cef | 983 | |
| 1d12d88f | 984 | extern void info_args_command (const char *, int); |
| 36dc181b | 985 | |
| 1d12d88f | 986 | extern void info_locals_command (const char *, int); |
| 36dc181b | 987 | |
| 0b39b52e | 988 | extern void return_command (const char *, int); |
| 36dc181b | 989 | |
| 669fac23 | 990 | /* Set FRAME's unwinder temporarily, so that we can call a sniffer. |
| 30a9c02f TT |
991 | If sniffing fails, the caller should be sure to call |
| 992 | frame_cleanup_after_sniffer. */ | |
| 669fac23 | 993 | |
| 8480a37e | 994 | extern void frame_prepare_for_sniffer (const frame_info_ptr &frame, |
| 30a9c02f TT |
995 | const struct frame_unwind *unwind); |
| 996 | ||
| 997 | /* Clean up after a failed (wrong unwinder) attempt to unwind past | |
| 998 | FRAME. */ | |
| 999 | ||
| 8480a37e | 1000 | extern void frame_cleanup_after_sniffer (const frame_info_ptr &frame); |
| abc0af47 | 1001 | |
| 206415a3 | 1002 | /* Notes (cagney/2002-11-27, drow/2003-09-06): |
| abc0af47 | 1003 | |
| 206415a3 DJ |
1004 | You might think that calls to this function can simply be replaced by a |
| 1005 | call to get_selected_frame(). | |
| abc0af47 | 1006 | |
| ce2826aa | 1007 | Unfortunately, it isn't that easy. |
| abc0af47 AC |
1008 | |
| 1009 | The relevant code needs to be audited to determine if it is | |
| 4a0e2f88 | 1010 | possible (or practical) to instead pass the applicable frame in as a |
| abc0af47 | 1011 | parameter. For instance, DEPRECATED_DO_REGISTERS_INFO() relied on |
| 6e7f8b9c | 1012 | the deprecated_selected_frame global, while its replacement, |
| abc0af47 | 1013 | PRINT_REGISTERS_INFO(), is parameterized with the selected frame. |
| 4a0e2f88 | 1014 | The only real exceptions occur at the edge (in the CLI code) where |
| abc0af47 AC |
1015 | user commands need to pick up the selected frame before proceeding. |
| 1016 | ||
| 206415a3 DJ |
1017 | There are also some functions called with a NULL frame meaning either "the |
| 1018 | program is not running" or "use the selected frame". | |
| 1019 | ||
| abc0af47 AC |
1020 | This is important. GDB is trying to stamp out the hack: |
| 1021 | ||
| 206415a3 DJ |
1022 | saved_frame = deprecated_safe_get_selected_frame (); |
| 1023 | select_frame (...); | |
| abc0af47 | 1024 | hack_using_global_selected_frame (); |
| 206415a3 | 1025 | select_frame (saved_frame); |
| 7dd88986 | 1026 | |
| 206415a3 | 1027 | Take care! |
| 7dd88986 DJ |
1028 | |
| 1029 | This function calls get_selected_frame if the inferior should have a | |
| 1030 | frame, or returns NULL otherwise. */ | |
| 1031 | ||
| bd2b40ac | 1032 | extern frame_info_ptr deprecated_safe_get_selected_frame (void); |
| abc0af47 | 1033 | |
| 18ea5ba4 | 1034 | /* Create a frame using the specified BASE and PC. */ |
| abc0af47 | 1035 | |
| bd2b40ac | 1036 | extern frame_info_ptr create_new_frame (CORE_ADDR base, CORE_ADDR pc); |
| abc0af47 | 1037 | |
| e7802207 TT |
1038 | /* Return true if the frame unwinder for frame FI is UNWINDER; false |
| 1039 | otherwise. */ | |
| 1040 | ||
| 8480a37e | 1041 | extern bool frame_unwinder_is (const frame_info_ptr &fi, const frame_unwind *unwinder); |
| e7802207 | 1042 | |
| 06096720 AB |
1043 | /* Return the language of FRAME. */ |
| 1044 | ||
| 8480a37e | 1045 | extern enum language get_frame_language (const frame_info_ptr &frame); |
| 06096720 | 1046 | |
| 2f3ef606 | 1047 | /* Return the first non-tailcall frame above FRAME or FRAME if it is not a |
| 33b4777c MM |
1048 | tailcall frame. Return NULL if FRAME is the start of a tailcall-only |
| 1049 | chain. */ | |
| 2f3ef606 | 1050 | |
| 8480a37e | 1051 | extern frame_info_ptr skip_tailcall_frames (const frame_info_ptr &frame); |
| 06096720 | 1052 | |
| 7eb89530 YQ |
1053 | /* Return the first frame above FRAME or FRAME of which the code is |
| 1054 | writable. */ | |
| 1055 | ||
| 8480a37e | 1056 | extern frame_info_ptr skip_unwritable_frames (const frame_info_ptr &frame); |
| 7eb89530 | 1057 | |
| d4c16835 PA |
1058 | /* Data for the "set backtrace" settings. */ |
| 1059 | ||
| 1060 | struct set_backtrace_options | |
| 1061 | { | |
| 1062 | /* Flag to indicate whether backtraces should continue past | |
| 1063 | main. */ | |
| 491144b5 | 1064 | bool backtrace_past_main = false; |
| d4c16835 PA |
1065 | |
| 1066 | /* Flag to indicate whether backtraces should continue past | |
| 1067 | entry. */ | |
| 491144b5 | 1068 | bool backtrace_past_entry = false; |
| d4c16835 PA |
1069 | |
| 1070 | /* Upper bound on the number of backtrace levels. Note this is not | |
| 1071 | exposed as a command option, because "backtrace" and "frame | |
| 1072 | apply" already have other means to set a frame count limit. */ | |
| 1073 | unsigned int backtrace_limit = UINT_MAX; | |
| 1074 | }; | |
| 1075 | ||
| 1076 | /* The corresponding option definitions. */ | |
| 1077 | extern const gdb::option::option_def set_backtrace_option_defs[2]; | |
| 1078 | ||
| 1079 | /* The values behind the global "set backtrace ..." settings. */ | |
| 1080 | extern set_backtrace_options user_set_backtrace_options; | |
| 1081 | ||
| e7bc9db8 PA |
1082 | /* Get the number of calls to reinit_frame_cache. */ |
| 1083 | ||
| 1084 | unsigned int get_frame_cache_generation (); | |
| 1085 | ||
| 3d31bc39 AH |
1086 | /* Mark that the PC value is masked for the previous frame. */ |
| 1087 | ||
| 8480a37e | 1088 | extern void set_frame_previous_pc_masked (const frame_info_ptr &frame); |
| 3d31bc39 AH |
1089 | |
| 1090 | /* Get whether the PC value is masked for the given frame. */ | |
| 1091 | ||
| 8480a37e | 1092 | extern bool get_frame_pc_masked (const frame_info_ptr &frame); |
| 3d31bc39 AH |
1093 | |
| 1094 | ||
| cc709640 | 1095 | #endif /* GDB_FRAME_H */ |