• 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 
21 namespace OHOS {
22 namespace HiviewDFX {
23 
24 /**
25  * @brief Processdump error code
26  * It describes the status of dumping.
27  */
28 enum DumpErrorCode : int32_t {
29     /** no error */
30     DUMP_ESUCCESS = 0,
31     /** read request error */
32     DUMP_EREADREQUEST,
33     /** ptrace attach thread failed */
34     DUMP_EATTACH,
35     /** get fd error */
36     DUMP_EGETFD,
37     /** out of memory */
38     DUMP_ENOMEM,
39     /** bad register number */
40     DUMP_EBADREG,
41     /** attempt to write read-only register */
42     DUMP_EREADONLYREG,
43     /** stop unwinding */
44     DUMP_ESTOPUNWIND,
45     /** invalid IP */
46     DUMP_EINVALIDIP,
47     /** bad frame */
48     DUMP_EBADFRAME,
49     /** unsupported operation or bad value */
50     DUMP_EINVAL,
51     /** unwind info has unsupported version */
52     DUMP_EBADVERSION,
53     /** no unwind info found */
54     DUMP_ENOINFO,
55     /** no map info found */
56     DUMP_ENOMAP,
57     /** fail to read real pid */
58     DUMP_EREADPID,
59 };
60 
61 class DfxDumpRes {
62 public:
ToString(const int32_t & res)63     inline static std::string ToString(const int32_t& res)
64     {
65         std::string ss = std::to_string(res) + " ( " + GetResStr(res) + " )";
66         return ss;
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_EATTACH:      cp = "ptrace attach thread failed"; break;
77             case DUMP_EGETFD:       cp = "get fd error"; break;
78             case DUMP_ENOMEM:       cp = "out of memory"; break;
79             case DUMP_EBADREG:      cp = "bad register number"; break;
80             case DUMP_EREADONLYREG: cp = "attempt to write read-only register"; break;
81             case DUMP_ESTOPUNWIND:  cp = "stop unwinding"; break;
82             case DUMP_EINVALIDIP:   cp = "invalid IP"; break;
83             case DUMP_EBADFRAME:    cp = "bad frame"; break;
84             case DUMP_EINVAL:       cp = "unsupported operation or bad value"; break;
85             case DUMP_EBADVERSION:  cp = "unwind info has unsupported version"; break;
86             case DUMP_ENOINFO:      cp = "no unwind info found"; break;
87             case DUMP_ENOMAP:       cp = "mapinfo is not exist"; break;
88             case DUMP_EREADPID:     cp = "fail to read real pid"; break;
89             default:                cp = "invalid error code"; break;
90         }
91         return cp;
92     }
93 };
94 } // namespace HiviewDFX
95 } // namespace OHOS
96 #endif
97