• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "dfx_dump_res.h"
16 
17 #include <sstream>
18 #include <string>
19 #include "ostream"
20 
21 namespace OHOS {
22 namespace HiviewDFX {
GetInstance()23 DfxDumpRes &DfxDumpRes::GetInstance()
24 {
25     static DfxDumpRes ins;
26     return ins;
27 }
28 
SetRes(int32_t res)29 void DfxDumpRes::SetRes(int32_t res)
30 {
31     resMsg_.res = res;
32 }
33 
GetRes() const34 int32_t DfxDumpRes::GetRes() const
35 {
36     return resMsg_.res;
37 }
38 
GetResStr(const int res) const39 const char* DfxDumpRes::GetResStr(const int res) const
40 {
41     const char *cp;
42     switch (res) {
43         case DUMP_ESUCCESS:     cp = "no error"; break;
44         case DUMP_EREADREQUEST: cp = "read dump request error"; break;
45         case DUMP_EGETPPID:     cp = "ppid is crashed before unwind"; break;
46         case DUMP_EATTACH:      cp = "ptrace attach thread failed"; break;
47         case DUMP_EGETFD:       cp = "get fd error"; break;
48         case DUMP_ENOMEM:       cp = "out of memory"; break;
49         case DUMP_EBADREG:      cp = "bad register number"; break;
50         case DUMP_EREADONLYREG: cp = "attempt to write read-only register"; break;
51         case DUMP_ESTOPUNWIND:  cp = "stop unwinding"; break;
52         case DUMP_EINVALIDIP:   cp = "invalid IP"; break;
53         case DUMP_EBADFRAME:    cp = "bad frame"; break;
54         case DUMP_EINVAL:       cp = "unsupported operation or bad value"; break;
55         case DUMP_EBADVERSION:  cp = "unwind info has unsupported version"; break;
56         case DUMP_ENOINFO:      cp = "no unwind info found"; break;
57         default:                cp = "invalid error code"; break;
58     }
59     return cp;
60 }
61 
ToString() const62 std::string DfxDumpRes::ToString() const
63 {
64     std::stringstream ss;
65     ss << std::to_string(resMsg_.res) << " ( " << GetResStr(resMsg_.res) << " )";
66     return ss.str();
67 }
68 } // namespace HiviewDFX
69 } // namespace OHOS