/* Verify if there is sufficient libunwind information for the frame to use libunwind frame unwinding. */ const struct frame_unwind * libunwind_frame_sniffer (struct frame_info *next_frame) { unw_cursor_t cursor; unw_accessors_t *acc; unw_addr_space_t as; struct libunwind_descr *descr; int i, ret; /* To test for libunwind unwind support, initialize a cursor to the current frame and try to back up. We use this same method when setting up the frame cache (see libunwind_frame_cache()). If libunwind returns success for this operation, it means that it has found sufficient libunwind unwinding information to do so. */ 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); ret = unw_init_remote_p (&cursor, as, next_frame); if (ret >= 0) ret = unw_step_p (&cursor); if (ret < 0) return NULL; return &libunwind_frame_unwind; }
/* 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; }
/* Verify if there is sufficient libunwind information for the frame to use libunwind frame unwinding. */ int libunwind_frame_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **this_cache) { unw_cursor_t cursor; unw_accessors_t *acc; unw_addr_space_t as; struct libunwind_descr *descr; struct gdbarch *gdbarch = get_frame_arch (this_frame); int i, ret; /* To test for libunwind unwind support, initialize a cursor to the current frame and try to back up. We use this same method when setting up the frame cache (see libunwind_frame_cache()). If libunwind returns success for this operation, it means that it has found sufficient libunwind unwinding information to do so. */ 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); ret = unw_init_remote_p (&cursor, as, this_frame); if (ret < 0) { unw_destroy_addr_space_p (as); return 0; } /* Check to see if we have libunwind info by checking if we are in a signal frame. If it doesn't return an error, we have libunwind info and can use libunwind. */ ret = unw_is_signal_frame_p (&cursor); unw_destroy_addr_space_p (as); if (ret < 0) return 0; return 1; }
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; }