• 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_FRAME_H
16 #define DFX_FRAME_H
17 
18 #include <string>
19 #include "dfx_maps.h"
20 #include "iosfwd"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 class DfxFrame {
25 public:
26     DfxFrame() = default;
27     ~DfxFrame() = default;
28 
29     void SetFrameIndex(size_t index);
30     size_t GetFrameIndex() const;
31     void SetFrameFuncOffset(uint64_t funcOffset);
32     uint64_t GetFrameFuncOffset() const;
33     void SetFramePc(uint64_t pc);
34     uint64_t GetFramePc() const;
35     void SetFrameLr(uint64_t lr);
36     uint64_t GetFrameLr() const;
37     void SetFrameSp(uint64_t sp);
38     uint64_t GetFrameSp() const;
39     void SetFrameRelativePc(uint64_t relativePc);
40     uint64_t GetFrameRelativePc() const;
41     void SetFrameFuncName(const std::string &funcName);
42     std::string GetFrameFuncName() const;
43     void SetFrameMap(const std::shared_ptr<DfxElfMap> map);
44     std::shared_ptr<DfxElfMap> GetFrameMap() const;
45     void SetFrameMapName(const std::string &mapName);
46     std::string GetFrameMapName() const;
47 
48     std::string ToString() const;
49     uint64_t GetRelativePc(const std::shared_ptr<DfxElfMaps> head);
50     uint64_t CalculateRelativePc(std::shared_ptr<DfxElfMap> elfMap);
51     std::string PrintFrame() const;
52 
53 private:
54     size_t index_ = 0;
55     uint64_t funcOffset_ = 0;
56     uint64_t pc_ = 0;
57     uint64_t lr_ = 0;
58     uint64_t sp_ = 0;
59     uint64_t relativePc_ = 0;
60     std::string funcName_;
61     std::string frameMapName_ = "";
62     std::shared_ptr<DfxElfMap> map_ = nullptr; // managed in DfxProcess class
63 };
64 
65 void PrintFrames(std::vector<std::shared_ptr<DfxFrame>> frames);
66 } // namespace HiviewDFX
67 } // namespace OHOS
68 
69 #endif
70