Changeset 6b72040 for doc/working


Ignore:
Timestamp:
Jun 2, 2017, 1:10:26 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
93684eb
Parents:
acd738aa
Message:

The try exception handler function is now generic.

Location:
doc/working/exception
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/working/exception/impl/except.c

    racd738aa r6b72040  
    44
    55#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
    612
    713//Global which defines the current exception
     
    1723                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
    1824{
     25        printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));
     26
    1927        //DEBUG
    2028        printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
     
    111119
    112120                                        //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);
    114125                                        _Unwind_Reason_Code ret = matcher();
    115126
  • doc/working/exception/impl/main.c

    racd738aa r6b72040  
    11#include <stdio.h>
    22#include "except.h"
     3
     4// Requires -fexceptions to work.
    35
    46#define EXCEPTION 2
     
    2628extern int this_exception;
    2729_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;
    2932}
    3033
     
    3437//for details
    3538__attribute__((noinline))
    36 void try( void (*try_block)(), void (*catch_block)() )
     39void try( void (*try_block)(), void (*catch_block)(),
     40          _Unwind_Reason_Code (*match_block)() )
    3741{
     42        volatile int xy = 0;
     43        printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     44
    3845        //Setup statments
    3946        //These 2 statments won't actually result in any code,
     
    95102        "       .uleb128 .CATCH-try\n"                          //Hanlder landing pad adress  (relative to start of function)
    96103        "       .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 matched
    99104        ".LLSDACSECFA2:\n"                                              //BODY end
    100105        "       .text\n"                                                        //TABLE footer
     
    122127
    123128        //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 );
    125130
    126131        printf( "Foo exited normally\n" );
    127132}
    128133
     134// Not in main.cfa
     135void 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
     158void 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
    129183int main() {
    130184        raii_t a = { "Main dtor" };
    131185
    132         for (unsigned int i = 0 ; i < 100000000 ; ++i) foo();
     186        //for (unsigned int i = 0 ; i < 100000000 ; ++i)
     187        foo();
     188        fee();
    133189
    134190        printf("End of program reached\n");
  • doc/working/exception/reference.c

    racd738aa r6b72040  
    114114// __builtin_eh_return_data_regno(^) ^=[0..3]? gives index.
    115115
     116// Locally we also seem to have:
     117_Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
    116118
    117119// 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: ???
    119122
    120123FIRST_PARAM_OFFSET(fundecl)
Note: See TracChangeset for help on using the changeset viewer.