15796c8dcSSimon Schubert /* Definitions for a frame unwinder, for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*c50c785cSJohn Marino Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011 4cf7f2e2dSJohn Marino Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This file is part of GDB. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 95796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 105796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 115796c8dcSSimon Schubert (at your option) any later version. 125796c8dcSSimon Schubert 135796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 145796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 155796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165796c8dcSSimon Schubert GNU General Public License for more details. 175796c8dcSSimon Schubert 185796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 195796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert #if !defined (FRAME_UNWIND_H) 225796c8dcSSimon Schubert #define FRAME_UNWIND_H 1 235796c8dcSSimon Schubert 245796c8dcSSimon Schubert struct frame_data; 255796c8dcSSimon Schubert struct frame_info; 265796c8dcSSimon Schubert struct frame_id; 275796c8dcSSimon Schubert struct frame_unwind; 285796c8dcSSimon Schubert struct gdbarch; 295796c8dcSSimon Schubert struct regcache; 305796c8dcSSimon Schubert struct value; 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert #include "frame.h" /* For enum frame_type. */ 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert /* The following unwind functions assume a chain of frames forming the 355796c8dcSSimon Schubert sequence: (outer) prev <-> this <-> next (inner). All the 36*c50c785cSJohn Marino functions are called with this frame's `struct frame_info' and 37*c50c785cSJohn Marino prologue cache. 385796c8dcSSimon Schubert 395796c8dcSSimon Schubert THIS frame's register values can be obtained by unwinding NEXT 405796c8dcSSimon Schubert frame's registers (a recursive operation). 415796c8dcSSimon Schubert 425796c8dcSSimon Schubert THIS frame's prologue cache can be used to cache information such 435796c8dcSSimon Schubert as where this frame's prologue stores the previous frame's 445796c8dcSSimon Schubert registers. */ 455796c8dcSSimon Schubert 465796c8dcSSimon Schubert /* Given THIS frame, take a whiff of its registers (namely 475796c8dcSSimon Schubert the PC and attributes) and if SELF is the applicable unwinder, 485796c8dcSSimon Schubert return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, 515796c8dcSSimon Schubert struct frame_info *this_frame, 525796c8dcSSimon Schubert void **this_prologue_cache); 535796c8dcSSimon Schubert 54*c50c785cSJohn Marino typedef enum unwind_stop_reason (frame_unwind_stop_reason_ftype) 55*c50c785cSJohn Marino (struct frame_info *this_frame, void **this_prologue_cache); 56*c50c785cSJohn Marino 575796c8dcSSimon Schubert /* A default frame sniffer which always accepts the frame. Used by 585796c8dcSSimon Schubert fallback prologue unwinders. */ 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert int default_frame_sniffer (const struct frame_unwind *self, 615796c8dcSSimon Schubert struct frame_info *this_frame, 625796c8dcSSimon Schubert void **this_prologue_cache); 635796c8dcSSimon Schubert 64*c50c785cSJohn Marino /* A default stop_reason callback which always claims the frame is 65*c50c785cSJohn Marino unwindable. */ 66*c50c785cSJohn Marino 67*c50c785cSJohn Marino enum unwind_stop_reason 68*c50c785cSJohn Marino default_frame_unwind_stop_reason (struct frame_info *this_frame, 69*c50c785cSJohn Marino void **this_cache); 70*c50c785cSJohn Marino 715796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 725796c8dcSSimon Schubert use THIS frame, and through it the NEXT frame's register unwind 735796c8dcSSimon Schubert method, to determine the frame ID of THIS frame. 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert A frame ID provides an invariant that can be used to re-identify an 765796c8dcSSimon Schubert instance of a frame. It is a combination of the frame's `base' and 775796c8dcSSimon Schubert the frame's function's code address. 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert Traditionally, THIS frame's ID was determined by examining THIS 805796c8dcSSimon Schubert frame's function's prologue, and identifying the register/offset 815796c8dcSSimon Schubert used as THIS frame's base. 825796c8dcSSimon Schubert 835796c8dcSSimon Schubert Example: An examination of THIS frame's prologue reveals that, on 845796c8dcSSimon Schubert entry, it saves the PC(+12), SP(+8), and R1(+4) registers 855796c8dcSSimon Schubert (decrementing the SP by 12). Consequently, the frame ID's base can 865796c8dcSSimon Schubert be determined by adding 12 to the THIS frame's stack-pointer, and 875796c8dcSSimon Schubert the value of THIS frame's SP can be obtained by unwinding the NEXT 885796c8dcSSimon Schubert frame's SP. 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 915796c8dcSSimon Schubert with the other unwind methods. Memory for that cache should be 925796c8dcSSimon Schubert allocated using FRAME_OBSTACK_ZALLOC(). */ 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert typedef void (frame_this_id_ftype) (struct frame_info *this_frame, 955796c8dcSSimon Schubert void **this_prologue_cache, 965796c8dcSSimon Schubert struct frame_id *this_id); 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 995796c8dcSSimon Schubert use THIS frame, and implicitly the NEXT frame's register unwind 1005796c8dcSSimon Schubert method, to unwind THIS frame's registers (returning the value of 1015796c8dcSSimon Schubert the specified register REGNUM in the previous frame). 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert Traditionally, THIS frame's registers were unwound by examining 1045796c8dcSSimon Schubert THIS frame's function's prologue and identifying which registers 1055796c8dcSSimon Schubert that prolog code saved on the stack. 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert Example: An examination of THIS frame's prologue reveals that, on 1085796c8dcSSimon Schubert entry, it saves the PC(+12), SP(+8), and R1(+4) registers 1095796c8dcSSimon Schubert (decrementing the SP by 12). Consequently, the value of the PC 1105796c8dcSSimon Schubert register in the previous frame is found in memory at SP+12, and 1115796c8dcSSimon Schubert THIS frame's SP can be obtained by unwinding the NEXT frame's SP. 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert This function takes THIS_FRAME as an argument. It can find the 1145796c8dcSSimon Schubert values of registers in THIS frame by calling get_frame_register 1155796c8dcSSimon Schubert (THIS_FRAME), and reinvoke itself to find other registers in the 1165796c8dcSSimon Schubert PREVIOUS frame by calling frame_unwind_register (THIS_FRAME). 1175796c8dcSSimon Schubert 1185796c8dcSSimon Schubert The result is a GDB value object describing the register value. It 1195796c8dcSSimon Schubert may be a lazy reference to memory, a lazy reference to the value of 1205796c8dcSSimon Schubert a register in THIS frame, or a non-lvalue. 1215796c8dcSSimon Schubert 1225796c8dcSSimon Schubert THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 1235796c8dcSSimon Schubert with the other unwind methods. Memory for that cache should be 1245796c8dcSSimon Schubert allocated using FRAME_OBSTACK_ZALLOC(). */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert typedef struct value * (frame_prev_register_ftype) 1275796c8dcSSimon Schubert (struct frame_info *this_frame, void **this_prologue_cache, 1285796c8dcSSimon Schubert int regnum); 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert /* Deallocate extra memory associated with the frame cache if any. */ 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert typedef void (frame_dealloc_cache_ftype) (struct frame_info *self, 1335796c8dcSSimon Schubert void *this_cache); 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 1365796c8dcSSimon Schubert use THIS frame, and implicitly the NEXT frame's register unwind 1375796c8dcSSimon Schubert method, return PREV frame's architecture. */ 1385796c8dcSSimon Schubert 1395796c8dcSSimon Schubert typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame, 1405796c8dcSSimon Schubert void **this_prologue_cache); 1415796c8dcSSimon Schubert 1425796c8dcSSimon Schubert struct frame_unwind 1435796c8dcSSimon Schubert { 1445796c8dcSSimon Schubert /* The frame's type. Should this instead be a collection of 1455796c8dcSSimon Schubert predicates that test the frame for various attributes? */ 1465796c8dcSSimon Schubert enum frame_type type; 1475796c8dcSSimon Schubert /* Should an attribute indicating the frame's address-in-block go 1485796c8dcSSimon Schubert here? */ 149*c50c785cSJohn Marino frame_unwind_stop_reason_ftype *stop_reason; 1505796c8dcSSimon Schubert frame_this_id_ftype *this_id; 1515796c8dcSSimon Schubert frame_prev_register_ftype *prev_register; 1525796c8dcSSimon Schubert const struct frame_data *unwind_data; 1535796c8dcSSimon Schubert frame_sniffer_ftype *sniffer; 1545796c8dcSSimon Schubert frame_dealloc_cache_ftype *dealloc_cache; 1555796c8dcSSimon Schubert frame_prev_arch_ftype *prev_arch; 1565796c8dcSSimon Schubert }; 1575796c8dcSSimon Schubert 1585796c8dcSSimon Schubert /* Register a frame unwinder, _prepending_ it to the front of the 1595796c8dcSSimon Schubert search list (so it is sniffed before previously registered 1605796c8dcSSimon Schubert unwinders). By using a prepend, later calls can install unwinders 1615796c8dcSSimon Schubert that override earlier calls. This allows, for instance, an OSABI 162*c50c785cSJohn Marino to install a more specific sigtramp unwinder that overrides the 1635796c8dcSSimon Schubert traditional brute-force unwinder. */ 164*c50c785cSJohn Marino extern void frame_unwind_prepend_unwinder (struct gdbarch *, 165*c50c785cSJohn Marino const struct frame_unwind *); 1665796c8dcSSimon Schubert 1675796c8dcSSimon Schubert /* Add a frame sniffer to the list. The predicates are polled in the 1685796c8dcSSimon Schubert order that they are appended. The initial list contains the dummy 1695796c8dcSSimon Schubert frame sniffer. */ 1705796c8dcSSimon Schubert 1715796c8dcSSimon Schubert extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch, 1725796c8dcSSimon Schubert const struct frame_unwind *unwinder); 1735796c8dcSSimon Schubert 174*c50c785cSJohn Marino /* Iterate through sniffers for THIS_FRAME frame until one returns with an 175*c50c785cSJohn Marino unwinder implementation. THIS_FRAME->UNWIND must be NULL, it will get set 176*c50c785cSJohn Marino by this function. Possibly initialize THIS_CACHE. */ 1775796c8dcSSimon Schubert 178*c50c785cSJohn Marino extern void frame_unwind_find_by_frame (struct frame_info *this_frame, 1795796c8dcSSimon Schubert void **this_cache); 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert /* Helper functions for value-based register unwinding. These return 1825796c8dcSSimon Schubert a (possibly lazy) value of the appropriate type. */ 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert /* Return a value which indicates that FRAME did not save REGNUM. */ 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert struct value *frame_unwind_got_optimized (struct frame_info *frame, 1875796c8dcSSimon Schubert int regnum); 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert /* Return a value which indicates that FRAME copied REGNUM into 1905796c8dcSSimon Schubert register NEW_REGNUM. */ 1915796c8dcSSimon Schubert 1925796c8dcSSimon Schubert struct value *frame_unwind_got_register (struct frame_info *frame, int regnum, 1935796c8dcSSimon Schubert int new_regnum); 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert /* Return a value which indicates that FRAME saved REGNUM in memory at 1965796c8dcSSimon Schubert ADDR. */ 1975796c8dcSSimon Schubert 1985796c8dcSSimon Schubert struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum, 1995796c8dcSSimon Schubert CORE_ADDR addr); 2005796c8dcSSimon Schubert 2015796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of 2025796c8dcSSimon Schubert REGNUM has a known constant (computed) value of VAL. */ 2035796c8dcSSimon Schubert 2045796c8dcSSimon Schubert struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum, 2055796c8dcSSimon Schubert ULONGEST val); 2065796c8dcSSimon Schubert 2075796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of 2085796c8dcSSimon Schubert REGNUM has a known constant (computed) value which is stored 2095796c8dcSSimon Schubert inside BUF. */ 2105796c8dcSSimon Schubert 2115796c8dcSSimon Schubert struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum, 2125796c8dcSSimon Schubert gdb_byte *buf); 2135796c8dcSSimon Schubert 2145796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of REGNUM 2155796c8dcSSimon Schubert has a known constant (computed) value of ADDR. Convert the 2165796c8dcSSimon Schubert CORE_ADDR to a target address if necessary. */ 2175796c8dcSSimon Schubert 2185796c8dcSSimon Schubert struct value *frame_unwind_got_address (struct frame_info *frame, int regnum, 2195796c8dcSSimon Schubert CORE_ADDR addr); 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert #endif 222