• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_FAULT_STACK_H
16 #define DFX_FAULT_STACK_H
17 
18 #include <memory>
19 #include <vector>
20 #include "dfx_frame.h"
21 #include "dfx_regs.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 struct MemoryBlockInfo {
26     uintptr_t startAddr;
27     uintptr_t nameAddr;
28     uintptr_t size;
29     std::vector<uintptr_t> content;
30     std::string name;
31 };
32 
33 // Only print first three frame stack
34 class FaultStack {
35 public:
FaultStack(int32_t tid)36     explicit FaultStack(int32_t tid) : tid_(tid) {};
37     ~FaultStack() = default;
38 
39     bool CollectStackInfo(std::shared_ptr<DfxRegs> reg, const std::vector<std::shared_ptr<DfxFrame>> &frames);
40     void Print() const;
41 
42 private:
43     bool ReadTargetMemory(uintptr_t addr, uintptr_t &value) const;
44     uintptr_t AdjustAndCreateMemoryBlock(size_t index, uintptr_t prevSp, uintptr_t prevEndAddr, uintptr_t size);
45     uintptr_t PrintMemoryBlock(const MemoryBlockInfo& info) const;
46     void CreateMemoryBlock(uintptr_t addr, uintptr_t offset, uintptr_t size, std::string name);
47 
48 private:
49     int32_t tid_;
50     std::vector<MemoryBlockInfo> blocks_;
51 };
52 } // namespace HiviewDFX
53 } // namespace OHOS
54 #endif
55