• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef DFX_ACCESSORS_H
17 #define DFX_ACCESSORS_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include "dfx_define.h"
24 #include "unwind_context.h"
25 
26 #if is_mingw
27 #ifndef UNWIND_BYTE_ORDER
28 #define UNWIND_BYTE_ORDER -1 // unknown
29 #endif
30 #endif
31 
32 namespace OHOS {
33 namespace HiviewDFX {
34 class DfxAccessors {
35 public:
bigEndian_(bigEndian)36     DfxAccessors(int bigEndian = UNWIND_BYTE_ORDER) : bigEndian_(bigEndian) {}
37     virtual ~DfxAccessors() = default;
38 
39     virtual int AccessMem(uintptr_t addr, uintptr_t *val, void *arg) = 0;
40     virtual int AccessReg(int regIdx, uintptr_t *val, void *arg) = 0;
41     virtual int FindUnwindTable(uintptr_t pc, UnwindTableInfo& uti, void *arg) = 0;
42 
43     int bigEndian_ = UNWIND_BYTE_ORDER;
44 };
45 
46 class DfxAccessorsLocal : public DfxAccessors {
47 public:
48     DfxAccessorsLocal() = default;
49     virtual ~DfxAccessorsLocal() = default;
50     static bool IsValidFrame(uintptr_t addr, uintptr_t stackBottom, uintptr_t stackTop);
51 
52     int AccessMem(uintptr_t addr, uintptr_t *val, void *arg) override;
53     int AccessReg(int regIdx, uintptr_t *val, void *arg) override;
54     int FindUnwindTable(uintptr_t pc, UnwindTableInfo& uti, void *arg) override;
55 };
56 
57 class DfxAccessorsRemote : public DfxAccessors {
58 public:
59     DfxAccessorsRemote() = default;
60     virtual ~DfxAccessorsRemote() = default;
61 
62     int AccessMem(uintptr_t addr, uintptr_t *val, void *arg) override;
63     int AccessReg(int regIdx, uintptr_t *val, void *arg) override;
64     int FindUnwindTable(uintptr_t pc, UnwindTableInfo& uti, void *arg) override;
65 };
66 
67 class DfxAccessorsCustomize : public DfxAccessors {
68 public:
DfxAccessorsCustomize(std::shared_ptr<UnwindAccessors> accessors)69     DfxAccessorsCustomize(std::shared_ptr<UnwindAccessors> accessors) : accessors_(accessors) {}
70     virtual ~DfxAccessorsCustomize() = default;
71 
72     int AccessMem(uintptr_t addr, uintptr_t *val, void *arg) override;
73     int AccessReg(int regIdx, uintptr_t *val, void *arg) override;
74     int FindUnwindTable(uintptr_t pc, UnwindTableInfo& uti, void *arg) override;
75 private:
76     std::shared_ptr<UnwindAccessors> accessors_;
77 };
78 } // namespace HiviewDFX
79 } // namespace OHOS
80 #endif
81