Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:56

0001 //===-- Unwind.h ------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_UNWIND_H
0010 #define LLDB_TARGET_UNWIND_H
0011 
0012 #include <mutex>
0013 
0014 #include "lldb/lldb-private.h"
0015 
0016 namespace lldb_private {
0017 
0018 class Unwind {
0019 protected:
0020   // Classes that inherit from Unwind can see and modify these
0021   Unwind(Thread &thread) : m_thread(thread) {}
0022 
0023 public:
0024   virtual ~Unwind() = default;
0025 
0026   void Clear() {
0027     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
0028     DoClear();
0029   }
0030 
0031   uint32_t GetFrameCount() {
0032     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
0033     return DoGetFrameCount();
0034   }
0035 
0036   uint32_t GetFramesUpTo(uint32_t end_idx) {
0037     lldb::addr_t cfa;
0038     lldb::addr_t pc;
0039     uint32_t idx;
0040     bool behaves_like_zeroth_frame = (end_idx == 0);
0041 
0042     for (idx = 0; idx < end_idx; idx++) {
0043       if (!DoGetFrameInfoAtIndex(idx, cfa, pc, behaves_like_zeroth_frame)) {
0044         break;
0045       }
0046     }
0047     return idx;
0048   }
0049 
0050   bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
0051                            lldb::addr_t &pc, bool &behaves_like_zeroth_frame) {
0052     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
0053     return DoGetFrameInfoAtIndex(frame_idx, cfa, pc, behaves_like_zeroth_frame);
0054   }
0055 
0056   lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) {
0057     std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
0058     return DoCreateRegisterContextForFrame(frame);
0059   }
0060 
0061   Thread &GetThread() { return m_thread; }
0062 
0063 protected:
0064   // Classes that inherit from Unwind can see and modify these
0065   virtual void DoClear() = 0;
0066 
0067   virtual uint32_t DoGetFrameCount() = 0;
0068 
0069   virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
0070                                      lldb::addr_t &pc,
0071                                      bool &behaves_like_zeroth_frame) = 0;
0072 
0073   virtual lldb::RegisterContextSP
0074   DoCreateRegisterContextForFrame(StackFrame *frame) = 0;
0075 
0076   Thread &m_thread;
0077   std::recursive_mutex m_unwind_mutex;
0078 
0079 private:
0080   Unwind(const Unwind &) = delete;
0081   const Unwind &operator=(const Unwind &) = delete;
0082 };
0083 
0084 } // namespace lldb_private
0085 
0086 #endif // LLDB_TARGET_UNWIND_H