LLDB mainline
Policy.cpp
Go to the documentation of this file.
1//===-- Policy.cpp --------------------------------------------------------===//
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
11#include "lldb/Utility/Log.h"
12#include "lldb/Utility/Stream.h"
14#include "llvm/Support/ErrorHandling.h"
15
16using namespace lldb_private;
17
19 Policy p = m_stack.back();
20 if (Log *log = GetLog(LLDBLog::Process)) {
22 p.Dump(s);
23 LLDB_LOG(log, "{0}", s.GetData());
24 }
25 return p;
26}
27
28// CreatePublicState is the baseline, not a transition. The stack returns to
29// public state by popping the private-state guards, not by pushing a
30// "public" policy on top. This factory exists only as a reference value
31// (tests, dump comparisons); it never reads the current stack.
33
47
53
55 if (!m_active)
56 return;
57 if (m_thread_id != std::this_thread::get_id())
58 llvm::report_fatal_error(
59 "PolicyStack::Guard destroyed on a different thread than the one "
60 "that created it");
61 Get().Pop();
62}
63
65 : m_thread_id(other.m_thread_id), m_active(other.m_active) {
66 if (m_active && m_thread_id != std::this_thread::get_id())
67 llvm::report_fatal_error("PolicyStack::Guard moved across threads");
68 other.m_active = false;
69}
70
72 if (this != &other) {
73 if (other.m_active && other.m_thread_id != std::this_thread::get_id())
74 llvm::report_fatal_error("PolicyStack::Guard moved across threads");
75 if (m_active) {
76 if (m_thread_id != std::this_thread::get_id())
77 llvm::report_fatal_error(
78 "PolicyStack::Guard destroyed on a different thread than the "
79 "one that created it");
80 Get().Pop();
81 }
82 m_thread_id = other.m_thread_id;
83 m_active = other.m_active;
84 other.m_active = false;
85 }
86 return *this;
87}
88
89void Policy::Dump(Stream &s) const {
90 s << "policy: view=" << (view == View::Public ? "public" : "private");
91 s << ", capabilities={";
92 s << "eval_expr=" << capabilities.can_evaluate_expressions;
93 s << " run_all=" << capabilities.can_run_all_threads;
94 s << " try_all=" << capabilities.can_try_all_threads;
95 s << " bp_actions=" << capabilities.can_run_breakpoint_actions;
96 s << " frame_providers=" << capabilities.can_load_frame_providers;
97 s << " frame_recognizers=" << capabilities.can_run_frame_recognizers;
98 s << '}';
99}
100
101void PolicyStack::Dump(Stream &s) const {
102 s.Printf("PolicyStack depth=%zu\n", m_stack.size());
103 for (size_t i = 0; i < m_stack.size(); i++) {
104 s.Printf(" [%zu] ", i);
105 m_stack[i].Dump(s);
106 s << '\n';
107 }
108}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:376
RAII guard that pops a policy on destruction.
Definition Policy.h:113
std::thread::id m_thread_id
Definition Policy.h:126
Guard & operator=(Guard &&other)
Definition Policy.cpp:71
void Dump(Stream &s) const
Definition Policy.cpp:101
static PolicyStack & Get()
Definition Policy.h:98
llvm::SmallVector< Policy > m_stack
Definition Policy.h:154
Policy Current() const
Definition Policy.cpp:18
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:339
Describes what view of the process a thread should see and what operations it is allowed to perform.
Definition Policy.h:33
static Policy CreatePublicState()
Definition Policy.cpp:32
Capabilities capabilities
Definition Policy.h:66
@ Public
Provider-augmented frames, public state, public run lock.
Definition Policy.h:36
@ Private
Parent (unwinder) frames, private state, private run lock.
Definition Policy.h:37
void Dump(Stream &s) const
Definition Policy.cpp:89
PrivateStatePurpose
Why a private-state policy is being pushed.
Definition Policy.h:60
static Policy CreatePublicStateRunningExpression()
Definition Policy.cpp:48
static Policy CreatePrivateState(PrivateStatePurpose purpose=PrivateStatePurpose::Default)
Definition Policy.cpp:34