1 /* libunwind - a platform-independent unwind library
2 Copyright (c) 2003, 2005 Hewlett-Packard Development Company, L.P.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 #include "libunwind_i.h"
30 #define alloc_reg_state() (mempool_alloc (&dwarf_reg_state_pool))
31 #define free_reg_state(rs) (mempool_free (&dwarf_reg_state_pool, rs))
34 read_regnum (unw_addr_space_t as, unw_accessors_t *a, unw_word_t *addr,
35 unw_word_t *valp, void *arg)
39 if ((ret = dwarf_read_uleb128 (as, a, addr, valp, arg)) < 0)
42 if (*valp >= DWARF_NUM_PRESERVED_REGS)
44 Debug (1, "Invalid register number %u\n", (unsigned int) *valp);
51 set_reg (dwarf_state_record_t *sr, unw_word_t regnum, dwarf_where_t where,
54 sr->rs_current.reg[regnum].where = where;
55 sr->rs_current.reg[regnum].val = val;
58 /* Run a CFI program to update the register state. */
60 run_cfi_program (struct dwarf_cursor *c, dwarf_state_record_t *sr,
61 unw_word_t ip, unw_word_t *addr, unw_word_t end_addr,
62 struct dwarf_cie_info *dci)
64 unw_word_t curr_ip, operand = 0, regnum, val, len, fde_encoding;
65 dwarf_reg_state_t *rs_stack = NULL, *new_rs, *old_rs;
76 if (c->pi.flags & UNW_PI_FLAG_DEBUG_FRAME)
78 /* .debug_frame CFI is stored in local address space. */
79 as = unw_local_addr_space;
82 a = unw_get_accessors (as);
83 curr_ip = c->pi.start_ip;
85 /* Process everything up to and including the current 'ip',
86 including all the DW_CFA_advance_loc instructions. See
87 'c->use_prev_instr' use in 'fetch_proc_info' for details. */
88 while (curr_ip <= ip && *addr < end_addr)
90 if ((ret = dwarf_readu8 (as, a, addr, &op, arg)) < 0)
93 if (op & DWARF_CFA_OPCODE_MASK)
95 operand = op & DWARF_CFA_OPERAND_MASK;
96 op &= ~DWARF_CFA_OPERAND_MASK;
98 switch ((dwarf_cfa_t) op)
100 case DW_CFA_advance_loc:
101 curr_ip += operand * dci->code_align;
102 Debug (15, "CFA_advance_loc to 0x%lx\n", (long) curr_ip);
105 case DW_CFA_advance_loc1:
106 if ((ret = dwarf_readu8 (as, a, addr, &u8, arg)) < 0)
108 curr_ip += u8 * dci->code_align;
109 Debug (15, "CFA_advance_loc1 to 0x%lx\n", (long) curr_ip);
112 case DW_CFA_advance_loc2:
113 if ((ret = dwarf_readu16 (as, a, addr, &u16, arg)) < 0)
115 curr_ip += u16 * dci->code_align;
116 Debug (15, "CFA_advance_loc2 to 0x%lx\n", (long) curr_ip);
119 case DW_CFA_advance_loc4:
120 if ((ret = dwarf_readu32 (as, a, addr, &u32, arg)) < 0)
122 curr_ip += u32 * dci->code_align;
123 Debug (15, "CFA_advance_loc4 to 0x%lx\n", (long) curr_ip);
126 case DW_CFA_MIPS_advance_loc8:
127 #ifdef UNW_TARGET_MIPS
131 if ((ret = dwarf_readu64 (as, a, addr, &u64, arg)) < 0)
133 curr_ip += u64 * dci->code_align;
134 Debug (15, "CFA_MIPS_advance_loc8\n");
138 Debug (1, "DW_CFA_MIPS_advance_loc8 on non-MIPS target\n");
145 if (regnum >= DWARF_NUM_PRESERVED_REGS)
147 Debug (1, "Invalid register number %u in DW_cfa_OFFSET\n",
148 (unsigned int) regnum);
152 if ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0)
154 set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
155 Debug (15, "CFA_offset r%lu at cfa+0x%lx\n",
156 (long) regnum, (long) (val * dci->data_align));
159 case DW_CFA_offset_extended:
160 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
161 || ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0))
163 set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
164 Debug (15, "CFA_offset_extended r%lu at cf+0x%lx\n",
165 (long) regnum, (long) (val * dci->data_align));
168 case DW_CFA_offset_extended_sf:
169 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
170 || ((ret = dwarf_read_sleb128 (as, a, addr, &val, arg)) < 0))
172 set_reg (sr, regnum, DWARF_WHERE_CFAREL, val * dci->data_align);
173 Debug (15, "CFA_offset_extended_sf r%lu at cf+0x%lx\n",
174 (long) regnum, (long) (val * dci->data_align));
179 if (regnum >= DWARF_NUM_PRESERVED_REGS)
181 Debug (1, "Invalid register number %u in DW_CFA_restore\n",
182 (unsigned int) regnum);
186 sr->rs_current.reg[regnum] = sr->rs_initial.reg[regnum];
187 Debug (15, "CFA_restore r%lu\n", (long) regnum);
190 case DW_CFA_restore_extended:
191 if ((ret = dwarf_read_uleb128 (as, a, addr, ®num, arg)) < 0)
193 if (regnum >= DWARF_NUM_PRESERVED_REGS)
195 Debug (1, "Invalid register number %u in "
196 "DW_CFA_restore_extended\n", (unsigned int) regnum);
200 sr->rs_current.reg[regnum] = sr->rs_initial.reg[regnum];
201 Debug (15, "CFA_restore_extended r%lu\n", (long) regnum);
208 fde_encoding = dci->fde_encoding;
209 if ((ret = dwarf_read_encoded_pointer (as, a, addr, fde_encoding,
213 Debug (15, "CFA_set_loc to 0x%lx\n", (long) curr_ip);
216 case DW_CFA_undefined:
217 if ((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
219 set_reg (sr, regnum, DWARF_WHERE_UNDEF, 0);
220 Debug (15, "CFA_undefined r%lu\n", (long) regnum);
223 case DW_CFA_same_value:
224 if ((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
226 set_reg (sr, regnum, DWARF_WHERE_SAME, 0);
227 Debug (15, "CFA_same_value r%lu\n", (long) regnum);
230 case DW_CFA_register:
231 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
232 || ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0))
234 set_reg (sr, regnum, DWARF_WHERE_REG, val);
235 Debug (15, "CFA_register r%lu to r%lu\n", (long) regnum, (long) val);
238 case DW_CFA_remember_state:
239 new_rs = alloc_reg_state ();
242 Debug (1, "Out of memory in DW_CFA_remember_state\n");
247 memcpy (new_rs->reg, sr->rs_current.reg, sizeof (new_rs->reg));
248 new_rs->next = rs_stack;
250 Debug (15, "CFA_remember_state\n");
253 case DW_CFA_restore_state:
256 Debug (1, "register-state stack underflow\n");
260 memcpy (&sr->rs_current.reg, &rs_stack->reg, sizeof (rs_stack->reg));
262 rs_stack = rs_stack->next;
263 free_reg_state (old_rs);
264 Debug (15, "CFA_restore_state\n");
268 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
269 || ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0))
271 set_reg (sr, DWARF_CFA_REG_COLUMN, DWARF_WHERE_REG, regnum);
272 set_reg (sr, DWARF_CFA_OFF_COLUMN, 0, val); /* NOT factored! */
273 Debug (15, "CFA_def_cfa r%lu+0x%lx\n", (long) regnum, (long) val);
276 case DW_CFA_def_cfa_sf:
277 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
278 || ((ret = dwarf_read_sleb128 (as, a, addr, &val, arg)) < 0))
280 set_reg (sr, DWARF_CFA_REG_COLUMN, DWARF_WHERE_REG, regnum);
281 set_reg (sr, DWARF_CFA_OFF_COLUMN, 0,
282 val * dci->data_align); /* factored! */
283 Debug (15, "CFA_def_cfa_sf r%lu+0x%lx\n",
284 (long) regnum, (long) (val * dci->data_align));
287 case DW_CFA_def_cfa_register:
288 if ((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
290 set_reg (sr, DWARF_CFA_REG_COLUMN, DWARF_WHERE_REG, regnum);
291 Debug (15, "CFA_def_cfa_register r%lu\n", (long) regnum);
294 case DW_CFA_def_cfa_offset:
295 if ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0)
297 set_reg (sr, DWARF_CFA_OFF_COLUMN, 0, val); /* NOT factored! */
298 Debug (15, "CFA_def_cfa_offset 0x%lx\n", (long) val);
301 case DW_CFA_def_cfa_offset_sf:
302 if ((ret = dwarf_read_sleb128 (as, a, addr, &val, arg)) < 0)
304 set_reg (sr, DWARF_CFA_OFF_COLUMN, 0,
305 val * dci->data_align); /* factored! */
306 Debug (15, "CFA_def_cfa_offset_sf 0x%lx\n",
307 (long) (val * dci->data_align));
310 case DW_CFA_def_cfa_expression:
311 /* Save the address of the DW_FORM_block for later evaluation. */
312 set_reg (sr, DWARF_CFA_REG_COLUMN, DWARF_WHERE_EXPR, *addr);
314 if ((ret = dwarf_read_uleb128 (as, a, addr, &len, arg)) < 0)
317 Debug (15, "CFA_def_cfa_expr @ 0x%lx [%lu bytes]\n",
318 (long) *addr, (long) len);
322 case DW_CFA_expression:
323 if ((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
326 /* Save the address of the DW_FORM_block for later evaluation. */
327 set_reg (sr, regnum, DWARF_WHERE_EXPR, *addr);
329 if ((ret = dwarf_read_uleb128 (as, a, addr, &len, arg)) < 0)
332 Debug (15, "CFA_expression r%lu @ 0x%lx [%lu bytes]\n",
333 (long) regnum, (long) addr, (long) len);
337 case DW_CFA_GNU_args_size:
338 if ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0)
341 Debug (15, "CFA_GNU_args_size %lu\n", (long) val);
344 case DW_CFA_GNU_negative_offset_extended:
345 /* A comment in GCC says that this is obsoleted by
346 DW_CFA_offset_extended_sf, but that it's used by older
348 if (((ret = read_regnum (as, a, addr, ®num, arg)) < 0)
349 || ((ret = dwarf_read_uleb128 (as, a, addr, &val, arg)) < 0))
351 set_reg (sr, regnum, DWARF_WHERE_CFAREL, -(val * dci->data_align));
352 Debug (15, "CFA_GNU_negative_offset_extended cfa+0x%lx\n",
353 (long) -(val * dci->data_align));
356 case DW_CFA_GNU_window_save:
357 #ifdef UNW_TARGET_SPARC
358 /* This is a special CFA to handle all 16 windowed registers
360 for (regnum = 16; regnum < 32; ++regnum)
361 set_reg (sr, regnum, DWARF_WHERE_CFAREL,
362 (regnum - 16) * sizeof (unw_word_t));
363 Debug (15, "CFA_GNU_window_save\n");
370 Debug (1, "Unexpected CFA opcode 0x%x\n", op);
378 /* Free the register-state stack, if not empty already. */
382 rs_stack = rs_stack->next;
383 free_reg_state (old_rs);
389 fetch_proc_info (struct dwarf_cursor *c, unw_word_t ip, int need_unwind_info)
391 int ret, dynamic = 1;
393 /* The 'ip' can point either to the previous or next instruction
394 depending on what type of frame we have: normal call or a place
395 to resume execution (e.g. after signal frame).
397 For a normal call frame we need to back up so we point within the
398 call itself; this is important because a) the call might be the
399 very last instruction of the function and the edge of the FDE,
400 and b) so that run_cfi_program() runs locations up to the call
403 For execution resume, we need to do the exact opposite and look
404 up using the current 'ip' value. That is where execution will
405 continue, and it's important we get this right, as 'ip' could be
406 right at the function entry and hence FDE edge, or at instruction
407 that manipulates CFA (push/pop). */
408 if (c->use_prev_instr)
411 if (c->pi_valid && !need_unwind_info)
414 memset (&c->pi, 0, sizeof (c->pi));
416 /* check dynamic info first --- it overrides everything else */
417 ret = unwi_find_dynamic_proc_info (c->as, ip, &c->pi, need_unwind_info,
419 if (ret == -UNW_ENOINFO)
422 if ((ret = tdep_find_proc_info (c, ip, need_unwind_info)) < 0)
426 if (c->pi.format != UNW_INFO_FORMAT_DYNAMIC
427 && c->pi.format != UNW_INFO_FORMAT_TABLE
428 && c->pi.format != UNW_INFO_FORMAT_REMOTE_TABLE)
432 c->pi_is_dynamic = dynamic;
434 /* Let system/machine-dependent code determine frame-specific attributes. */
436 tdep_fetch_frame (c, ip, need_unwind_info);
438 /* Update use_prev_instr for the next frame. */
439 if (need_unwind_info)
441 assert(c->pi.unwind_info);
442 struct dwarf_cie_info *dci = c->pi.unwind_info;
443 c->use_prev_instr = ! dci->signal_frame;
450 parse_dynamic (struct dwarf_cursor *c, unw_word_t ip, dwarf_state_record_t *sr)
452 Debug (1, "Not yet implemented\n");
454 /* Don't forget to set the ret_addr_column! */
455 c->ret_addr_column = XXX;
461 put_unwind_info (struct dwarf_cursor *c, unw_proc_info_t *pi)
466 if (c->pi_is_dynamic)
467 unwi_put_dynamic_unwind_info (c->as, pi, c->as_arg);
468 else if (pi->unwind_info)
470 mempool_free (&dwarf_cie_info_pool, pi->unwind_info);
471 pi->unwind_info = NULL;
476 parse_fde (struct dwarf_cursor *c, unw_word_t ip, dwarf_state_record_t *sr)
478 struct dwarf_cie_info *dci;
482 dci = c->pi.unwind_info;
483 c->ret_addr_column = dci->ret_addr_column;
485 addr = dci->cie_instr_start;
486 if ((ret = run_cfi_program (c, sr, ~(unw_word_t) 0, &addr,
487 dci->cie_instr_end, dci)) < 0)
490 memcpy (&sr->rs_initial, &sr->rs_current, sizeof (sr->rs_initial));
492 addr = dci->fde_instr_start;
493 if ((ret = run_cfi_program (c, sr, ip, &addr, dci->fde_instr_end, dci)) < 0)
500 flush_rs_cache (struct dwarf_rs_cache *cache)
504 cache->lru_head = DWARF_UNW_CACHE_SIZE - 1;
507 for (i = 0; i < DWARF_UNW_CACHE_SIZE; ++i)
510 cache->buckets[i].lru_chain = (i - 1);
511 cache->buckets[i].coll_chain = -1;
512 cache->buckets[i].ip = 0;
513 cache->buckets[i].valid = 0;
515 for (i = 0; i<DWARF_UNW_HASH_SIZE; ++i)
519 static inline struct dwarf_rs_cache *
520 get_rs_cache (unw_addr_space_t as, intrmask_t *saved_maskp)
522 struct dwarf_rs_cache *cache = &as->global_cache;
523 unw_caching_policy_t caching = as->caching_policy;
525 if (caching == UNW_CACHE_NONE)
528 if (likely (caching == UNW_CACHE_GLOBAL))
530 Debug (16, "acquiring lock\n");
531 lock_acquire (&cache->lock, *saved_maskp);
534 if (atomic_read (&as->cache_generation) != atomic_read (&cache->generation))
536 flush_rs_cache (cache);
537 cache->generation = as->cache_generation;
544 put_rs_cache (unw_addr_space_t as, struct dwarf_rs_cache *cache,
545 intrmask_t *saved_maskp)
547 assert (as->caching_policy != UNW_CACHE_NONE);
549 Debug (16, "unmasking signals/interrupts and releasing lock\n");
550 if (likely (as->caching_policy == UNW_CACHE_GLOBAL))
551 lock_release (&cache->lock, *saved_maskp);
554 static inline unw_hash_index_t CONST_ATTR
557 /* based on (sqrt(5)/2-1)*2^64 */
558 # define magic ((unw_word_t) 0x9e3779b97f4a7c16ULL)
560 return ip * magic >> ((sizeof(unw_word_t) * 8) - DWARF_LOG_UNW_HASH_SIZE);
564 cache_match (dwarf_reg_state_t *rs, unw_word_t ip)
566 if (rs->valid && (ip == rs->ip))
571 static dwarf_reg_state_t *
572 rs_lookup (struct dwarf_rs_cache *cache, struct dwarf_cursor *c)
574 dwarf_reg_state_t *rs = cache->buckets + c->hint;
575 unsigned short index;
580 if (cache_match (rs, ip))
583 index = cache->hash[hash (ip)];
584 if (index >= DWARF_UNW_CACHE_SIZE)
587 rs = cache->buckets + index;
590 if (cache_match (rs, ip))
592 /* update hint; no locking needed: single-word writes are atomic */
593 c->hint = cache->buckets[c->prev_rs].hint =
594 (rs - cache->buckets);
597 if (rs->coll_chain >= DWARF_UNW_HASH_SIZE)
599 rs = cache->buckets + rs->coll_chain;
603 static inline dwarf_reg_state_t *
604 rs_new (struct dwarf_rs_cache *cache, struct dwarf_cursor * c)
606 dwarf_reg_state_t *rs, *prev, *tmp;
607 unw_hash_index_t index;
610 head = cache->lru_head;
611 rs = cache->buckets + head;
612 cache->lru_head = rs->lru_chain;
614 /* re-insert rs at the tail of the LRU chain: */
615 cache->buckets[cache->lru_tail].lru_chain = head;
616 cache->lru_tail = head;
618 /* remove the old rs from the hash table (if it's there): */
621 index = hash (rs->ip);
622 tmp = cache->buckets + cache->hash[index];
629 prev->coll_chain = tmp->coll_chain;
631 cache->hash[index] = tmp->coll_chain;
636 if (tmp->coll_chain >= DWARF_UNW_CACHE_SIZE)
637 /* old rs wasn't in the hash-table */
639 tmp = cache->buckets + tmp->coll_chain;
643 /* enter new rs in the hash table */
644 index = hash (c->ip);
645 rs->coll_chain = cache->hash[index];
646 cache->hash[index] = rs - cache->buckets;
651 rs->ret_addr_column = c->ret_addr_column;
652 rs->signal_frame = 0;
653 tdep_cache_frame (c, rs);
659 create_state_record_for (struct dwarf_cursor *c, dwarf_state_record_t *sr,
664 assert (c->pi_valid);
666 memset (sr, 0, sizeof (*sr));
667 for (i = 0; i < DWARF_NUM_PRESERVED_REGS + 2; ++i)
668 set_reg (sr, i, DWARF_WHERE_SAME, 0);
670 switch (c->pi.format)
672 case UNW_INFO_FORMAT_TABLE:
673 case UNW_INFO_FORMAT_REMOTE_TABLE:
674 ret = parse_fde (c, ip, sr);
677 case UNW_INFO_FORMAT_DYNAMIC:
678 ret = parse_dynamic (c, ip, sr);
682 Debug (1, "Unexpected unwind-info format %d\n", c->pi.format);
689 eval_location_expr (struct dwarf_cursor *c, unw_addr_space_t as,
690 unw_accessors_t *a, unw_word_t addr,
691 dwarf_loc_t *locp, void *arg)
693 int ret, is_register;
696 /* read the length of the expression: */
697 if ((ret = dwarf_read_uleb128 (as, a, &addr, &len, arg)) < 0)
700 /* evaluate the expression: */
701 if ((ret = dwarf_eval_expr (c, &addr, len, &val, &is_register)) < 0)
705 *locp = DWARF_REG_LOC (c, dwarf_to_unw_regnum (val));
707 *locp = DWARF_MEM_LOC (c, val);
713 apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs)
715 unw_word_t regnum, addr, cfa, ip;
716 unw_word_t prev_ip, prev_cfa;
728 a = unw_get_accessors (as);
730 /* Evaluate the CFA first, because it may be referred to by other
733 if (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG)
735 /* CFA is equal to [reg] + offset: */
737 /* As a special-case, if the stack-pointer is the CFA and the
738 stack-pointer wasn't saved, popping the CFA implicitly pops
739 the stack-pointer as well. */
740 if ((rs->reg[DWARF_CFA_REG_COLUMN].val == UNW_TDEP_SP)
741 && (UNW_TDEP_SP < ARRAY_SIZE(rs->reg))
742 && (rs->reg[UNW_TDEP_SP].where == DWARF_WHERE_SAME))
746 regnum = dwarf_to_unw_regnum (rs->reg[DWARF_CFA_REG_COLUMN].val);
747 if ((ret = unw_get_reg ((unw_cursor_t *) c, regnum, &cfa)) < 0)
750 cfa += rs->reg[DWARF_CFA_OFF_COLUMN].val;
754 /* CFA is equal to EXPR: */
756 assert (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_EXPR);
758 addr = rs->reg[DWARF_CFA_REG_COLUMN].val;
759 if ((ret = eval_location_expr (c, as, a, addr, &cfa_loc, arg)) < 0)
761 /* the returned location better be a memory location... */
762 if (DWARF_IS_REG_LOC (cfa_loc))
763 return -UNW_EBADFRAME;
764 cfa = DWARF_GET_LOC (cfa_loc);
767 for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
769 switch ((dwarf_where_t) rs->reg[i].where)
771 case DWARF_WHERE_UNDEF:
772 c->loc[i] = DWARF_NULL_LOC;
775 case DWARF_WHERE_SAME:
778 case DWARF_WHERE_CFAREL:
779 c->loc[i] = DWARF_MEM_LOC (c, cfa + rs->reg[i].val);
782 case DWARF_WHERE_REG:
783 c->loc[i] = DWARF_REG_LOC (c, dwarf_to_unw_regnum (rs->reg[i].val));
786 case DWARF_WHERE_EXPR:
787 addr = rs->reg[i].val;
788 if ((ret = eval_location_expr (c, as, a, addr, c->loc + i, arg)) < 0)
795 /* DWARF spec says undefined return address location means end of stack. */
796 if (DWARF_IS_NULL_LOC (c->loc[c->ret_addr_column]))
800 ret = dwarf_get (c, c->loc[c->ret_addr_column], &ip);
806 /* XXX: check for ip to be code_aligned */
807 if (c->ip == prev_ip && c->cfa == prev_cfa)
809 Dprintf ("%s: ip and cfa unchanged; stopping here (ip=0x%lx)\n",
810 __FUNCTION__, (long) c->ip);
811 return -UNW_EBADFRAME;
815 tdep_stash_frame (c, rs);
821 uncached_dwarf_find_save_locs (struct dwarf_cursor *c)
823 dwarf_state_record_t sr;
826 if ((ret = fetch_proc_info (c, c->ip, 1)) < 0)
829 if ((ret = create_state_record_for (c, &sr, c->ip)) < 0)
832 if ((ret = apply_reg_state (c, &sr.rs_current)) < 0)
835 put_unwind_info (c, &c->pi);
839 /* The function finds the saved locations and applies the register
842 dwarf_find_save_locs (struct dwarf_cursor *c)
844 dwarf_state_record_t sr;
845 dwarf_reg_state_t *rs, rs_copy;
846 struct dwarf_rs_cache *cache;
848 intrmask_t saved_mask;
850 if (c->as->caching_policy == UNW_CACHE_NONE)
851 return uncached_dwarf_find_save_locs (c);
853 cache = get_rs_cache(c->as, &saved_mask);
854 rs = rs_lookup(cache, c);
858 c->ret_addr_column = rs->ret_addr_column;
859 c->use_prev_instr = ! rs->signal_frame;
863 if ((ret = fetch_proc_info (c, c->ip, 1)) < 0 ||
864 (ret = create_state_record_for (c, &sr, c->ip)) < 0)
866 put_rs_cache (c->as, cache, &saved_mask);
870 rs = rs_new (cache, c);
871 memcpy(rs, &sr.rs_current, offsetof(struct dwarf_reg_state, ip));
872 cache->buckets[c->prev_rs].hint = rs - cache->buckets;
875 c->prev_rs = rs - cache->buckets;
877 put_unwind_info (c, &c->pi);
880 memcpy (&rs_copy, rs, sizeof (rs_copy));
881 put_rs_cache (c->as, cache, &saved_mask);
883 tdep_reuse_frame (c, &rs_copy);
884 if ((ret = apply_reg_state (c, &rs_copy)) < 0)
890 /* The proc-info must be valid for IP before this routine can be
893 dwarf_create_state_record (struct dwarf_cursor *c, dwarf_state_record_t *sr)
895 return create_state_record_for (c, sr, c->ip);
899 dwarf_make_proc_info (struct dwarf_cursor *c)
902 if (c->as->caching_policy == UNW_CACHE_NONE
903 || get_cached_proc_info (c) < 0)
905 /* Lookup it up the slow way... */
906 return fetch_proc_info (c, c->ip, 0);