• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 /* This files contains faultlog crasher modules. */
17 
18 #ifndef DFX_CRASHER_H
19 #define DFX_CRASHER_H
20 
21 #include <cinttypes>
22 
23 #define NOINLINE __attribute__((noinline))
24 
25 #define GEN_TEST_FUNCTION(FuncNumA, FuncNumB)          \
26     __attribute__((noinline)) int TestFunc##FuncNumA() \
27     {                                                  \
28         return TestFunc##FuncNumB();                   \
29     }
30 
31 class DfxCrasher {
32 public:
33 
34     static DfxCrasher &GetInstance();
35     ~DfxCrasher();
36 
37     int RaiseAbort() const;
38     int RaiseBusError() const;
39     int RaiseFloatingPointException() const;
40     int RaiseIllegalInstructionException() const;
41     int RaiseSegmentFaultException() const;
42     int RaiseTrapException() const;
43     int IllegalInstructionException(void) const;
44     int SegmentFaultException(void) const;
45     int Abort(void) const;
46 
47     int DumpStackTrace() const;
48     void PrintUsage() const;
49 
50     static void* DoCrashInThread(void * inputArg);
51     uint64_t DoActionOnSubThread(const char* arg) const;
52     uint64_t ParseAndDoCrash(const char* arg);
53     int MaxStackDepth() const;
54     int MultiThreadCrash() const;
55     int ProgramCounterZero() const;
56     int StackOver64() const;
57     int StackTop() const;
58     //           1         2         3         4         5         6         7
59     //  1234567890123456789012345678901234567890123456789012345678901234567890
60     int MaxMethodNameTest12345678901234567890123456789012345678901234567890ABC() const;
61 
62     int TriggerSegmentFaultException() const;
63     int StackOverflow() const;
64     int Oom() const;
65     int TriggerTrapException() const;
66 
67 private:
68     DfxCrasher();
69     DfxCrasher(const DfxCrasher &) = delete;
70     DfxCrasher &operator=(const DfxCrasher &) = delete;
71 };
72 int SleepThread(int threadID);
73 // test functions for callstack depth test
74 int TestFunc0(void);
75 int TestFunc1(void);
76 int TestFunc2(void);
77 int TestFunc3(void);
78 int TestFunc4(void);
79 int TestFunc5(void);
80 int TestFunc6(void);
81 int TestFunc7(void);
82 int TestFunc8(void);
83 int TestFunc9(void);
84 int TestFunc10(void);
85 int TestFunc11(void);
86 int TestFunc12(void);
87 int TestFunc13(void);
88 int TestFunc14(void);
89 int TestFunc15(void);
90 int TestFunc16(void);
91 int TestFunc17(void);
92 int TestFunc18(void);
93 int TestFunc19(void);
94 int TestFunc20(void);
95 int TestFunc21(void);
96 int TestFunc22(void);
97 int TestFunc23(void);
98 int TestFunc24(void);
99 int TestFunc25(void);
100 int TestFunc26(void);
101 int TestFunc27(void);
102 int TestFunc28(void);
103 int TestFunc29(void);
104 int TestFunc30(void);
105 int TestFunc31(void);
106 int TestFunc32(void);
107 int TestFunc33(void);
108 int TestFunc34(void);
109 int TestFunc35(void);
110 int TestFunc36(void);
111 int TestFunc37(void);
112 int TestFunc38(void);
113 int TestFunc39(void);
114 int TestFunc40(void);
115 int TestFunc41(void);
116 int TestFunc42(void);
117 int TestFunc43(void);
118 int TestFunc44(void);
119 int TestFunc45(void);
120 int TestFunc46(void);
121 int TestFunc47(void);
122 int TestFunc48(void);
123 int TestFunc49(void);
124 int TestFunc50(void);
125 int TestFunc51(void);
126 int TestFunc52(void);
127 int TestFunc53(void);
128 int TestFunc54(void);
129 int TestFunc55(void);
130 int TestFunc56(void);
131 int TestFunc57(void);
132 int TestFunc58(void);
133 int TestFunc59(void);
134 int TestFunc60(void);
135 int TestFunc61(void);
136 int TestFunc62(void);
137 int TestFunc63(void);
138 int TestFunc64(void);
139 int TestFunc65(void);
140 int TestFunc66(void);
141 int TestFunc67(void);
142 int TestFunc68(void);
143 int TestFunc69(void);
144 int TestFunc70(void);
145 
146 #endif // DFX_CRASHER_H
147