• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "dfx_dump_catcher_errno.h"
17 #include <algorithm>
18 namespace OHOS {
19 namespace HiviewDFX {
20 struct DumpCatchErrInfo {
21     int32_t code;
22     const char *info;
23 };
24 
25 const DumpCatchErrInfo ERROR_CODE_MAPS[] = {
26     { DUMPCATCH_ESUCCESS, "success" },
27     { DUMPCATCH_EPARAM, "param error" },
28     { DUMPCATCH_NO_PROCESS, "process has exited" },
29     { DUMPCATCH_IS_DUMPING, "process is dumping" },
30     { DUMPCATCH_EPERMISSION, "check permission error" },
31     { DUMPCATCH_HAS_CRASHED, "process has been crashed" },
32     { DUMPCATCH_ECONNECT, "failed to connect to faultloggerd" },
33     { DUMPCATCH_EWRITE, "failed to write data to faultloggerd" },
34     { DUMPCATCH_EFD, "buf or res fd error" },
35     { DUMPCATCH_EPOLL, "poll error" },
36     { DUMPCATCH_EFAULTLOGGERD, "faultloggerd maybe exception occurred" },
37     { DUMPCATCH_DUMP_EPTRACE, "failed to ptrace thread" },
38     { DUMPCATCH_DUMP_EUNWIND, "failed to unwind" },
39     { DUMPCATCH_DUMP_EMAP, "failed to find map" },
40     { DUMPCATCH_DUMP_ERROR, "exception occurred in processdump" },
41     { DUMPCATCH_TIMEOUT_SIGNAL_BLOCK, "signal has been block by target process" },
42     { DUMPCATCH_TIMEOUT_KERNEL_FROZEN, "target process has been frozen in kernel" },
43     { DUMPCATCH_TIMEOUT_PROCESS_KILLED, "target process has been killed during dumping" },
44     { DUMPCATCH_TIMEOUT_DUMP_SLOW, "failed to fully dump due to timeout" },
45     { DUMPCATCH_TIMEOUT_DUMP_IN_SLOWPERIOD, "in dump slow period and return kernel stack" },
46     { DUMPCATCH_TIMEOUT_PARSE_FAIL_READ_ESTATUS, "dump timeout, parse reason fail for read status fail" },
47     { DUMPCATCH_TIMEOUT_PARSE_FAIL_READ_ECGROUP, "dump timeout, parse reason fail for read cgroup fail" },
48     { DUMPCATCH_KERNELSTACK_ECREATE, "kernelstack fail due to create hstackval fail" },
49     { DUMPCATCH_KERNELSTACK_EOPEN, "kernelstack fail due to open bbox fail" },
50     { DUMPCATCH_KERNELSTACK_EIOCTL, "kernelstack fail due to ioctl fail" },
51     { DUMPCATCH_KERNELSTACK_TIMEOUT, "kernelstack fail due to wait timeout" },
52     { DUMPCATCH_KERNELSTACK_OVER_LIMIT, "kernelstack fail due to over limit" },
53     { DUMPCATCH_KERNELSTACK_NONEED, "no need to dump kernelstack" },
54     { DUMPCATCH_DUMP_ESYMBOL_NO_PARSE, "no enough time to parse symbol" },
55     { DUMPCATCH_DUMP_ESYMBOL_PARSE_TIMEOUT, "parse symbol timeout" },
56     { DUMPCATCH_DUMP_SELF_FAIL, "dump self fail" },
57     { DUMPCATCH_UNKNOWN, "unknown reason" }
58 };
59 
ToString(const int32_t res)60 std::string DfxDumpCatchError::ToString(const int32_t res)
61 {
62     auto iter = std::find_if(std::begin(ERROR_CODE_MAPS), std::end(ERROR_CODE_MAPS),
63         [res](const DumpCatchErrInfo &errInfo) { return errInfo.code == res; });
64     return iter != std::end(ERROR_CODE_MAPS) ? iter->info : "invalid error code";
65 }
66 } // namespace HiviewDFX
67 } // namespace OHOS
68