/* The following routine is for accessing special registers of the top frame. A special set of accessors must be given that work without frame info. This is used by ia64 to access the rse registers r32-r127. While they are usually located at BOF, this is not always true and only the libunwind info can decipher where they actually are. */ int libunwind_get_reg_special (struct gdbarch *gdbarch, struct regcache *regcache, int regnum, void *buf) { unw_cursor_t cursor; unw_accessors_t *acc; unw_addr_space_t as; struct libunwind_descr *descr; int ret; unw_regnum_t uw_regnum; unw_word_t intval; unw_fpreg_t fpval; void *ptr; descr = libunwind_descr (gdbarch); acc = (unw_accessors_t *) descr->special_accessors; as = unw_create_addr_space_p (acc, gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? __BIG_ENDIAN : __LITTLE_ENDIAN); ret = unw_init_remote_p (&cursor, as, regcache); if (ret < 0) { unw_destroy_addr_space_p (as); return -1; } uw_regnum = descr->gdb2uw (regnum); if (descr->is_fpreg (uw_regnum)) { ret = unw_get_fpreg_p (&cursor, uw_regnum, &fpval); ptr = &fpval; } else { ret = unw_get_reg_p (&cursor, uw_regnum, &intval); ptr = &intval; } unw_destroy_addr_space_p (as); if (ret < 0) return -1; if (buf) memcpy (buf, ptr, register_size (gdbarch, regnum)); return 0; }
static struct libunwind_frame_cache * libunwind_frame_cache (struct frame_info *next_frame, void **this_cache) { unw_accessors_t *acc; unw_addr_space_t as; unw_word_t fp; unw_regnum_t uw_sp_regnum; struct libunwind_frame_cache *cache; struct libunwind_descr *descr; int i, ret; if (*this_cache) return *this_cache; /* Allocate a new cache. */ cache = FRAME_OBSTACK_ZALLOC (struct libunwind_frame_cache); cache->func_addr = frame_func_unwind (next_frame); /* Get a libunwind cursor to the previous frame. We do this by initializing a cursor. Libunwind treats a new cursor as the top of stack and will get the current register set via the libunwind register accessor. Now, we provide the platform-specific accessors and we set up the register accessor to use the frame register unwinding interfaces so that we properly get the registers for the current frame rather than the top. We then use the unw_step function to move the libunwind cursor back one frame. We can later use this cursor to find previous registers via the unw_get_reg interface which will invoke libunwind's special logic. */ descr = libunwind_descr (get_frame_arch (next_frame)); acc = descr->accessors; as = unw_create_addr_space_p (acc, TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? __BIG_ENDIAN : __LITTLE_ENDIAN); unw_init_remote_p (&cache->cursor, as, next_frame); unw_step_p (&cache->cursor); /* To get base address, get sp from previous frame. */ uw_sp_regnum = descr->gdb2uw (SP_REGNUM); ret = unw_get_reg_p (&cache->cursor, uw_sp_regnum, &fp); if (ret < 0) error ("Can't get libunwind sp register."); cache->base = (CORE_ADDR)fp; *this_cache = cache; return cache; }
void libunwind_frame_prev_register (struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { struct libunwind_frame_cache *cache = libunwind_frame_cache (next_frame, this_cache); void *ptr; unw_cursor_t *c; unw_save_loc_t sl; int i, ret; unw_word_t intval; unw_fpreg_t fpval; unw_regnum_t uw_regnum; struct libunwind_descr *descr; /* Convert from gdb register number to libunwind register number. */ descr = libunwind_descr (get_frame_arch (next_frame)); uw_regnum = descr->gdb2uw (regnum); gdb_assert (regnum >= 0); if (!target_has_registers) error ("No registers."); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; if (valuep) memset (valuep, 0, register_size (current_gdbarch, regnum)); if (uw_regnum < 0) return; /* To get the previous register, we use the libunwind register APIs with the cursor we have already pushed back to the previous frame. */ if (descr->is_fpreg (uw_regnum)) { ret = unw_get_fpreg_p (&cache->cursor, uw_regnum, &fpval); ptr = &fpval; } else { ret = unw_get_reg_p (&cache->cursor, uw_regnum, &intval); ptr = &intval; } if (ret < 0) return; if (valuep) memcpy (valuep, ptr, register_size (current_gdbarch, regnum)); if (unw_get_saveloc_p (&cache->cursor, uw_regnum, &sl) < 0) return; switch (sl.type) { case UNW_SLT_NONE: *optimizedp = 1; break; case UNW_SLT_MEMORY: *lvalp = lval_memory; *addrp = sl.u.addr; break; case UNW_SLT_REG: *lvalp = lval_register; *realnump = regnum; break; } }
struct value * libunwind_frame_prev_register (struct frame_info *this_frame, void **this_cache, int regnum) { struct libunwind_frame_cache *cache = libunwind_frame_cache (this_frame, this_cache); struct gdbarch *gdbarch = get_frame_arch (this_frame); void *ptr; unw_cursor_t *c; unw_save_loc_t sl; int i, ret; unw_word_t intval; unw_fpreg_t fpval; unw_regnum_t uw_regnum; struct libunwind_descr *descr; struct value *val = NULL; if (cache == NULL) return frame_unwind_got_constant (this_frame, regnum, 0); /* Convert from gdb register number to libunwind register number. */ descr = libunwind_descr (get_frame_arch (this_frame)); uw_regnum = descr->gdb2uw (regnum); gdb_assert (regnum >= 0); if (!target_has_registers) error (_("No registers.")); if (uw_regnum < 0) return frame_unwind_got_constant (this_frame, regnum, 0); if (unw_get_saveloc_p (&cache->cursor, uw_regnum, &sl) < 0) return frame_unwind_got_constant (this_frame, regnum, 0); switch (sl.type) { case UNW_SLT_MEMORY: val = frame_unwind_got_memory (this_frame, regnum, sl.u.addr); break; case UNW_SLT_REG: val = frame_unwind_got_register (this_frame, regnum, descr->uw2gdb (sl.u.regnum)); break; case UNW_SLT_NONE: { /* The register is not stored at a specific memory address nor inside another register. So use libunwind to fetch the register value for us, and create a constant value with the result. */ if (descr->is_fpreg (uw_regnum)) { ret = unw_get_fpreg_p (&cache->cursor, uw_regnum, &fpval); if (ret < 0) return frame_unwind_got_constant (this_frame, regnum, 0); val = frame_unwind_got_bytes (this_frame, regnum, (gdb_byte *) &fpval); } else { ret = unw_get_reg_p (&cache->cursor, uw_regnum, &intval); if (ret < 0) return frame_unwind_got_constant (this_frame, regnum, 0); val = frame_unwind_got_constant (this_frame, regnum, intval); } break; } } return val; }
static struct libunwind_frame_cache * libunwind_frame_cache (struct frame_info *this_frame, void **this_cache) { unw_accessors_t *acc; unw_addr_space_t as; unw_word_t fp; unw_regnum_t uw_sp_regnum; struct libunwind_frame_cache *cache; struct libunwind_descr *descr; struct gdbarch *gdbarch = get_frame_arch (this_frame); int i, ret; if (*this_cache) return (struct libunwind_frame_cache *) *this_cache; /* Allocate a new cache. */ cache = FRAME_OBSTACK_ZALLOC (struct libunwind_frame_cache); cache->func_addr = get_frame_func (this_frame); if (cache->func_addr == 0) /* This can happen when the frame corresponds to a function for which there is no debugging information nor any entry in the symbol table. This is probably a static function for which an entry in the symbol table was not created when the objfile got linked (observed in libpthread.so on ia64-hpux). The best we can do, in that case, is use the frame PC as the function address. We don't need to give up since we still have the unwind record to help us perform the unwinding. There is also another compelling to continue, because abandonning now means stopping the backtrace, which can never be helpful for the user. */ cache->func_addr = get_frame_pc (this_frame); /* Get a libunwind cursor to the previous frame. We do this by initializing a cursor. Libunwind treats a new cursor as the top of stack and will get the current register set via the libunwind register accessor. Now, we provide the platform-specific accessors and we set up the register accessor to use the frame register unwinding interfaces so that we properly get the registers for the current frame rather than the top. We then use the unw_step function to move the libunwind cursor back one frame. We can later use this cursor to find previous registers via the unw_get_reg interface which will invoke libunwind's special logic. */ descr = libunwind_descr (gdbarch); acc = (unw_accessors_t *) descr->accessors; as = unw_create_addr_space_p (acc, gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? __BIG_ENDIAN : __LITTLE_ENDIAN); unw_init_remote_p (&cache->cursor, as, this_frame); if (unw_step_p (&cache->cursor) < 0) { unw_destroy_addr_space_p (as); return NULL; } /* To get base address, get sp from previous frame. */ uw_sp_regnum = descr->gdb2uw (gdbarch_sp_regnum (gdbarch)); ret = unw_get_reg_p (&cache->cursor, uw_sp_regnum, &fp); if (ret < 0) { unw_destroy_addr_space_p (as); error (_("Can't get libunwind sp register.")); } cache->base = (CORE_ADDR)fp; cache->as = as; *this_cache = cache; return cache; }