Changeset 21476 for trunk/testapp/exceptions/seh
- Timestamp:
- Nov 16, 2010, 11:38:57 PM (15 years ago)
- Location:
- trunk/testapp/exceptions/seh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/testapp/exceptions/seh/Makefile
r21449 r21476 3 3 include $(ODIN)/testapp/common.mak 4 4 5 all: except.exe finally.exe # except.s 5 all: except.exe finally.exe longjmp.exe # except.s 6 7 except.exe_ARGS.1 = 1 8 except.exe_ARGS.2 = 2 9 except.exe_ARGS.3 = 3 10 except.exe_ARGS.4 = 4 6 11 7 12 finally.exe_ARGS.1 = 1 … … 9 14 finally.exe_ARGS.3 = 3 10 15 11 run: run-except.exe $(call run-with-args,finally.exe,1 2 3,all) 16 longjmp.exe_ARGS.1 = 1 17 longjmp.exe_ARGS.2 = 2 18 19 run: \ 20 $(call run-with-args,except.exe,1 2 3 4,all) \ 21 $(call run-with-args,finally.exe,1 2 3,all) \ 22 $(call run-with-args,longjmp.exe,1 2,all) 12 23 13 24 CLEAN += *.s -
trunk/testapp/exceptions/seh/except.c
r21449 r21476 8 8 9 9 int _main(); 10 int _argc; 11 char **_argv; 10 12 11 13 int WIN32API WinMain(HANDLE hInstance, … … 14 16 int nCmdShow) 15 17 { 16 return _main( );18 return _main(_argc, _argv); 17 19 } 18 20 19 int main( )21 int main(int argc, char **argv) 20 22 { 23 _argc = argc; 24 _argv = argv; 21 25 EnableSEH(); 22 26 RegisterLxExe(WinMain, NULL); … … 27 31 #endif 28 32 29 int exc_filter(DWORD code, DWORD filtercode, PEXCEPTION_RECORD pRec) 33 int testCode = 0; 34 35 int tries = 3; 36 37 int exc_filter(DWORD code, DWORD filtercode, PEXCEPTION_POINTERS pPtrs) 30 38 { 39 PEXCEPTION_RECORD pRec = pPtrs->ExceptionRecord; 40 31 41 printf("Filter: code %08lx, filtercode %08lx\n", code, filtercode); 32 42 printf("ExceptionCode %p\n", pRec->ExceptionCode); … … 34 44 printf("NumberParameters %d\n", pRec->NumberParameters); 35 45 36 // if (code == filtercode) 46 if (code == filtercode) 47 { 48 if (testCode == 4 && tries) 49 { 50 --tries; 51 return EXCEPTION_CONTINUE_EXECUTION; 52 } 53 37 54 return EXCEPTION_EXECUTE_HANDLER; 38 // return EXCEPTION_CONTINUE_SEARCH; 39 // return EXCEPTION_CONTINUE_EXECUTION; 55 } 56 57 return EXCEPTION_CONTINUE_SEARCH; 40 58 } 41 59 … … 54 72 } 55 73 56 int _main( )74 int _main(int argc, char **argv) 57 75 { 76 testCode = argc > 1 ? atoi(argv[1]) : 0; 77 78 switch (testCode) 79 { 80 case 1: 81 printf("Target: Throw EXCEPTION_ACCESS_VIOLATION from inner __try\n" 82 "and catch it in inner __except.\n\n"); 83 break; 84 case 2: 85 printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from inner __try\n" 86 "and catch it in outer __except.\n\n"); 87 break; 88 case 3: 89 printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from outer __try\n" 90 "and catch it in outer __except.\n\n"); 91 break; 92 case 4: 93 printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from outer __try,\n" 94 "fix it in the handler and continue execution.\n\n"); 95 break; 96 default: 97 printf("Invalid test code %d\n", testCode); 98 return 1; 99 } 100 58 101 __try 59 102 { 60 #if 0 61 throw_EXCEPTION_INT_DIVIDE_BY_ZERO(); 62 printf("FAILED: No outer exception!\n"); 63 return 1; 64 #endif 103 if (testCode == 3 || testCode == 4) 104 { 105 throw_EXCEPTION_INT_DIVIDE_BY_ZERO(); 106 107 printf("FAILED: No outer exception!\n"); 108 return 1; 109 } 110 65 111 __try 66 112 { 67 #if 1 68 throw_EXCEPTION_ACCESS_VIOLATION();69 #else 70 throw_EXCEPTION_INT_DIVIDE_BY_ZERO();71 #endif 113 if (testCode == 1) 114 throw_EXCEPTION_ACCESS_VIOLATION(); 115 else if (testCode == 2) 116 throw_EXCEPTION_INT_DIVIDE_BY_ZERO(); 117 72 118 printf("FAILED: No inner exception!\n"); 73 119 return 1; 74 120 } 75 121 __except(exc_filter(GetExceptionCode(), 76 EXCEPTION_ACCESS_VIOLATION,77 _exception_info()->ExceptionRecord))122 EXCEPTION_ACCESS_VIOLATION, 123 exception_info())) 78 124 { 79 125 // handle exception … … 82 128 } 83 129 __except(exc_filter(GetExceptionCode(), 84 EXCEPTION_INT_DIVIDE_BY_ZERO,85 _exception_info()->ExceptionRecord))130 EXCEPTION_INT_DIVIDE_BY_ZERO, 131 exception_info())) 86 132 { 133 if (testCode == 4 && tries) 134 { 135 printf("FAILED: Outer exception (tries = %d)!\n", tries); 136 return 1; 137 } 138 87 139 // handle exception 88 140 printf("Outer exception handled.\n");
Note:
See TracChangeset
for help on using the changeset viewer.