1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci#ifndef DFX_DUMP_RES_H
16800b99b8Sopenharmony_ci#define DFX_DUMP_RES_H
17800b99b8Sopenharmony_ci
18800b99b8Sopenharmony_ci#include <cinttypes>
19800b99b8Sopenharmony_ci#include <string>
20800b99b8Sopenharmony_ci
21800b99b8Sopenharmony_cinamespace OHOS {
22800b99b8Sopenharmony_cinamespace HiviewDFX {
23800b99b8Sopenharmony_ci
24800b99b8Sopenharmony_ci/**
25800b99b8Sopenharmony_ci * @brief Processdump error code
26800b99b8Sopenharmony_ci * It describes the status of dumping.
27800b99b8Sopenharmony_ci */
28800b99b8Sopenharmony_cienum DumpErrorCode : int32_t {
29800b99b8Sopenharmony_ci    /** no error */
30800b99b8Sopenharmony_ci    DUMP_ESUCCESS = 0,
31800b99b8Sopenharmony_ci    /** read request error */
32800b99b8Sopenharmony_ci    DUMP_EREADREQUEST,
33800b99b8Sopenharmony_ci    /** ppid is crash */
34800b99b8Sopenharmony_ci    DUMP_EGETPPID,
35800b99b8Sopenharmony_ci    /** ptrace attach thread failed */
36800b99b8Sopenharmony_ci    DUMP_EATTACH,
37800b99b8Sopenharmony_ci    /** get fd error */
38800b99b8Sopenharmony_ci    DUMP_EGETFD,
39800b99b8Sopenharmony_ci    /** out of memory */
40800b99b8Sopenharmony_ci    DUMP_ENOMEM,
41800b99b8Sopenharmony_ci    /** bad register number */
42800b99b8Sopenharmony_ci    DUMP_EBADREG,
43800b99b8Sopenharmony_ci    /** attempt to write read-only register */
44800b99b8Sopenharmony_ci    DUMP_EREADONLYREG,
45800b99b8Sopenharmony_ci    /** stop unwinding */
46800b99b8Sopenharmony_ci    DUMP_ESTOPUNWIND,
47800b99b8Sopenharmony_ci    /** invalid IP */
48800b99b8Sopenharmony_ci    DUMP_EINVALIDIP,
49800b99b8Sopenharmony_ci    /** bad frame */
50800b99b8Sopenharmony_ci    DUMP_EBADFRAME,
51800b99b8Sopenharmony_ci    /** unsupported operation or bad value */
52800b99b8Sopenharmony_ci    DUMP_EINVAL,
53800b99b8Sopenharmony_ci    /** unwind info has unsupported version */
54800b99b8Sopenharmony_ci    DUMP_EBADVERSION,
55800b99b8Sopenharmony_ci    /** no unwind info found */
56800b99b8Sopenharmony_ci    DUMP_ENOINFO,
57800b99b8Sopenharmony_ci    /** no map info found */
58800b99b8Sopenharmony_ci    DUMP_ENOMAP,
59800b99b8Sopenharmony_ci    /** fail to read real pid */
60800b99b8Sopenharmony_ci    DUMP_EREADPID,
61800b99b8Sopenharmony_ci};
62800b99b8Sopenharmony_ci
63800b99b8Sopenharmony_ciclass DfxDumpRes {
64800b99b8Sopenharmony_cipublic:
65800b99b8Sopenharmony_ci    inline static std::string ToString(const int32_t& res)
66800b99b8Sopenharmony_ci    {
67800b99b8Sopenharmony_ci        std::string ss = std::to_string(res) + " ( " + GetResStr(res) + " )";
68800b99b8Sopenharmony_ci        return ss;
69800b99b8Sopenharmony_ci    }
70800b99b8Sopenharmony_ci
71800b99b8Sopenharmony_ciprivate:
72800b99b8Sopenharmony_ci    inline static const char* GetResStr(const int32_t& res)
73800b99b8Sopenharmony_ci    {
74800b99b8Sopenharmony_ci        const char *cp;
75800b99b8Sopenharmony_ci        switch (res) {
76800b99b8Sopenharmony_ci            case DUMP_ESUCCESS:     cp = "no error"; break;
77800b99b8Sopenharmony_ci            case DUMP_EREADREQUEST: cp = "read dump request error"; break;
78800b99b8Sopenharmony_ci            case DUMP_EGETPPID:     cp = "ppid is crashed before unwind"; break;
79800b99b8Sopenharmony_ci            case DUMP_EATTACH:      cp = "ptrace attach thread failed"; break;
80800b99b8Sopenharmony_ci            case DUMP_EGETFD:       cp = "get fd error"; break;
81800b99b8Sopenharmony_ci            case DUMP_ENOMEM:       cp = "out of memory"; break;
82800b99b8Sopenharmony_ci            case DUMP_EBADREG:      cp = "bad register number"; break;
83800b99b8Sopenharmony_ci            case DUMP_EREADONLYREG: cp = "attempt to write read-only register"; break;
84800b99b8Sopenharmony_ci            case DUMP_ESTOPUNWIND:  cp = "stop unwinding"; break;
85800b99b8Sopenharmony_ci            case DUMP_EINVALIDIP:   cp = "invalid IP"; break;
86800b99b8Sopenharmony_ci            case DUMP_EBADFRAME:    cp = "bad frame"; break;
87800b99b8Sopenharmony_ci            case DUMP_EINVAL:       cp = "unsupported operation or bad value"; break;
88800b99b8Sopenharmony_ci            case DUMP_EBADVERSION:  cp = "unwind info has unsupported version"; break;
89800b99b8Sopenharmony_ci            case DUMP_ENOINFO:      cp = "no unwind info found"; break;
90800b99b8Sopenharmony_ci            case DUMP_ENOMAP:       cp = "mapinfo is not exist"; break;
91800b99b8Sopenharmony_ci            case DUMP_EREADPID:     cp = "fail to read real pid"; break;
92800b99b8Sopenharmony_ci            default:                cp = "invalid error code"; break;
93800b99b8Sopenharmony_ci        }
94800b99b8Sopenharmony_ci        return cp;
95800b99b8Sopenharmony_ci    }
96800b99b8Sopenharmony_ci};
97800b99b8Sopenharmony_ci} // namespace HiviewDFX
98800b99b8Sopenharmony_ci} // namespace OHOS
99800b99b8Sopenharmony_ci#endif
100