• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DFX_DUMP_RES_H
16 #define DFX_DUMP_RES_H
17 
18 #include <cinttypes>
19 #include <string>
20 #include <sstream>
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 
25 /**
26  * @brief Processdump error code
27  * It describes the status of dumping.
28  */
29 enum DumpErrorCode : int32_t {
30     /** no error */
31     DUMP_ESUCCESS = 0,
32     /** read request error */
33     DUMP_EREADREQUEST,
34     /** ppid is crash */
35     DUMP_EGETPPID,
36     /** ptrace attach thread failed */
37     DUMP_EATTACH,
38     /** get fd error */
39     DUMP_EGETFD,
40     /** out of memory */
41     DUMP_ENOMEM,
42     /** bad register number */
43     DUMP_EBADREG,
44     /** attempt to write read-only register */
45     DUMP_EREADONLYREG,
46     /** stop unwinding */
47     DUMP_ESTOPUNWIND,
48     /** invalid IP */
49     DUMP_EINVALIDIP,
50     /** bad frame */
51     DUMP_EBADFRAME,
52     /** unsupported operation or bad value */
53     DUMP_EINVAL,
54     /** unwind info has unsupported version */
55     DUMP_EBADVERSION,
56     /** no unwind info found */
57     DUMP_ENOINFO,
58 };
59 
60 class DfxDumpRes {
61 public:
ToString(const int32_t & res)62     inline static std::string ToString(const int32_t& res)
63     {
64         std::stringstream ss;
65         ss << std::to_string(res) << " ( " << GetResStr(res) << " )";
66         return ss.str();
67     }
68 
69 private:
GetResStr(const int32_t & res)70     inline static const char* GetResStr(const int32_t& res)
71     {
72         const char *cp;
73         switch (res) {
74             case DUMP_ESUCCESS:     cp = "no error"; break;
75             case DUMP_EREADREQUEST: cp = "read dump request error"; break;
76             case DUMP_EGETPPID:     cp = "ppid is crashed before unwind"; break;
77             case DUMP_EATTACH:      cp = "ptrace attach thread failed"; break;
78             case DUMP_EGETFD:       cp = "get fd error"; break;
79             case DUMP_ENOMEM:       cp = "out of memory"; break;
80             case DUMP_EBADREG:      cp = "bad register number"; break;
81             case DUMP_EREADONLYREG: cp = "attempt to write read-only register"; break;
82             case DUMP_ESTOPUNWIND:  cp = "stop unwinding"; break;
83             case DUMP_EINVALIDIP:   cp = "invalid IP"; break;
84             case DUMP_EBADFRAME:    cp = "bad frame"; break;
85             case DUMP_EINVAL:       cp = "unsupported operation or bad value"; break;
86             case DUMP_EBADVERSION:  cp = "unwind info has unsupported version"; break;
87             case DUMP_ENOINFO:      cp = "no unwind info found"; break;
88             default:                cp = "invalid error code"; break;
89         }
90         return cp;
91     }
92 };
93 } // namespace HiviewDFX
94 } // namespace OHOS
95 #endif
96