Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Target/Unwind.h
Line
Count
Source (jump to first uncovered line)
1
//===-- Unwind.h ------------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_TARGET_UNWIND_H
10
#define LLDB_TARGET_UNWIND_H
11
12
#include <mutex>
13
14
#include "lldb/lldb-private.h"
15
16
namespace lldb_private {
17
18
class Unwind {
19
protected:
20
  // Classes that inherit from Unwind can see and modify these
21
2.76k
  Unwind(Thread &thread) : m_thread(thread) {}
22
23
public:
24
2.76k
  virtual ~Unwind() = default;
25
26
22.0k
  void Clear() {
27
22.0k
    std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
28
22.0k
    DoClear();
29
22.0k
  }
30
31
0
  uint32_t GetFrameCount() {
32
0
    std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
33
0
    return DoGetFrameCount();
34
0
  }
35
36
0
  uint32_t GetFramesUpTo(uint32_t end_idx) {
37
0
    lldb::addr_t cfa;
38
0
    lldb::addr_t pc;
39
0
    uint32_t idx;
40
0
    bool behaves_like_zeroth_frame = (end_idx == 0);
41
42
0
    for (idx = 0; idx < end_idx; idx++) {
43
0
      if (!DoGetFrameInfoAtIndex(idx, cfa, pc, behaves_like_zeroth_frame)) {
44
0
        break;
45
0
      }
46
0
    }
47
0
    return idx;
48
0
  }
49
50
  bool GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
51
201k
                           lldb::addr_t &pc, bool &behaves_like_zeroth_frame) {
52
201k
    std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
53
201k
    return DoGetFrameInfoAtIndex(frame_idx, cfa, pc, behaves_like_zeroth_frame);
54
201k
  }
55
56
181k
  lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) {
57
181k
    std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex);
58
181k
    return DoCreateRegisterContextForFrame(frame);
59
181k
  }
60
61
0
  Thread &GetThread() { return m_thread; }
62
63
protected:
64
  // Classes that inherit from Unwind can see and modify these
65
  virtual void DoClear() = 0;
66
67
  virtual uint32_t DoGetFrameCount() = 0;
68
69
  virtual bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
70
                                     lldb::addr_t &pc,
71
                                     bool &behaves_like_zeroth_frame) = 0;
72
73
  virtual lldb::RegisterContextSP
74
  DoCreateRegisterContextForFrame(StackFrame *frame) = 0;
75
76
  Thread &m_thread;
77
  std::recursive_mutex m_unwind_mutex;
78
79
private:
80
  Unwind(const Unwind &) = delete;
81
  const Unwind &operator=(const Unwind &) = delete;
82
};
83
84
} // namespace lldb_private
85
86
#endif // LLDB_TARGET_UNWIND_H