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 DFX_REGS_QUT_H
16  #define DFX_REGS_QUT_H
17  
18  #include <cstdint>
19  #include <vector>
20  #include "unwind_define.h"
21  
22  namespace OHOS {
23  namespace HiviewDFX {
24  class DfxRegsQut {
25  public:
SetQutRegs(const std::vector<uint16_t> & qutRegs)26      static inline void SetQutRegs(const std::vector<uint16_t>& qutRegs)
27      {
28          qutRegs_ = qutRegs;
29      }
30  
GetQutRegs()31      static inline const std::vector<uint16_t>& GetQutRegs()
32      {
33          if (!qutRegs_.empty()) {
34              return qutRegs_;
35          }
36          return QUT_REGS;
37      }
38  
GetQutRegsSize()39      static inline size_t GetQutRegsSize()
40      {
41          return GetQutRegs().size();
42      }
43  
IsQutReg(uint16_t reg,size_t & qutIdx)44      static inline bool IsQutReg(uint16_t reg, size_t& qutIdx)
45      {
46          const std::vector<uint16_t>& qutRegs = GetQutRegs();
47          for (size_t i = 0; i < qutRegs.size(); ++i) {
48              if (qutRegs[i] == reg) {
49                  qutIdx = i;
50                  return true;
51              }
52          }
53          return false;
54      }
55  
56  protected:
57      static std::vector<uint16_t> qutRegs_;
58  };
59  } // namespace HiviewDFX
60  } // namespace OHOS
61  #endif
62