1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DFX_CRASHER_H 17 #define DFX_CRASHER_H 18 19 #include <cinttypes> 20 #include <string> 21 22 #define NOINLINE __attribute__((noinline)) 23 24 #define GEN_TEST_FUNCTION(FuncNumA, FuncNumB) \ 25 __attribute__((noinline)) int TestFunc##FuncNumA() \ 26 { \ 27 return TestFunc##FuncNumB(); \ 28 } 29 30 class DfxCrasher { 31 public: 32 33 static DfxCrasher &GetInstance(); 34 ~DfxCrasher(); 35 36 static int RaiseAbort(); 37 static int RaiseBusError(); 38 static int RaiseFloatingPointException(); 39 static int RaiseIllegalInstructionException(); 40 static int RaiseSegmentFaultException(); 41 static int RaiseTrapException(); 42 static int IllegalInstructionException(); 43 static int SegmentFaultException(); 44 static int Abort(); 45 static int Loop(); 46 47 void PrintUsage() const; 48 49 static void* DoCrashInThread(void* inputArg); 50 uint64_t DoActionOnSubThread(const char* arg) const; 51 uint64_t ParseAndDoCrash(const char* arg) const; 52 static int MaxStackDepth(); 53 static int MultiThreadCrash(); 54 static int ProgramCounterZero(); 55 static int StackOver64(); 56 static int StackTop(); 57 // 1 2 3 4 5 6 7 58 // 1234567890123456789012345678901234567890123456789012345678901234567890 59 static int MaxMethodNameTest12345678901234567890123456789012345678901234567890ABC(); 60 static int TriggerSegmentFaultException(); 61 static int StackOverflow(); 62 static int Oom(); 63 static int TriggerTrapException(); 64 static int CrashInLambda(); 65 static int DoDumpCrash(); 66 static int TestExitHook(); 67 static int TestSigHook(); 68 static int StackCorruption(); 69 static int StackCorruption2(); 70 71 static int RecursiveFunc(int curLevel, int targetLevel, int midLevel); 72 static int PrintFatalMessageInLibc(); 73 static int TestGetCrashObj(); 74 #ifndef is_ohos_lite 75 static int AsyncStacktrace(); 76 static int CrashInFFRT(const std::string &debug); 77 static int CrashInLibuvWork(const std::string &debug); 78 static int CrashInLibuvTimer(const std::string &debug); 79 static int CrashInLibuvWorkDone(const std::string &debug); 80 #endif 81 static int TestDeadlock(); 82 83 private: 84 DfxCrasher(); 85 DfxCrasher(const DfxCrasher &) = delete; 86 DfxCrasher &operator=(const DfxCrasher &) = delete; 87 }; 88 int SleepThread(int threadID); 89 // test functions for callstack depth test 90 int TestFunc0(void); 91 int TestFunc1(void); 92 int TestFunc2(void); 93 int TestFunc3(void); 94 int TestFunc4(void); 95 int TestFunc5(void); 96 int TestFunc6(void); 97 int TestFunc7(void); 98 int TestFunc8(void); 99 int TestFunc9(void); 100 int TestFunc10(void); 101 int TestFunc11(void); 102 int TestFunc12(void); 103 int TestFunc13(void); 104 int TestFunc14(void); 105 int TestFunc15(void); 106 int TestFunc16(void); 107 int TestFunc17(void); 108 int TestFunc18(void); 109 int TestFunc19(void); 110 int TestFunc20(void); 111 int TestFunc21(void); 112 int TestFunc22(void); 113 int TestFunc23(void); 114 int TestFunc24(void); 115 int TestFunc25(void); 116 int TestFunc26(void); 117 int TestFunc27(void); 118 int TestFunc28(void); 119 int TestFunc29(void); 120 int TestFunc30(void); 121 int TestFunc31(void); 122 int TestFunc32(void); 123 int TestFunc33(void); 124 int TestFunc34(void); 125 int TestFunc35(void); 126 int TestFunc36(void); 127 int TestFunc37(void); 128 int TestFunc38(void); 129 int TestFunc39(void); 130 int TestFunc40(void); 131 int TestFunc41(void); 132 int TestFunc42(void); 133 int TestFunc43(void); 134 int TestFunc44(void); 135 int TestFunc45(void); 136 int TestFunc46(void); 137 int TestFunc47(void); 138 int TestFunc48(void); 139 int TestFunc49(void); 140 int TestFunc50(void); 141 int TestFunc51(void); 142 int TestFunc52(void); 143 int TestFunc53(void); 144 int TestFunc54(void); 145 int TestFunc55(void); 146 int TestFunc56(void); 147 int TestFunc57(void); 148 int TestFunc58(void); 149 int TestFunc59(void); 150 int TestFunc60(void); 151 int TestFunc61(void); 152 int TestFunc62(void); 153 int TestFunc63(void); 154 int TestFunc64(void); 155 int TestFunc65(void); 156 int TestFunc66(void); 157 int TestFunc67(void); 158 int TestFunc68(void); 159 int TestFunc69(void); 160 int TestFunc70(void); 161 162 #endif // DFX_CRASHER_H 163