1*6881a400Schristos /* Definitions for dealing with stack frames, for GDB, the GNU debugger. 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 1986-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos This file is part of GDB. 6*6881a400Schristos 7*6881a400Schristos This program is free software; you can redistribute it and/or modify 8*6881a400Schristos it under the terms of the GNU General Public License as published by 9*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 10*6881a400Schristos (at your option) any later version. 11*6881a400Schristos 12*6881a400Schristos This program is distributed in the hope that it will be useful, 13*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*6881a400Schristos GNU General Public License for more details. 16*6881a400Schristos 17*6881a400Schristos You should have received a copy of the GNU General Public License 18*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*6881a400Schristos 20*6881a400Schristos #ifndef GDB_FRAME_ID_H 21*6881a400Schristos #define GDB_FRAME_ID_H 1 22*6881a400Schristos 23*6881a400Schristos /* Status of a given frame's stack. */ 24*6881a400Schristos 25*6881a400Schristos enum frame_id_stack_status 26*6881a400Schristos { 27*6881a400Schristos /* Stack address is invalid. */ 28*6881a400Schristos FID_STACK_INVALID = 0, 29*6881a400Schristos 30*6881a400Schristos /* Stack address is valid, and is found in the stack_addr field. */ 31*6881a400Schristos FID_STACK_VALID = 1, 32*6881a400Schristos 33*6881a400Schristos /* Sentinel frame. */ 34*6881a400Schristos FID_STACK_SENTINEL = 2, 35*6881a400Schristos 36*6881a400Schristos /* Outer frame. Since a frame's stack address is typically defined as the 37*6881a400Schristos value the stack pointer had prior to the activation of the frame, an outer 38*6881a400Schristos frame doesn't have a stack address. The frame ids of frames inlined in the 39*6881a400Schristos outer frame are also of this type. */ 40*6881a400Schristos FID_STACK_OUTER = 3, 41*6881a400Schristos 42*6881a400Schristos /* Stack address is unavailable. I.e., there's a valid stack, but 43*6881a400Schristos we don't know where it is (because memory or registers we'd 44*6881a400Schristos compute it from were not collected). */ 45*6881a400Schristos FID_STACK_UNAVAILABLE = -1 46*6881a400Schristos }; 47*6881a400Schristos 48*6881a400Schristos /* The frame object's ID. This provides a per-frame unique identifier 49*6881a400Schristos that can be used to relocate a `struct frame_info' after a target 50*6881a400Schristos resume or a frame cache destruct. It of course assumes that the 51*6881a400Schristos inferior hasn't unwound the stack past that frame. */ 52*6881a400Schristos 53*6881a400Schristos struct frame_id 54*6881a400Schristos { 55*6881a400Schristos /* The frame's stack address. This shall be constant through out 56*6881a400Schristos the lifetime of a frame. Note that this requirement applies to 57*6881a400Schristos not just the function body, but also the prologue and (in theory 58*6881a400Schristos at least) the epilogue. Since that value needs to fall either on 59*6881a400Schristos the boundary, or within the frame's address range, the frame's 60*6881a400Schristos outer-most address (the inner-most address of the previous frame) 61*6881a400Schristos is used. Watch out for all the legacy targets that still use the 62*6881a400Schristos function pointer register or stack pointer register. They are 63*6881a400Schristos wrong. 64*6881a400Schristos 65*6881a400Schristos This field is valid only if frame_id.stack_status is 66*6881a400Schristos FID_STACK_VALID. It will be 0 for other 67*6881a400Schristos FID_STACK_... statuses. */ 68*6881a400Schristos CORE_ADDR stack_addr; 69*6881a400Schristos 70*6881a400Schristos /* The frame's code address. This shall be constant through out the 71*6881a400Schristos lifetime of the frame. While the PC (a.k.a. resume address) 72*6881a400Schristos changes as the function is executed, this code address cannot. 73*6881a400Schristos Typically, it is set to the address of the entry point of the 74*6881a400Schristos frame's function (as returned by get_frame_func). 75*6881a400Schristos 76*6881a400Schristos For inlined functions (INLINE_DEPTH != 0), this is the address of 77*6881a400Schristos the first executed instruction in the block corresponding to the 78*6881a400Schristos inlined function. 79*6881a400Schristos 80*6881a400Schristos This field is valid only if code_addr_p is true. Otherwise, this 81*6881a400Schristos frame is considered to have a wildcard code address, i.e. one that 82*6881a400Schristos matches every address value in frame comparisons. */ 83*6881a400Schristos CORE_ADDR code_addr; 84*6881a400Schristos 85*6881a400Schristos /* The frame's special address. This shall be constant through out the 86*6881a400Schristos lifetime of the frame. This is used for architectures that may have 87*6881a400Schristos frames that do not change the stack but are still distinct and have 88*6881a400Schristos some form of distinct identifier (e.g. the ia64 which uses a 2nd 89*6881a400Schristos stack for registers). This field is treated as unordered - i.e. will 90*6881a400Schristos not be used in frame ordering comparisons. 91*6881a400Schristos 92*6881a400Schristos This field is valid only if special_addr_p is true. Otherwise, this 93*6881a400Schristos frame is considered to have a wildcard special address, i.e. one that 94*6881a400Schristos matches every address value in frame comparisons. */ 95*6881a400Schristos CORE_ADDR special_addr; 96*6881a400Schristos 97*6881a400Schristos /* Flags to indicate the above fields have valid contents. */ 98*6881a400Schristos ENUM_BITFIELD(frame_id_stack_status) stack_status : 3; 99*6881a400Schristos unsigned int code_addr_p : 1; 100*6881a400Schristos unsigned int special_addr_p : 1; 101*6881a400Schristos 102*6881a400Schristos /* It is non-zero for a frame made up by GDB without stack data 103*6881a400Schristos representation in inferior, such as INLINE_FRAME or TAILCALL_FRAME. 104*6881a400Schristos Caller of inlined function will have it zero, each more inner called frame 105*6881a400Schristos will have it increasingly one, two etc. Similarly for TAILCALL_FRAME. */ 106*6881a400Schristos int artificial_depth; 107*6881a400Schristos 108*6881a400Schristos /* Return a string representation of this frame id. */ 109*6881a400Schristos std::string to_string () const; 110*6881a400Schristos 111*6881a400Schristos /* Returns true when this frame_id and R identify the same 112*6881a400Schristos frame. */ 113*6881a400Schristos bool operator== (const frame_id &r) const; 114*6881a400Schristos 115*6881a400Schristos /* Inverse of ==. */ 116*6881a400Schristos bool operator!= (const frame_id &r) const 117*6881a400Schristos { 118*6881a400Schristos return !(*this == r); 119*6881a400Schristos } 120*6881a400Schristos }; 121*6881a400Schristos 122*6881a400Schristos /* Methods for constructing and comparing Frame IDs. */ 123*6881a400Schristos 124*6881a400Schristos /* For convenience. All fields are zero. This means "there is no frame". */ 125*6881a400Schristos extern const struct frame_id null_frame_id; 126*6881a400Schristos 127*6881a400Schristos /* Sentinel frame. */ 128*6881a400Schristos extern const struct frame_id sentinel_frame_id; 129*6881a400Schristos 130*6881a400Schristos /* This means "there is no frame ID, but there is a frame". It should be 131*6881a400Schristos replaced by best-effort frame IDs for the outermost frame, somehow. 132*6881a400Schristos The implementation is only special_addr_p set. */ 133*6881a400Schristos extern const struct frame_id outer_frame_id; 134*6881a400Schristos 135*6881a400Schristos #endif /* ifdef GDB_FRAME_ID_H */ 136