Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
unwind.h
Go to the documentation of this file.
00001 
00002 /*
00003 
00004   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00005 
00006   This program is free software; you can redistribute it and/or modify it
00007   under the terms of version 2 of the GNU General Public License as
00008   published by the Free Software Foundation.
00009 
00010   This program is distributed in the hope that it would be useful, but
00011   WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00013 
00014   Further, this software is distributed without any warranty that it is
00015   free of the rightful claim of any third person regarding infringement 
00016   or the like.  Any license provided herein, whether implied or 
00017   otherwise, applies only to this software file.  Patent licenses, if 
00018   any, provided herein do not apply to combinations of this program with 
00019   other software, or any other product whatsoever.  
00020 
00021   You should have received a copy of the GNU General Public License along
00022   with this program; if not, write the Free Software Foundation, Inc., 59
00023   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 /*
00037  * ==========================================================================
00038  *
00039  * Module   : unwind.h -- IA64 unwind consumer header file
00040  *            Used by debuggers, exception handling, stack trace
00041  *
00042  * ==========================================================================
00043  */
00044 
00045 #ifndef __SYS_IA64_UNWIND_H
00046 #define __SYS_IA64_UNWIND_H
00047 
00048 #define VERSION_NUMBER 1
00049 
00050 #include <sys/ia64/unwind_ia64.h>
00051 
00052 #ifndef _LP64
00053 /* Structure modified to reflect IA64 sizes and alignment.  GMB */
00054 typedef struct unw_sigaltstack {
00055   uint64_t /* void * */ ss_sp;
00056   uint32_t /* int */            ss_flags;
00057   uint32_t                      ss_empty;               /* added. GMB. */
00058   uint64_t /* size_t */ ss_size;
00059 } unw_stack_t;
00060 
00061 #define __UNW_STRUCT_FPREG  long double
00062 
00063 
00064 struct _Unwind_Exception;
00065 
00066 struct sigcontext {
00067         uint64_t           sc_flags;       /* see manifest constants above */
00068         uint64_t           sc_nat;         /* bit i == 1 iff gr[i] is a NaT */
00069         unw_stack_t        sc_stack;       /* previously active stack */
00070 
00071         uint64_t           sc_ip;          /* instruction pointer */
00072         uint64_t           sc_cfm;         /* current frame marker */
00073         uint64_t           sc_psr;         /* (some bits of the) processor status reg. */
00074 #if 1
00075         uint64_t           sc_ar_rsc;      /* register stack configuration register */
00076         uint64_t           sc_ar_bsp;      /* backing store pointer */
00077         uint64_t           sc_ar_rnat;     /* RSE NaT collection register */
00078         uint64_t           sc_ar_ccv;      /* compare and exchange compare value register */
00079         uint64_t           sc_ar_unat;     /* ar.unat of interrupted context */
00080         uint64_t           sc_ar_fpsr;     /* floating-point status register */
00081         uint64_t           sc_ar_pfs;      /* previous function state */
00082         uint64_t           sc_ar_ec;       /* epilog count register */
00083         uint64_t           sc_ar_lc;       /* loop count register */
00084 #else
00085         uint64_t           sc_ar[128];
00086 #endif
00087         uint64_t           sc_pr;          /* predicate registers */
00088         uint64_t           sc_br[8];       /* branch registers */
00089         uint64_t           sc_gr[128];
00090         __UNW_STRUCT_FPREG sc_fr[128];     /* floating-point registers */
00091 
00092         /*
00093          * The mask must come last so we can increase _NSIG_WORDS
00094          * without breaking binary compatibility.
00095          */
00096         uint64_t                sc_mask;        /* signal mask to restore after handler returns */
00097 };
00098 
00099 #else
00100 #include <signal.h>
00101 /* #include <asm/sigcontext.h> */
00102 #define __UNW_STRUCT_FPREG  struct ia64_fpreg
00103 
00104 #endif
00105 
00106 struct _Unwind_Context
00107 {
00108   uint64_t unwind_table_addr;   /* cached pointer to unwind table for ip */
00109   uint64_t unwind_info_addr;    /* cached pointer to unwind info for ip */
00110   uint64_t sc_priunat;          /* primary unat collection */
00111   uint64_t sc_ar_ec;            /* epilog counter */
00112   struct sigcontext context;
00113 };
00114 
00115 typedef struct _Unwind_Context unw_sigcontext_t;
00116 
00117 #ifdef __cplusplus
00118 extern "C" {
00119 #endif
00120 
00121 
00122 typedef enum {
00123   
00124         /*
00125          * Indicates that this is not the desired destination frame.
00126          */
00127   _URC_NO_REASON                = 0,
00128 
00129         /*
00130          * Exception caught by a different runtime.  Warning: nested
00131          * foreign exceptions or rethrowing a foreign exception, result
00132          * in undefined behavior.
00133          */
00134   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
00135 
00136         /*
00137          * The personality routine encountered an unexpected error during
00138          * phase 2, e.g., stack corruption caused by landing pad code.
00139          */
00140   _URC_FATAL_PHASE2_ERROR       = 2,
00141 
00142         /*
00143          * The personality routine encountered an unexpected error during
00144          * phase 1.  The unwind runtime has not modified the stack.
00145          * Normally, the C++ runtime will call terminate().
00146          */
00147   _URC_FATAL_PHASE1_ERROR       = 3,
00148 
00149         /*
00150          * 
00151          */
00152   _URC_NORMAL_STOP              = 4,
00153 
00154         /*
00155          * The unwinder encountered the end of the stack during phase 1,
00156          * without finding a handler.   The unwind runtime will not have
00157          * modified the stack.  The C++ runtime will normally call
00158          * uncaught_exception() in this case.
00159          */
00160   _URC_END_OF_STACK             = 5,
00161 
00162         /*
00163          */
00164   _URC_HANDLER_FOUND            = 6,
00165 
00166         /*
00167          */
00168   _URC_INSTALL_CONTEXT          = 7
00169 } _Unwind_Reason_Code;
00170 
00171 
00172 /*
00173  *      The following flags control the behavior of the personality
00174  * routines which are recovered from the unwind tables.
00175  *
00176  *      _UA_SEARCH_PHASE: does the current routine contain a handler?
00177  *            true  => _URC_HANDLER_FOUND
00178  *            false => _URC_CONTINUE_UNWIND
00179  *      _UA_CLEANUP_PHASE: cleansup and returns _URC_CONTINUE_UNWIND
00180  *            or uses a landing pad and returns _URC_INSTALL_CONTEXT
00181  *
00182  * _UA_SEARCH_PHASE and _UA_CLEANUP_PHASE are mutually exclusive.
00183  *
00184  *      _UA_HANDLER_FRAME: Phase 1 determined that this frame was
00185  *            the one with the handler, Phase 2 must handle the
00186  *            exception in this frame.
00187  *
00188  *      _UA_FORCE_UNWIND: Exception may not be caught, used by
00189  *            longjmp or thread cancellation.  Note that _Unwind_Resume
00190  *            may be called rather than having the personality
00191  *            routine return.
00192  */
00193 
00194 typedef int _Unwind_Action;
00195 #if 1
00196 #define _UA_SEARCH_PHASE 1
00197 #define _UA_CLEANUP_PHASE 2
00198 #define _UA_HANDLER_FRAME 4
00199 #define _UA_FORCE_UNWIND 8
00200 #else
00201 const _Unwind_Action _UA_SEARCH_PHASE = 1;
00202 const _Unwind_Action _UA_CLEANUP_PHASE = 2;
00203 const _Unwind_Action _UA_HANDLER_FRAME = 4;
00204 const _Unwind_Action _UA_FORCE_UNWIND = 8;
00205 #endif
00206 
00207 struct _Unwind_Exception;
00208 
00209 typedef void (*_Unwind_Exception_Cleanup_Fn)
00210   (_Unwind_Reason_Code reason,
00211    struct _Unwind_Exception *exc);
00212 
00213 struct _Unwind_Exception {
00214   uint64_t                       exception_class;
00215   _Unwind_Exception_Cleanup_Fn   exception_cleanup;
00216   uint64_t                       private_1;
00217   uint64_t                       private_2;
00218 };
00219 
00220 typedef _Unwind_Reason_Code (* __personality_routine)
00221   (int version,
00222    _Unwind_Action actions,
00223    uint64_t exceptionClass,
00224    struct _Unwind_Exception *exceptionObject,
00225    struct _Unwind_Context *context);
00226 
00227 typedef _Unwind_Reason_Code (* _Unwind_Stop_Fn)
00228   (int version,
00229    _Unwind_Action actions,
00230    uint64_t exceptionClass,
00231    struct _Unwind_Exception *exceptionObject,
00232    struct _Unwind_Context *context,
00233    void* stop_parameter);
00234 
00235    
00236 _Unwind_Reason_Code
00237 _Unwind_RaiseException(
00238     struct _Unwind_Exception *exception_object);
00239 
00240 _Unwind_Reason_Code
00241 _Unwind_ForceUnwind(
00242     struct _Unwind_Exception *exception_object,
00243     _Unwind_Stop_Fn stop,
00244     void* stop_parameter);
00245 
00246 void
00247 _Unwind_Resume(
00248     struct _Unwind_Exception *exception_object);
00249 
00250 void
00251 _Unwind_DeleteException(
00252     struct _Unwind_Exception *exception_object);
00253 
00254 
00255 uint64_t
00256 _Unwind_GetGR(
00257     struct _Unwind_Context *context,
00258     int index);
00259 
00260 void
00261 _Unwind_SetGR(
00262     struct _Unwind_Context *context,
00263     int index,
00264     uint64_t new_value);
00265 
00266 uint64_t
00267 _Unwind_GetIP(
00268     struct _Unwind_Context *context);
00269 
00270 void
00271 _Unwind_SetIP(
00272     struct _Unwind_Context *context,
00273     uint64_t new_value);
00274 
00275 uint64_t
00276 _Unwind_GetLanguageSpecificData(
00277     struct _Unwind_Context *context);
00278 
00279 uint64_t
00280 _Unwind_GetRegionStart(
00281     struct _Unwind_Context *context);
00282 
00283 int __cxa_personality_routine(
00284     int version,
00285     int phase,
00286     uint64_t exceptionClass,
00287     struct _Unwind_Exception *exceptionObject,
00288     struct _Unwind_Context *context);
00289     
00290 
00291 
00292 /***********************************************************************
00293  ***********************************************************************
00294  *
00295  *      The following routines are part of the original unwind library
00296  * and the gdb interface to the unwind library.  They are not part of
00297  * the standard API.
00298  */
00299 
00300 
00301 /* consumer API */
00302 
00303 /* functionality for general operations */
00304 __unw_error_t unwind_init(void);
00305 __unw_error_t unwind_fini(void);
00306 
00307 /* consumer function to unwind past one activation record,
00308    except in simulator it is OK to pass NULL for pid */
00309 __unw_error_t unwind_frame(unw_sigcontext_t *scp);
00310 
00311 /* initialize callback routines for debugger interface */
00312 void unwind_debugger_init(int (*dbg_unwind_table_addr_arg)(uint64_t,
00313                                                 uint64_t *, uint64_t *),
00314                         int (*dbg_unwind_info_addr_arg)(uint64_t,
00315                                                 uint64_t *, uint64_t *),
00316                         int (*dbg_unwind_info_target_addr_arg)(uint64_t,
00317                                                                 uint64_t *),
00318                         int (*dbg_text_segment_target_addr_arg)(uint64_t,
00319                                                                 uint64_t *),
00320                         int (*dbg_restore_gp_arg)(uint64_t,
00321                                                                 uint64_t *),
00322                         int (*dbg_addr_read_arg)(uint64_t,
00323                                                 uint64_t, void *));
00324 
00325 
00326 
00327 int
00328 trace_back_stack(
00329      int num,
00330      uint64_t *ips,
00331      const char **names,
00332      int ips_sz,
00333      int names_sz);
00334 
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339 
00340 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines