• 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  * @brief dump poll error code
25  * It describes the status of dump poll.
26  */
27 enum DfxDumpPollRes : int32_t {
28     DUMP_POLL_INIT = -1,
29     DUMP_POLL_OK,
30     DUMP_POLL_FD,
31     DUMP_POLL_FAILED,
32     DUMP_POLL_TIMEOUT,
33     DUMP_POLL_RETURN,
34     DUMP_POLL_NO_PARSE_SYMBOL,
35     DUMP_POLL_PARSE_SYMBOL_TIMEOUT,
36 };
37 
38 /**
39  * @brief Processdump error code
40  * It describes the status of dumping.
41  */
42 enum DumpErrorCode : int32_t {
43     /** no error */
44     DUMP_ESUCCESS = 0,
45     /** read request error */
46     DUMP_EREADREQUEST,
47     /** ptrace attach thread failed */
48     DUMP_EATTACH,
49     /** get fd error */
50     DUMP_EGETFD,
51     /** out of memory */
52     DUMP_ENOMEM,
53     /** bad register number */
54     DUMP_EBADREG,
55     /** attempt to write read-only register */
56     DUMP_EREADONLYREG,
57     /** stop unwinding */
58     DUMP_ESTOPUNWIND,
59     /** invalid IP */
60     DUMP_EINVALIDIP,
61     /** bad frame */
62     DUMP_EBADFRAME,
63     /** unsupported operation or bad value */
64     DUMP_EINVAL,
65     /** unwind info has unsupported version */
66     DUMP_EBADVERSION,
67     /** no unwind info found */
68     DUMP_ENOINFO,
69     /** no map info found */
70     DUMP_ENOMAP,
71     /** fail to read real pid */
72     DUMP_EREADPID,
73     /** no enough time to parse symbol*/
74     DUMP_ESYMBOL_NO_PARSE,
75     /** parse symbol timeout */
76     DUMP_ESYMBOL_PARSE_TIMEOUT,
77 };
78 
79 class DfxDumpRes {
80 public:
ToString(int32_t res)81     inline static std::string ToString(int32_t res)
82     {
83         return std::to_string(res) + " ( " + GetResStr(res) + " )";
84     }
85 
86 private:
87     struct DumpErrInfo {
88         int32_t errCode;
89         const char *info;
90     };
GetResStr(int32_t res)91     static const char* GetResStr(int32_t res)
92     {
93         const DumpErrInfo errInfos[] = {
94             { DUMP_ESUCCESS, "no error" },
95             { DUMP_EREADREQUEST, "read dump request error" },
96             { DUMP_EATTACH, "ptrace attach thread failed" },
97             { DUMP_EGETFD, "get fd error" },
98             { DUMP_ENOMEM, "out of memory" },
99             { DUMP_EBADREG, "bad register number" },
100             { DUMP_EREADONLYREG, "attempt to write read-only register" },
101             { DUMP_ESTOPUNWIND, "stop unwinding" },
102             { DUMP_EINVALIDIP, "invalid IP" },
103             { DUMP_EBADFRAME, "bad frame" },
104             { DUMP_EINVAL, "unsupported operation or bad value" },
105             { DUMP_EBADVERSION, "unwind info has unsupported version" },
106             { DUMP_ENOINFO, "no unwind info found" },
107             { DUMP_ENOMAP, "mapinfo is not exist" },
108             { DUMP_EREADPID, "fail to read real pid" },
109             { DUMP_ESYMBOL_NO_PARSE, "no enough time to parse symbol" },
110             { DUMP_ESYMBOL_PARSE_TIMEOUT, "parse symbol timeout" },
111         };
112 
113         auto iter = std::find_if(std::begin(errInfos), std::end(errInfos), [res](const DumpErrInfo &ele) {
114             return ele.errCode == res;
115         });
116         return iter != std::end(errInfos) ? iter->info : "invalid error code";
117     }
118 };
119 } // namespace HiviewDFX
120 } // namespace OHOS
121 #endif
122