Home | History | Annotate | Line # | Download | only in gdb
      1   1.1  christos /* Frame unwinder for ia64 frames using the libunwind library.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 2003-2024 Free Software Foundation, Inc.
      4   1.1  christos 
      5   1.1  christos    Written by Jeff Johnston, contributed by Red Hat Inc.
      6   1.1  christos 
      7   1.1  christos    This file is part of GDB.
      8   1.1  christos 
      9   1.1  christos    This program is free software; you can redistribute it and/or modify
     10   1.1  christos    it under the terms of the GNU General Public License as published by
     11   1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12   1.1  christos    (at your option) any later version.
     13   1.1  christos 
     14   1.1  christos    This program is distributed in the hope that it will be useful,
     15   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17   1.1  christos    GNU General Public License for more details.
     18   1.1  christos 
     19   1.1  christos    You should have received a copy of the GNU General Public License
     20   1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21   1.1  christos 
     22   1.1  christos 
     23   1.1  christos #include "inferior.h"
     24   1.1  christos #include "frame.h"
     25   1.1  christos #include "frame-base.h"
     26   1.1  christos #include "frame-unwind.h"
     27   1.1  christos #include "gdbcore.h"
     28   1.1  christos #include "gdbtypes.h"
     29   1.1  christos #include "symtab.h"
     30   1.1  christos #include "objfiles.h"
     31   1.1  christos #include "regcache.h"
     32   1.1  christos 
     33   1.1  christos #include <dlfcn.h>
     34   1.1  christos 
     35   1.1  christos #include "ia64-libunwind-tdep.h"
     36   1.1  christos 
     37   1.9  christos #include "gdbsupport/preprocessor.h"
     38   1.1  christos 
     39   1.1  christos /* IA-64 is the only target that currently uses ia64-libunwind-tdep.
     40   1.1  christos    Note how UNW_TARGET, UNW_OBJ, etc. are compile time constants below.
     41   1.1  christos    Those come from libunwind's headers, and are target dependent.
     42   1.1  christos    Also, some of libunwind's typedefs are target dependent, as e.g.,
     43   1.1  christos    unw_word_t.  If some other target wants to use this, we will need
     44   1.1  christos    to do some abstracting in order to make it possible to select which
     45   1.1  christos    libunwind we're talking to at runtime (and have one per arch).  */
     46   1.1  christos 
     47   1.1  christos /* The following two macros are normally defined in <endian.h>.
     48   1.1  christos    But systems such as ia64-hpux do not provide such header, so
     49   1.1  christos    we just define them here if not already defined.  */
     50   1.1  christos #ifndef __LITTLE_ENDIAN
     51   1.1  christos #define __LITTLE_ENDIAN 1234
     52   1.1  christos #endif
     53   1.1  christos #ifndef __BIG_ENDIAN
     54   1.1  christos #define __BIG_ENDIAN    4321
     55   1.1  christos #endif
     56   1.1  christos 
     57   1.1  christos static int libunwind_initialized;
     58  1.10  christos static const registry<gdbarch>::key<libunwind_descr> libunwind_descr_handle;
     59   1.1  christos 
     60   1.1  christos /* Required function pointers from libunwind.  */
     61   1.6  christos typedef int (unw_get_reg_p_ftype) (unw_cursor_t *, unw_regnum_t, unw_word_t *);
     62   1.6  christos static unw_get_reg_p_ftype *unw_get_reg_p;
     63   1.6  christos typedef int (unw_get_fpreg_p_ftype) (unw_cursor_t *, unw_regnum_t,
     64   1.6  christos 				     unw_fpreg_t *);
     65   1.6  christos static unw_get_fpreg_p_ftype *unw_get_fpreg_p;
     66   1.6  christos typedef int (unw_get_saveloc_p_ftype) (unw_cursor_t *, unw_regnum_t,
     67   1.6  christos 				       unw_save_loc_t *);
     68   1.6  christos static unw_get_saveloc_p_ftype *unw_get_saveloc_p;
     69   1.6  christos typedef int (unw_is_signal_frame_p_ftype) (unw_cursor_t *);
     70   1.6  christos static unw_is_signal_frame_p_ftype *unw_is_signal_frame_p;
     71   1.6  christos typedef int (unw_step_p_ftype) (unw_cursor_t *);
     72   1.6  christos static unw_step_p_ftype *unw_step_p;
     73   1.6  christos typedef int (unw_init_remote_p_ftype) (unw_cursor_t *, unw_addr_space_t,
     74   1.6  christos 				       void *);
     75   1.6  christos static unw_init_remote_p_ftype *unw_init_remote_p;
     76   1.6  christos typedef unw_addr_space_t (unw_create_addr_space_p_ftype) (unw_accessors_t *,
     77   1.6  christos 							  int);
     78   1.6  christos static unw_create_addr_space_p_ftype *unw_create_addr_space_p;
     79   1.6  christos typedef void (unw_destroy_addr_space_p_ftype) (unw_addr_space_t);
     80   1.6  christos static unw_destroy_addr_space_p_ftype *unw_destroy_addr_space_p;
     81   1.6  christos typedef int (unw_search_unwind_table_p_ftype) (unw_addr_space_t, unw_word_t,
     82   1.6  christos 					       unw_dyn_info_t *,
     83   1.6  christos 					       unw_proc_info_t *, int, void *);
     84   1.6  christos static unw_search_unwind_table_p_ftype *unw_search_unwind_table_p;
     85   1.6  christos typedef unw_word_t (unw_find_dyn_list_p_ftype) (unw_addr_space_t,
     86   1.6  christos 						unw_dyn_info_t *, void *);
     87   1.6  christos static unw_find_dyn_list_p_ftype *unw_find_dyn_list_p;
     88   1.1  christos 
     89   1.1  christos 
     90   1.1  christos struct libunwind_frame_cache
     91   1.1  christos {
     92   1.1  christos   CORE_ADDR base;
     93   1.1  christos   CORE_ADDR func_addr;
     94   1.1  christos   unw_cursor_t cursor;
     95   1.1  christos   unw_addr_space_t as;
     96   1.1  christos };
     97   1.1  christos 
     98   1.1  christos /* We need to qualify the function names with a platform-specific prefix
     99   1.1  christos    to match the names used by the libunwind library.  The UNW_OBJ macro is
    100   1.1  christos    provided by the libunwind.h header file.  */
    101   1.1  christos 
    102   1.1  christos #ifndef LIBUNWIND_SO
    103   1.1  christos /* Use the stable ABI major version number.  `libunwind-ia64.so' is a link time
    104   1.1  christos    only library, not a runtime one.  */
    105   1.1  christos #define LIBUNWIND_SO "libunwind-" STRINGIFY(UNW_TARGET) ".so.8"
    106   1.1  christos 
    107   1.1  christos /* Provide also compatibility with older .so.  The two APIs are compatible, .8
    108   1.1  christos    is only extended a bit, GDB does not use the extended API at all.  */
    109   1.1  christos #define LIBUNWIND_SO_7 "libunwind-" STRINGIFY(UNW_TARGET) ".so.7"
    110   1.1  christos #endif
    111   1.1  christos 
    112   1.8  christos static const char *get_reg_name = STRINGIFY(UNW_OBJ(get_reg));
    113   1.8  christos static const char *get_fpreg_name = STRINGIFY(UNW_OBJ(get_fpreg));
    114   1.8  christos static const char *get_saveloc_name = STRINGIFY(UNW_OBJ(get_save_loc));
    115   1.8  christos static const char *is_signal_frame_name = STRINGIFY(UNW_OBJ(is_signal_frame));
    116   1.8  christos static const char *step_name = STRINGIFY(UNW_OBJ(step));
    117   1.8  christos static const char *init_remote_name = STRINGIFY(UNW_OBJ(init_remote));
    118   1.8  christos static const char *create_addr_space_name
    119   1.8  christos   = STRINGIFY(UNW_OBJ(create_addr_space));
    120   1.8  christos static const char *destroy_addr_space_name
    121   1.8  christos   = STRINGIFY(UNW_OBJ(destroy_addr_space));
    122   1.8  christos static const char *search_unwind_table_name
    123   1.1  christos   = STRINGIFY(UNW_OBJ(search_unwind_table));
    124   1.8  christos static const char *find_dyn_list_name = STRINGIFY(UNW_OBJ(find_dyn_list));
    125   1.1  christos 
    126   1.1  christos static struct libunwind_descr *
    127   1.1  christos libunwind_descr (struct gdbarch *gdbarch)
    128   1.1  christos {
    129  1.10  christos   struct libunwind_descr *result = libunwind_descr_handle.get (gdbarch);
    130  1.10  christos   if (result == nullptr)
    131  1.10  christos     result = libunwind_descr_handle.emplace (gdbarch);
    132  1.10  christos   return result;
    133   1.1  christos }
    134   1.1  christos 
    135   1.1  christos void
    136   1.1  christos libunwind_frame_set_descr (struct gdbarch *gdbarch,
    137   1.1  christos 			   struct libunwind_descr *descr)
    138   1.1  christos {
    139   1.1  christos   struct libunwind_descr *arch_descr;
    140   1.1  christos 
    141   1.1  christos   gdb_assert (gdbarch != NULL);
    142   1.1  christos 
    143  1.10  christos   arch_descr = libunwind_descr (gdbarch);
    144   1.9  christos   gdb_assert (arch_descr != NULL);
    145   1.1  christos 
    146   1.1  christos   /* Copy new descriptor info into arch descriptor.  */
    147   1.1  christos   arch_descr->gdb2uw = descr->gdb2uw;
    148   1.1  christos   arch_descr->uw2gdb = descr->uw2gdb;
    149   1.1  christos   arch_descr->is_fpreg = descr->is_fpreg;
    150   1.1  christos   arch_descr->accessors = descr->accessors;
    151   1.1  christos   arch_descr->special_accessors = descr->special_accessors;
    152   1.1  christos }
    153   1.1  christos 
    154   1.1  christos static struct libunwind_frame_cache *
    155  1.11  christos libunwind_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
    156   1.1  christos {
    157   1.1  christos   unw_accessors_t *acc;
    158   1.1  christos   unw_addr_space_t as;
    159   1.1  christos   unw_word_t fp;
    160   1.1  christos   unw_regnum_t uw_sp_regnum;
    161   1.1  christos   struct libunwind_frame_cache *cache;
    162   1.1  christos   struct libunwind_descr *descr;
    163   1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
    164   1.8  christos   int ret;
    165   1.1  christos 
    166   1.1  christos   if (*this_cache)
    167   1.6  christos     return (struct libunwind_frame_cache *) *this_cache;
    168   1.1  christos 
    169   1.1  christos   /* Allocate a new cache.  */
    170   1.1  christos   cache = FRAME_OBSTACK_ZALLOC (struct libunwind_frame_cache);
    171   1.1  christos 
    172   1.1  christos   cache->func_addr = get_frame_func (this_frame);
    173   1.1  christos   if (cache->func_addr == 0)
    174   1.1  christos     /* This can happen when the frame corresponds to a function for which
    175   1.1  christos        there is no debugging information nor any entry in the symbol table.
    176   1.1  christos        This is probably a static function for which an entry in the symbol
    177   1.1  christos        table was not created when the objfile got linked (observed in
    178   1.1  christos        libpthread.so on ia64-hpux).
    179   1.1  christos 
    180   1.1  christos        The best we can do, in that case, is use the frame PC as the function
    181   1.1  christos        address.  We don't need to give up since we still have the unwind
    182   1.1  christos        record to help us perform the unwinding.  There is also another
    183   1.9  christos        compelling to continue, because abandoning now means stopping
    184   1.1  christos        the backtrace, which can never be helpful for the user.  */
    185   1.1  christos     cache->func_addr = get_frame_pc (this_frame);
    186   1.1  christos 
    187   1.1  christos   /* Get a libunwind cursor to the previous frame.
    188   1.1  christos 
    189   1.1  christos      We do this by initializing a cursor.  Libunwind treats a new cursor
    190   1.1  christos      as the top of stack and will get the current register set via the
    191   1.1  christos      libunwind register accessor.  Now, we provide the platform-specific
    192   1.1  christos      accessors and we set up the register accessor to use the frame
    193   1.1  christos      register unwinding interfaces so that we properly get the registers
    194   1.1  christos      for the current frame rather than the top.  We then use the unw_step
    195   1.1  christos      function to move the libunwind cursor back one frame.  We can later
    196   1.1  christos      use this cursor to find previous registers via the unw_get_reg
    197   1.1  christos      interface which will invoke libunwind's special logic.  */
    198   1.1  christos   descr = libunwind_descr (gdbarch);
    199   1.6  christos   acc = (unw_accessors_t *) descr->accessors;
    200   1.1  christos   as =  unw_create_addr_space_p (acc,
    201   1.1  christos 				 gdbarch_byte_order (gdbarch)
    202   1.1  christos 				 == BFD_ENDIAN_BIG
    203   1.1  christos 				 ? __BIG_ENDIAN
    204   1.1  christos 				 : __LITTLE_ENDIAN);
    205   1.1  christos 
    206   1.1  christos   unw_init_remote_p (&cache->cursor, as, this_frame);
    207   1.1  christos   if (unw_step_p (&cache->cursor) < 0)
    208   1.1  christos     {
    209   1.1  christos       unw_destroy_addr_space_p (as);
    210   1.1  christos       return NULL;
    211   1.1  christos     }
    212   1.1  christos 
    213   1.1  christos   /* To get base address, get sp from previous frame.  */
    214   1.1  christos   uw_sp_regnum = descr->gdb2uw (gdbarch_sp_regnum (gdbarch));
    215   1.1  christos   ret = unw_get_reg_p (&cache->cursor, uw_sp_regnum, &fp);
    216   1.1  christos   if (ret < 0)
    217   1.1  christos     {
    218   1.1  christos       unw_destroy_addr_space_p (as);
    219   1.1  christos       error (_("Can't get libunwind sp register."));
    220   1.1  christos     }
    221   1.1  christos 
    222   1.1  christos   cache->base = (CORE_ADDR)fp;
    223   1.1  christos   cache->as = as;
    224   1.1  christos 
    225   1.1  christos   *this_cache = cache;
    226   1.1  christos   return cache;
    227   1.1  christos }
    228   1.1  christos 
    229   1.1  christos void
    230  1.10  christos libunwind_frame_dealloc_cache (frame_info_ptr self, void *this_cache)
    231   1.1  christos {
    232   1.6  christos   struct libunwind_frame_cache *cache
    233   1.6  christos     = (struct libunwind_frame_cache *) this_cache;
    234   1.1  christos 
    235   1.1  christos   if (cache->as)
    236   1.1  christos     unw_destroy_addr_space_p (cache->as);
    237   1.1  christos }
    238   1.1  christos 
    239   1.1  christos unw_word_t
    240   1.1  christos libunwind_find_dyn_list (unw_addr_space_t as, unw_dyn_info_t *di, void *arg)
    241   1.1  christos {
    242   1.1  christos   return unw_find_dyn_list_p (as, di, arg);
    243   1.1  christos }
    244   1.1  christos 
    245   1.1  christos /* Verify if there is sufficient libunwind information for the frame to use
    246   1.1  christos    libunwind frame unwinding.  */
    247   1.1  christos int
    248   1.1  christos libunwind_frame_sniffer (const struct frame_unwind *self,
    249  1.11  christos 			 const frame_info_ptr &this_frame, void **this_cache)
    250   1.1  christos {
    251   1.1  christos   unw_cursor_t cursor;
    252   1.1  christos   unw_accessors_t *acc;
    253   1.1  christos   unw_addr_space_t as;
    254   1.1  christos   struct libunwind_descr *descr;
    255   1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
    256   1.8  christos   int ret;
    257   1.1  christos 
    258   1.1  christos   /* To test for libunwind unwind support, initialize a cursor to
    259   1.1  christos      the current frame and try to back up.  We use this same method
    260   1.1  christos      when setting up the frame cache (see libunwind_frame_cache()).
    261   1.1  christos      If libunwind returns success for this operation, it means that
    262   1.1  christos      it has found sufficient libunwind unwinding information to do so.  */
    263   1.1  christos 
    264   1.1  christos   descr = libunwind_descr (gdbarch);
    265   1.6  christos   acc = (unw_accessors_t *) descr->accessors;
    266   1.1  christos   as =  unw_create_addr_space_p (acc,
    267   1.1  christos 				 gdbarch_byte_order (gdbarch)
    268   1.1  christos 				 == BFD_ENDIAN_BIG
    269   1.1  christos 				 ? __BIG_ENDIAN
    270   1.1  christos 				 : __LITTLE_ENDIAN);
    271   1.1  christos 
    272   1.1  christos   ret = unw_init_remote_p (&cursor, as, this_frame);
    273   1.1  christos 
    274   1.1  christos   if (ret < 0)
    275   1.1  christos     {
    276   1.1  christos       unw_destroy_addr_space_p (as);
    277   1.1  christos       return 0;
    278   1.1  christos     }
    279   1.1  christos 
    280   1.1  christos 
    281   1.1  christos   /* Check to see if we have libunwind info by checking if we are in a
    282   1.1  christos      signal frame.  If it doesn't return an error, we have libunwind info
    283   1.1  christos      and can use libunwind.  */
    284   1.1  christos   ret = unw_is_signal_frame_p (&cursor);
    285   1.1  christos   unw_destroy_addr_space_p (as);
    286   1.1  christos 
    287   1.1  christos   if (ret < 0)
    288   1.1  christos     return 0;
    289   1.1  christos 
    290   1.1  christos   return 1;
    291   1.1  christos }
    292   1.1  christos 
    293   1.1  christos void
    294  1.11  christos libunwind_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
    295  1.10  christos 			 struct frame_id *this_id)
    296   1.1  christos {
    297   1.1  christos   struct libunwind_frame_cache *cache =
    298   1.1  christos     libunwind_frame_cache (this_frame, this_cache);
    299   1.1  christos 
    300   1.1  christos   if (cache != NULL)
    301   1.1  christos     (*this_id) = frame_id_build (cache->base, cache->func_addr);
    302   1.1  christos }
    303   1.1  christos 
    304   1.1  christos struct value *
    305  1.11  christos libunwind_frame_prev_register (const frame_info_ptr &this_frame,
    306  1.10  christos 			       void **this_cache, int regnum)
    307   1.1  christos {
    308   1.1  christos   struct libunwind_frame_cache *cache =
    309   1.1  christos     libunwind_frame_cache (this_frame, this_cache);
    310   1.1  christos 
    311   1.1  christos   unw_save_loc_t sl;
    312   1.8  christos   int ret;
    313   1.1  christos   unw_word_t intval;
    314   1.1  christos   unw_fpreg_t fpval;
    315   1.1  christos   unw_regnum_t uw_regnum;
    316   1.1  christos   struct libunwind_descr *descr;
    317   1.1  christos   struct value *val = NULL;
    318   1.1  christos 
    319   1.1  christos   if (cache == NULL)
    320   1.1  christos     return frame_unwind_got_constant (this_frame, regnum, 0);
    321   1.1  christos 
    322   1.1  christos   /* Convert from gdb register number to libunwind register number.  */
    323   1.1  christos   descr = libunwind_descr (get_frame_arch (this_frame));
    324   1.1  christos   uw_regnum = descr->gdb2uw (regnum);
    325   1.1  christos 
    326   1.1  christos   gdb_assert (regnum >= 0);
    327   1.1  christos 
    328  1.10  christos   if (!target_has_registers ())
    329   1.1  christos     error (_("No registers."));
    330   1.1  christos 
    331   1.1  christos   if (uw_regnum < 0)
    332   1.1  christos     return frame_unwind_got_constant (this_frame, regnum, 0);
    333   1.1  christos 
    334   1.1  christos   if (unw_get_saveloc_p (&cache->cursor, uw_regnum, &sl) < 0)
    335   1.1  christos     return frame_unwind_got_constant (this_frame, regnum, 0);
    336   1.1  christos 
    337   1.1  christos   switch (sl.type)
    338   1.1  christos     {
    339   1.1  christos     case UNW_SLT_MEMORY:
    340   1.1  christos       val = frame_unwind_got_memory (this_frame, regnum, sl.u.addr);
    341   1.1  christos       break;
    342   1.1  christos 
    343   1.1  christos     case UNW_SLT_REG:
    344   1.1  christos       val = frame_unwind_got_register (this_frame, regnum,
    345  1.10  christos 				       descr->uw2gdb (sl.u.regnum));
    346   1.1  christos       break;
    347   1.1  christos     case UNW_SLT_NONE:
    348   1.1  christos       {
    349  1.10  christos 	/* The register is not stored at a specific memory address nor
    350  1.10  christos 	   inside another register.  So use libunwind to fetch the register
    351  1.10  christos 	   value for us, and create a constant value with the result.  */
    352  1.10  christos 	if (descr->is_fpreg (uw_regnum))
    353  1.10  christos 	  {
    354  1.10  christos 	    ret = unw_get_fpreg_p (&cache->cursor, uw_regnum, &fpval);
    355  1.10  christos 	    if (ret < 0)
    356  1.10  christos 	      return frame_unwind_got_constant (this_frame, regnum, 0);
    357  1.10  christos 	    val = frame_unwind_got_bytes (this_frame, regnum,
    358  1.10  christos 					  (gdb_byte *) &fpval);
    359  1.10  christos 	  }
    360  1.10  christos 	else
    361  1.10  christos 	  {
    362  1.10  christos 	    ret = unw_get_reg_p (&cache->cursor, uw_regnum, &intval);
    363  1.10  christos 	    if (ret < 0)
    364  1.10  christos 	      return frame_unwind_got_constant (this_frame, regnum, 0);
    365  1.10  christos 	    val = frame_unwind_got_constant (this_frame, regnum, intval);
    366  1.10  christos 	  }
    367  1.10  christos 	break;
    368   1.1  christos       }
    369   1.1  christos     }
    370   1.1  christos 
    371   1.1  christos   return val;
    372   1.1  christos }
    373   1.1  christos 
    374   1.1  christos /* The following is a glue routine to call the libunwind unwind table
    375   1.1  christos    search function to get unwind information for a specified ip address.  */
    376   1.1  christos int
    377   1.1  christos libunwind_search_unwind_table (void *as, long ip, void *di,
    378   1.1  christos 			       void *pi, int need_unwind_info, void *args)
    379   1.1  christos {
    380   1.6  christos   return unw_search_unwind_table_p (*(unw_addr_space_t *) as, (unw_word_t) ip,
    381   1.6  christos 				    (unw_dyn_info_t *) di,
    382   1.6  christos 				    (unw_proc_info_t *) pi, need_unwind_info,
    383   1.6  christos 				    args);
    384   1.1  christos }
    385   1.1  christos 
    386   1.1  christos /* Verify if we are in a sigtramp frame and we can use libunwind to unwind.  */
    387   1.1  christos int
    388   1.1  christos libunwind_sigtramp_frame_sniffer (const struct frame_unwind *self,
    389  1.11  christos 				  const frame_info_ptr &this_frame,
    390  1.10  christos 				  void **this_cache)
    391   1.1  christos {
    392   1.1  christos   unw_cursor_t cursor;
    393   1.1  christos   unw_accessors_t *acc;
    394   1.1  christos   unw_addr_space_t as;
    395   1.1  christos   struct libunwind_descr *descr;
    396   1.1  christos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
    397   1.8  christos   int ret;
    398   1.1  christos 
    399   1.1  christos   /* To test for libunwind unwind support, initialize a cursor to the
    400   1.1  christos      current frame and try to back up.  We use this same method when
    401   1.1  christos      setting up the frame cache (see libunwind_frame_cache()).  If
    402   1.1  christos      libunwind returns success for this operation, it means that it
    403   1.1  christos      has found sufficient libunwind unwinding information to do
    404   1.1  christos      so.  */
    405   1.1  christos 
    406   1.1  christos   descr = libunwind_descr (gdbarch);
    407   1.6  christos   acc = (unw_accessors_t *) descr->accessors;
    408   1.1  christos   as =  unw_create_addr_space_p (acc,
    409   1.1  christos 				 gdbarch_byte_order (gdbarch)
    410   1.1  christos 				 == BFD_ENDIAN_BIG
    411   1.1  christos 				 ? __BIG_ENDIAN
    412   1.1  christos 				 : __LITTLE_ENDIAN);
    413   1.1  christos 
    414   1.1  christos   ret = unw_init_remote_p (&cursor, as, this_frame);
    415   1.1  christos 
    416   1.1  christos   if (ret < 0)
    417   1.1  christos     {
    418   1.1  christos       unw_destroy_addr_space_p (as);
    419   1.1  christos       return 0;
    420   1.1  christos     }
    421   1.1  christos 
    422   1.1  christos   /* Check to see if we are in a signal frame.  */
    423   1.1  christos   ret = unw_is_signal_frame_p (&cursor);
    424   1.1  christos   unw_destroy_addr_space_p (as);
    425   1.1  christos   if (ret > 0)
    426   1.1  christos     return 1;
    427   1.1  christos 
    428   1.1  christos   return 0;
    429   1.1  christos }
    430   1.1  christos 
    431   1.1  christos /* The following routine is for accessing special registers of the top frame.
    432   1.1  christos    A special set of accessors must be given that work without frame info.
    433   1.1  christos    This is used by ia64 to access the rse registers r32-r127.  While they
    434   1.1  christos    are usually located at BOF, this is not always true and only the libunwind
    435   1.1  christos    info can decipher where they actually are.  */
    436   1.1  christos int
    437   1.8  christos libunwind_get_reg_special (struct gdbarch *gdbarch, readable_regcache *regcache,
    438   1.1  christos 			   int regnum, void *buf)
    439   1.1  christos {
    440   1.1  christos   unw_cursor_t cursor;
    441   1.1  christos   unw_accessors_t *acc;
    442   1.1  christos   unw_addr_space_t as;
    443   1.1  christos   struct libunwind_descr *descr;
    444   1.1  christos   int ret;
    445   1.1  christos   unw_regnum_t uw_regnum;
    446   1.1  christos   unw_word_t intval;
    447   1.1  christos   unw_fpreg_t fpval;
    448   1.1  christos   void *ptr;
    449   1.1  christos 
    450   1.1  christos 
    451   1.1  christos   descr = libunwind_descr (gdbarch);
    452   1.6  christos   acc = (unw_accessors_t *) descr->special_accessors;
    453   1.1  christos   as =  unw_create_addr_space_p (acc,
    454   1.1  christos 				 gdbarch_byte_order (gdbarch)
    455   1.1  christos 				 == BFD_ENDIAN_BIG
    456   1.1  christos 				 ? __BIG_ENDIAN
    457   1.1  christos 				 : __LITTLE_ENDIAN);
    458   1.1  christos 
    459   1.1  christos   ret = unw_init_remote_p (&cursor, as, regcache);
    460   1.1  christos   if (ret < 0)
    461   1.1  christos     {
    462   1.1  christos       unw_destroy_addr_space_p (as);
    463   1.1  christos       return -1;
    464   1.1  christos     }
    465   1.1  christos 
    466   1.1  christos   uw_regnum = descr->gdb2uw (regnum);
    467   1.1  christos 
    468   1.1  christos   if (descr->is_fpreg (uw_regnum))
    469   1.1  christos     {
    470   1.1  christos       ret = unw_get_fpreg_p (&cursor, uw_regnum, &fpval);
    471   1.1  christos       ptr = &fpval;
    472   1.1  christos     }
    473   1.1  christos   else
    474   1.1  christos     {
    475   1.1  christos       ret = unw_get_reg_p (&cursor, uw_regnum, &intval);
    476   1.1  christos       ptr = &intval;
    477   1.1  christos     }
    478   1.1  christos 
    479   1.1  christos   unw_destroy_addr_space_p (as);
    480   1.1  christos 
    481   1.1  christos   if (ret < 0)
    482   1.1  christos     return -1;
    483   1.1  christos 
    484   1.1  christos   if (buf)
    485   1.1  christos     memcpy (buf, ptr, register_size (gdbarch, regnum));
    486   1.1  christos 
    487   1.1  christos   return 0;
    488   1.1  christos }
    489   1.1  christos 
    490   1.1  christos static int
    491   1.1  christos libunwind_load (void)
    492   1.1  christos {
    493   1.1  christos   void *handle;
    494   1.1  christos   char *so_error = NULL;
    495   1.1  christos 
    496   1.1  christos   handle = dlopen (LIBUNWIND_SO, RTLD_NOW);
    497   1.1  christos   if (handle == NULL)
    498   1.1  christos     {
    499   1.1  christos       so_error = xstrdup (dlerror ());
    500   1.1  christos #ifdef LIBUNWIND_SO_7
    501   1.1  christos       handle = dlopen (LIBUNWIND_SO_7, RTLD_NOW);
    502   1.1  christos #endif /* LIBUNWIND_SO_7 */
    503   1.1  christos     }
    504   1.1  christos   if (handle == NULL)
    505   1.1  christos     {
    506  1.10  christos       gdb_printf (gdb_stderr, _("[GDB failed to load %s: %s]\n"),
    507  1.10  christos 		  LIBUNWIND_SO, so_error);
    508   1.1  christos #ifdef LIBUNWIND_SO_7
    509  1.10  christos       gdb_printf (gdb_stderr, _("[GDB failed to load %s: %s]\n"),
    510  1.10  christos 		  LIBUNWIND_SO_7, dlerror ());
    511   1.1  christos #endif /* LIBUNWIND_SO_7 */
    512   1.1  christos     }
    513   1.1  christos   xfree (so_error);
    514   1.1  christos   if (handle == NULL)
    515   1.1  christos     return 0;
    516   1.1  christos 
    517   1.1  christos   /* Initialize pointers to the dynamic library functions we will use.  */
    518   1.1  christos 
    519   1.6  christos   unw_get_reg_p = (unw_get_reg_p_ftype *) dlsym (handle, get_reg_name);
    520   1.1  christos   if (unw_get_reg_p == NULL)
    521   1.1  christos     return 0;
    522   1.1  christos 
    523   1.6  christos   unw_get_fpreg_p = (unw_get_fpreg_p_ftype *) dlsym (handle, get_fpreg_name);
    524   1.1  christos   if (unw_get_fpreg_p == NULL)
    525   1.1  christos     return 0;
    526   1.1  christos 
    527   1.6  christos   unw_get_saveloc_p
    528   1.6  christos     = (unw_get_saveloc_p_ftype *) dlsym (handle, get_saveloc_name);
    529   1.1  christos   if (unw_get_saveloc_p == NULL)
    530   1.1  christos     return 0;
    531   1.1  christos 
    532   1.6  christos   unw_is_signal_frame_p
    533   1.6  christos     = (unw_is_signal_frame_p_ftype *) dlsym (handle, is_signal_frame_name);
    534   1.1  christos   if (unw_is_signal_frame_p == NULL)
    535   1.1  christos     return 0;
    536   1.1  christos 
    537   1.6  christos   unw_step_p = (unw_step_p_ftype *) dlsym (handle, step_name);
    538   1.1  christos   if (unw_step_p == NULL)
    539   1.1  christos     return 0;
    540   1.1  christos 
    541   1.6  christos   unw_init_remote_p
    542   1.6  christos     = (unw_init_remote_p_ftype *) dlsym (handle, init_remote_name);
    543   1.1  christos   if (unw_init_remote_p == NULL)
    544   1.1  christos     return 0;
    545   1.1  christos 
    546   1.6  christos   unw_create_addr_space_p
    547   1.6  christos     = (unw_create_addr_space_p_ftype *) dlsym (handle, create_addr_space_name);
    548   1.1  christos   if (unw_create_addr_space_p == NULL)
    549   1.1  christos     return 0;
    550   1.1  christos 
    551   1.6  christos   unw_destroy_addr_space_p
    552   1.6  christos     = (unw_destroy_addr_space_p_ftype *) dlsym (handle,
    553   1.6  christos 						destroy_addr_space_name);
    554   1.1  christos   if (unw_destroy_addr_space_p == NULL)
    555   1.1  christos     return 0;
    556   1.1  christos 
    557   1.6  christos   unw_search_unwind_table_p
    558   1.6  christos     = (unw_search_unwind_table_p_ftype *) dlsym (handle,
    559   1.6  christos 						 search_unwind_table_name);
    560   1.1  christos   if (unw_search_unwind_table_p == NULL)
    561   1.1  christos     return 0;
    562   1.1  christos 
    563   1.6  christos   unw_find_dyn_list_p
    564   1.6  christos     = (unw_find_dyn_list_p_ftype *) dlsym (handle, find_dyn_list_name);
    565   1.1  christos   if (unw_find_dyn_list_p == NULL)
    566   1.1  christos     return 0;
    567   1.1  christos 
    568   1.1  christos   return 1;
    569   1.1  christos }
    570   1.1  christos 
    571   1.1  christos int
    572   1.1  christos libunwind_is_initialized (void)
    573   1.1  christos {
    574   1.1  christos   return libunwind_initialized;
    575   1.1  christos }
    576   1.1  christos 
    577   1.9  christos void _initialize_libunwind_frame ();
    578   1.1  christos void
    579   1.9  christos _initialize_libunwind_frame ()
    580   1.1  christos {
    581   1.1  christos   libunwind_initialized = libunwind_load ();
    582   1.1  christos }
    583