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_DWARF_INSTRUCTIONS_H
17#define DFX_DWARF_INSTRUCTIONS_H
18
19#include <cinttypes>
20#include <memory>
21#include <stack>
22#include "dwarf_define.h"
23#include "dfx_memory.h"
24#include "dfx_regs.h"
25#include "unwind_context.h"
26
27namespace OHOS {
28namespace HiviewDFX {
29class DwarfCfaInstructions {
30public:
31    DwarfCfaInstructions(std::shared_ptr<DfxMemory> memory) : memory_(memory) {};
32    virtual ~DwarfCfaInstructions() = default;
33
34    bool Parse(uintptr_t pc, FrameDescEntry fde, RegLocState& rsState);
35
36private:
37    bool Iterate(uintptr_t pc, FrameDescEntry fde, uintptr_t instStart, uintptr_t instEnd, RegLocState &rsState);
38    bool DecodeDwCfa(uint8_t op, CommonInfoEntry cie, uintptr_t& pcOffset, uintptr_t& instPtr, RegLocState &rsState);
39
40private:
41    std::shared_ptr<DfxMemory> memory_;
42    RegLocState backupRsState_;
43    std::stack<RegLocState> saveRsStates_;
44};
45} // nameapace HiviewDFX
46} // nameapace OHOS
47#endif
48