llvm.org GIT mirror llvm / 308b046
ExceptionDemo: prefer headers over redeclarations Rather than redeclaring the interfaces for exceptions, prefer using the `unwind.h` header. This is vended by at least gcc and clang, and can also be found by an external unwinding library (e.g. libunwind). Doing this simplifies the example to the exception handling itself. Minor tweaks are the result of _Unwind_Context_t not being defined, which is just a typedef for struct _Unwind_Context *. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287478 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 2 years ago
1 changed file(s) with 9 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
7878
7979 #include
8080
81 #include
82
8183 #ifndef USE_GLOBAL_STR_CONSTS
8284 #define USE_GLOBAL_STR_CONSTS true
8385 #endif
84
85 // System C++ ABI unwind types from:
86 // http://mentorembedded.github.com/cxx-abi/abi-eh.html (v1.22)
87
88 extern "C" {
89
90 typedef enum {
91 _URC_NO_REASON = 0,
92 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
93 _URC_FATAL_PHASE2_ERROR = 2,
94 _URC_FATAL_PHASE1_ERROR = 3,
95 _URC_NORMAL_STOP = 4,
96 _URC_END_OF_STACK = 5,
97 _URC_HANDLER_FOUND = 6,
98 _URC_INSTALL_CONTEXT = 7,
99 _URC_CONTINUE_UNWIND = 8
100 } _Unwind_Reason_Code;
101
102 typedef enum {
103 _UA_SEARCH_PHASE = 1,
104 _UA_CLEANUP_PHASE = 2,
105 _UA_HANDLER_FRAME = 4,
106 _UA_FORCE_UNWIND = 8,
107 _UA_END_OF_STACK = 16
108 } _Unwind_Action;
109
110 struct _Unwind_Exception;
111
112 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
113 struct _Unwind_Exception *);
114
115 struct _Unwind_Exception {
116 uint64_t exception_class;
117 _Unwind_Exception_Cleanup_Fn exception_cleanup;
118
119 uintptr_t private_1;
120 uintptr_t private_2;
121
122 // @@@ The IA-64 ABI says that this structure must be double-word aligned.
123 // Taking that literally does not make much sense generically. Instead
124 // we provide the maximum alignment required by any type for the machine.
125 } __attribute__((__aligned__));
126
127 struct _Unwind_Context;
128 typedef struct _Unwind_Context *_Unwind_Context_t;
129
130 extern const uint8_t *_Unwind_GetLanguageSpecificData (_Unwind_Context_t c);
131 extern uintptr_t _Unwind_GetGR (_Unwind_Context_t c, int i);
132 extern void _Unwind_SetGR (_Unwind_Context_t c, int i, uintptr_t n);
133 extern void _Unwind_SetIP (_Unwind_Context_t, uintptr_t new_value);
134 extern uintptr_t _Unwind_GetIP (_Unwind_Context_t context);
135 extern uintptr_t _Unwind_GetRegionStart (_Unwind_Context_t context);
136
137 } // extern "C"
13886
13987 //
14088 // Example types
641589 /// @param exceptionObject thrown _Unwind_Exception instance.
642590 /// @param context unwind system context
643591 /// @returns minimally supported unwinding control indicator
644 static _Unwind_Reason_Code handleLsda(int version,
645 const uint8_t *lsda,
592 static _Unwind_Reason_Code handleLsda(int version, const uint8_t *lsda,
646593 _Unwind_Action actions,
647 uint64_t exceptionClass,
648 struct _Unwind_Exception *exceptionObject,
649 _Unwind_Context_t context) {
594 _Unwind_Exception_Class exceptionClass,
595 struct _Unwind_Exception *exceptionObject,
596 struct _Unwind_Context *context) {
650597 _Unwind_Reason_Code ret = _URC_CONTINUE_UNWIND;
651598
652599 if (!lsda)
825772 /// @param exceptionObject thrown _Unwind_Exception instance.
826773 /// @param context unwind system context
827774 /// @returns minimally supported unwinding control indicator
828 _Unwind_Reason_Code ourPersonality(int version,
829 _Unwind_Action actions,
830 uint64_t exceptionClass,
775 _Unwind_Reason_Code ourPersonality(int version, _Unwind_Action actions,
776 _Unwind_Exception_Class exceptionClass,
831777 struct _Unwind_Exception *exceptionObject,
832 _Unwind_Context_t context) {
778 struct _Unwind_Context *context) {
833779 #ifdef DEBUG
834780 fprintf(stderr,
835781 "We are in ourPersonality(...):actions is <%d>.\n",