Changeset 6b72040 for doc/working
- Timestamp:
- Jun 2, 2017, 1:10:26 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 93684eb
- Parents:
- acd738aa
- Location:
- doc/working/exception
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/working/exception/impl/except.c
racd738aa r6b72040 4 4 5 5 #include "lsda.h" 6 7 // This macro should be the only thing that needs to change across machines. 8 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)() 9 #define MATCHER_FROM_CONTEXT(ptr_to_context) \ 10 (*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8)) 11 6 12 7 13 //Global which defines the current exception … … 17 23 struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context) 18 24 { 25 printf("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 26 19 27 //DEBUG 20 28 printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); … … 111 119 112 120 //Get a function pointer from the relative offset and call it 113 _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 121 // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher; 122 123 _Unwind_Reason_Code (*matcher)() = 124 MATCHER_FROM_CONTEXT(context); 114 125 _Unwind_Reason_Code ret = matcher(); 115 126 -
doc/working/exception/impl/main.c
racd738aa r6b72040 1 1 #include <stdio.h> 2 2 #include "except.h" 3 4 // Requires -fexceptions to work. 3 5 4 6 #define EXCEPTION 2 … … 26 28 extern int this_exception; 27 29 _Unwind_Reason_Code foo_try_match() { 28 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 30 printf(" (foo_try_match called)"); 31 return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 29 32 } 30 33 … … 34 37 //for details 35 38 __attribute__((noinline)) 36 void try( void (*try_block)(), void (*catch_block)() ) 39 void try( void (*try_block)(), void (*catch_block)(), 40 _Unwind_Reason_Code (*match_block)() ) 37 41 { 42 volatile int xy = 0; 43 printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy); 44 38 45 //Setup statments 39 46 //These 2 statments won't actually result in any code, … … 95 102 " .uleb128 .CATCH-try\n" //Hanlder landing pad adress (relative to start of function) 96 103 " .uleb128 1\n" //Action code, gcc seems to use always 0 97 //Beyond this point we don't match gcc data'98 " .uleb128 foo_try_match-try\n" //Handler routine to check if the exception is matched99 104 ".LLSDACSECFA2:\n" //BODY end 100 105 " .text\n" //TABLE footer … … 122 127 123 128 //Actual call to the try block 124 try( foo_try_block, foo_catch_block );129 try( foo_try_block, foo_catch_block, foo_try_match ); 125 130 126 131 printf( "Foo exited normally\n" ); 127 132 } 128 133 134 // Not in main.cfa 135 void fy() { 136 // Currently not destroyed if the exception is caught in fee. 137 raii_t a = { "Fy dtor" }; 138 139 void fy_try_block() { 140 raii_t b = { "Fy try dtor" }; 141 142 throw( 3 ); 143 } 144 145 void fy_catch_block() { 146 printf("Fy caught exception\n"); 147 } 148 149 _Unwind_Reason_Code fy_match_block() { 150 return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 151 } 152 153 try(fy_try_block, fy_catch_block, fy_match_block); 154 155 printf( "Fy exited normally\n" ); 156 } 157 158 void fee() { 159 raii_t a = { "Fee dtor" }; 160 161 void fee_try_block() { 162 raii_t b = { "Fee try dtor" }; 163 164 fy(); 165 166 printf("fy returned\n"); 167 } 168 169 void fee_catch_block() { 170 printf("Fee caught exception\n"); 171 } 172 173 _Unwind_Reason_Code fee_match_block() { 174 return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND; 175 } 176 177 try(fee_try_block, fee_catch_block, fee_match_block); 178 179 printf( "Fee exited normally\n" ); 180 } 181 // End not in main.cfa 182 129 183 int main() { 130 184 raii_t a = { "Main dtor" }; 131 185 132 for (unsigned int i = 0 ; i < 100000000 ; ++i) foo(); 186 //for (unsigned int i = 0 ; i < 100000000 ; ++i) 187 foo(); 188 fee(); 133 189 134 190 printf("End of program reached\n"); -
doc/working/exception/reference.c
racd738aa r6b72040 114 114 // __builtin_eh_return_data_regno(^) ^=[0..3]? gives index. 115 115 116 // Locally we also seem to have: 117 _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *); 116 118 117 119 // GCC (Dwarf2 ?) Frame Layout Macros 118 // https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 120 // See: https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html 121 // Include from: ??? 119 122 120 123 FIRST_PARAM_OFFSET(fundecl)
Note: See TracChangeset
for help on using the changeset viewer.