1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2010, 2011 by FERMI NATIONAL ACCELERATOR LABORATORY 3 Copyright (C) 2014 CERN and Aalto University 4 Contributed by Filip Nyback 5 6This file is part of libunwind. 7 8Permission is hereby granted, free of charge, to any person obtaining 9a copy of this software and associated documentation files (the 10"Software"), to deal in the Software without restriction, including 11without limitation the rights to use, copy, modify, merge, publish, 12distribute, sublicense, and/or sell copies of the Software, and to 13permit persons to whom the Software is furnished to do so, subject to 14the following conditions: 15 16The above copyright notice and this permission notice shall be 17included in all copies or substantial portions of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 26 27#include "unwind_i.h" 28#include "dwarf_i.h" 29 30HIDDEN void 31tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs) 32{ 33 struct cursor *c = (struct cursor *) dwarf_to_cursor (d); 34 unw_tdep_frame_t *f = &c->frame_info; 35 36 Debug (4, "ip=0x%lx cfa=0x%lx type %d cfa [where=%d val=%ld] cfaoff=%ld" 37 " ra=0x%lx fp [where=%d val=%ld @0x%lx] lr [where=%d val=%ld @0x%lx] " 38 "sp [where=%d val=%ld @0x%lx]\n", 39 d->ip, d->cfa, f->frame_type, 40 rs->reg[DWARF_CFA_REG_COLUMN].where, 41 rs->reg[DWARF_CFA_REG_COLUMN].val, 42 rs->reg[DWARF_CFA_OFF_COLUMN].val, 43 DWARF_GET_LOC(d->loc[d->ret_addr_column]), 44 rs->reg[FP].where, rs->reg[FP].val, DWARF_GET_LOC(d->loc[FP]), 45 rs->reg[LR].where, rs->reg[LR].val, DWARF_GET_LOC(d->loc[LR]), 46 rs->reg[SP].where, rs->reg[SP].val, DWARF_GET_LOC(d->loc[SP])); 47 48 /* A standard frame is defined as: 49 - CFA is register-relative offset off FP or SP; 50 - Return address is saved in LR; 51 - FP is unsaved or saved at CFA+offset, offset != -1; 52 - LR is unsaved or saved at CFA+offset, offset != -1; 53 - SP is unsaved or saved at CFA+offset, offset != -1. */ 54 if (f->frame_type == UNW_AARCH64_FRAME_OTHER 55 && (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG) 56 && (rs->reg[DWARF_CFA_REG_COLUMN].val == FP 57 || rs->reg[DWARF_CFA_REG_COLUMN].val == SP) 58 && labs(rs->reg[DWARF_CFA_OFF_COLUMN].val) < (1 << 29) 59 && d->ret_addr_column == LR 60 && (rs->reg[FP].where == DWARF_WHERE_UNDEF 61 || rs->reg[FP].where == DWARF_WHERE_SAME 62 || (rs->reg[FP].where == DWARF_WHERE_CFAREL 63 && labs(rs->reg[FP].val) < (1 << 29) 64 && rs->reg[FP].val+1 != 0)) 65 && (rs->reg[LR].where == DWARF_WHERE_UNDEF 66 || rs->reg[LR].where == DWARF_WHERE_SAME 67 || (rs->reg[LR].where == DWARF_WHERE_CFAREL 68 && labs(rs->reg[LR].val) < (1 << 29) 69 && rs->reg[LR].val+1 != 0)) 70 && (rs->reg[SP].where == DWARF_WHERE_UNDEF 71 || rs->reg[SP].where == DWARF_WHERE_SAME 72 || (rs->reg[SP].where == DWARF_WHERE_CFAREL 73 && labs(rs->reg[SP].val) < (1 << 29) 74 && rs->reg[SP].val+1 != 0))) 75 { 76 /* Save information for a standard frame. */ 77 f->frame_type = UNW_AARCH64_FRAME_STANDARD; 78 f->cfa_reg_sp = (rs->reg[DWARF_CFA_REG_COLUMN].val == SP); 79 f->cfa_reg_offset = rs->reg[DWARF_CFA_OFF_COLUMN].val; 80 if (rs->reg[FP].where == DWARF_WHERE_CFAREL) 81 f->fp_cfa_offset = rs->reg[FP].val; 82 if (rs->reg[LR].where == DWARF_WHERE_CFAREL) 83 f->lr_cfa_offset = rs->reg[LR].val; 84 if (rs->reg[SP].where == DWARF_WHERE_CFAREL) 85 f->sp_cfa_offset = rs->reg[SP].val; 86 Debug (4, " standard frame\n"); 87 } 88 else 89 Debug (4, " unusual frame\n"); 90} 91