• 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 #ifndef FP_UNWINDER_H
16 #define FP_UNWINDER_H
17 
18 #include <memory>
19 #include <vector>
20 #include <link.h>
21 #include <unistd.h>
22 #include <libunwind.h>
23 #include "dfx_frame.h"
24 #include "dfx_regs.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class FpUnwinder {
29 public:
30     FpUnwinder();
31     ~FpUnwinder();
32 
33     bool UnwindWithContext(unw_context_t& context, size_t skipFrameNum);
34     bool Unwind(size_t skipFrameNum);
35     bool Unwind(const std::shared_ptr<DfxRegs> &dfxregs, size_t skipFrameNum);
36 
37     void UpdateFrameInfo();
38     const std::vector<DfxFrame>& GetFrames() const;
39 private:
40     bool Step(uintptr_t& fp, uintptr_t& pc);
IsValidFrame(uintptr_t frame,uintptr_t stackTop,uintptr_t stackBottom)41     inline bool IsValidFrame(uintptr_t frame, uintptr_t stackTop, uintptr_t stackBottom)
42     {
43         return ((frame > stackBottom) && (frame < stackTop - sizeof(uintptr_t)));
44     }
45     static int DlIteratePhdrCallback(struct dl_phdr_info *info, size_t size, void *data);
46 
47 private:
48     std::vector<DfxFrame> frames_;
49     uintptr_t stackBottom_;
50     uintptr_t stackTop_;
51 };
52 } // namespace HiviewDFX
53 } // namespace OHOS
54 #endif
55