• 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 #ifndef DFX_REGS_H
16 #define DFX_REGS_H
17 
18 #include <cstdint>
19 #include <string>
20 #include <sys/types.h>
21 #include <ucontext.h>
22 #include <vector>
23 #include "dfx_define.h"
24 #include "dfx_util.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class DfxRegs {
29 public:
30     DfxRegs() = default;
~DfxRegs()31     virtual ~DfxRegs() {};
GetRegsData()32     std::vector<uintptr_t> GetRegsData() const
33     {
34         return regsData_;
35     }
36     virtual std::string PrintRegs() const = 0;
37     virtual std::string GetSpecialRegisterName(uintptr_t val) const = 0;
38     virtual uintptr_t GetPC() const = 0;
39     virtual uintptr_t GetLR() const = 0;
SetRegs(const std::vector<uintptr_t> & regs)40     void SetRegs(const std::vector<uintptr_t>& regs)
41     {
42         regsData_ = regs;
43     }
44 protected:
45     std::vector<uintptr_t> regsData_ {};
46 };
47 
48 class DfxRegsArm : public DfxRegs {
49 public:
50     explicit DfxRegsArm(const ucontext_t &context);
~DfxRegsArm()51     ~DfxRegsArm() override {};
52     std::string PrintRegs() const override;
53     std::string GetSpecialRegisterName(uintptr_t val) const override;
54     uintptr_t GetPC() const override;
55     uintptr_t GetLR() const override;
56 private:
57     DfxRegsArm() = delete;
58 };
59 
60 class DfxRegsArm64 : public DfxRegs {
61 public:
62     explicit DfxRegsArm64(const ucontext_t &context);
~DfxRegsArm64()63     ~DfxRegsArm64() override {};
64     std::string PrintRegs() const override;
65     std::string GetSpecialRegisterName(uintptr_t val) const override;
66     uintptr_t GetPC() const override;
67     uintptr_t GetLR() const override;
68 private:
69     DfxRegsArm64() = delete;
70 };
71 
72 class DfxRegsX86_64 : public DfxRegs {
73 public:
74     explicit DfxRegsX86_64(const ucontext_t &context);
~DfxRegsX86_64()75     ~DfxRegsX86_64() override {};
76     std::string PrintRegs() const override;
77     std::string GetSpecialRegisterName(uintptr_t val) const override;
78     uintptr_t GetPC() const override;
79     uintptr_t GetLR() const override;
80 private:
81     DfxRegsX86_64() = delete;
82 };
83 } // namespace HiviewDFX
84 } // namespace OHOS
85 #endif
86