[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / Breakpoint / WatchpointOptions.cpp
blob026bf2f746aef7efc3b6a4c6466529cba6845352
1 //===-- WatchpointOptions.cpp -----------------------------------*- 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 //===----------------------------------------------------------------------===//
9 #include "lldb/Breakpoint/WatchpointOptions.h"
11 #include "lldb/Breakpoint/StoppointCallbackContext.h"
12 #include "lldb/Core/Value.h"
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Target/ThreadSpec.h"
16 #include "lldb/Utility/Stream.h"
17 #include "lldb/Utility/StringList.h"
19 using namespace lldb;
20 using namespace lldb_private;
22 bool WatchpointOptions::NullCallback(void *baton,
23 StoppointCallbackContext *context,
24 lldb::user_id_t watch_id) {
25 return true;
28 // WatchpointOptions constructor
29 WatchpointOptions::WatchpointOptions()
30 : m_callback(WatchpointOptions::NullCallback), m_callback_baton_sp(),
31 m_callback_is_synchronous(false), m_thread_spec_up() {}
33 // WatchpointOptions copy constructor
34 WatchpointOptions::WatchpointOptions(const WatchpointOptions &rhs)
35 : m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
36 m_callback_is_synchronous(rhs.m_callback_is_synchronous),
37 m_thread_spec_up() {
38 if (rhs.m_thread_spec_up != nullptr)
39 m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
42 // WatchpointOptions assignment operator
43 const WatchpointOptions &WatchpointOptions::
44 operator=(const WatchpointOptions &rhs) {
45 m_callback = rhs.m_callback;
46 m_callback_baton_sp = rhs.m_callback_baton_sp;
47 m_callback_is_synchronous = rhs.m_callback_is_synchronous;
48 if (rhs.m_thread_spec_up != nullptr)
49 m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
50 return *this;
53 WatchpointOptions *
54 WatchpointOptions::CopyOptionsNoCallback(WatchpointOptions &orig) {
55 WatchpointHitCallback orig_callback = orig.m_callback;
56 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
57 bool orig_is_sync = orig.m_callback_is_synchronous;
59 orig.ClearCallback();
60 WatchpointOptions *ret_val = new WatchpointOptions(orig);
62 orig.SetCallback(orig_callback, orig_callback_baton_sp, orig_is_sync);
64 return ret_val;
67 // Destructor
68 WatchpointOptions::~WatchpointOptions() = default;
70 // Callbacks
71 void WatchpointOptions::SetCallback(WatchpointHitCallback callback,
72 const BatonSP &callback_baton_sp,
73 bool callback_is_synchronous) {
74 m_callback_is_synchronous = callback_is_synchronous;
75 m_callback = callback;
76 m_callback_baton_sp = callback_baton_sp;
79 void WatchpointOptions::ClearCallback() {
80 m_callback = WatchpointOptions::NullCallback;
81 m_callback_is_synchronous = false;
82 m_callback_baton_sp.reset();
85 Baton *WatchpointOptions::GetBaton() { return m_callback_baton_sp.get(); }
87 const Baton *WatchpointOptions::GetBaton() const {
88 return m_callback_baton_sp.get();
91 bool WatchpointOptions::InvokeCallback(StoppointCallbackContext *context,
92 lldb::user_id_t watch_id) {
93 if (m_callback && context->is_synchronous == IsCallbackSynchronous()) {
94 return m_callback(m_callback_baton_sp ? m_callback_baton_sp->data()
95 : nullptr,
96 context, watch_id);
97 } else
98 return true;
101 bool WatchpointOptions::HasCallback() {
102 return m_callback != WatchpointOptions::NullCallback;
105 const ThreadSpec *WatchpointOptions::GetThreadSpecNoCreate() const {
106 return m_thread_spec_up.get();
109 ThreadSpec *WatchpointOptions::GetThreadSpec() {
110 if (m_thread_spec_up == nullptr)
111 m_thread_spec_up.reset(new ThreadSpec());
113 return m_thread_spec_up.get();
116 void WatchpointOptions::SetThreadID(lldb::tid_t thread_id) {
117 GetThreadSpec()->SetTID(thread_id);
120 void WatchpointOptions::GetCallbackDescription(
121 Stream *s, lldb::DescriptionLevel level) const {
122 if (m_callback_baton_sp.get()) {
123 s->EOL();
124 m_callback_baton_sp->GetDescription(s->AsRawOstream(), level,
125 s->GetIndentLevel());
129 void WatchpointOptions::GetDescription(Stream *s,
130 lldb::DescriptionLevel level) const {
131 // Figure out if there are any options not at their default value, and only
132 // print anything if there are:
134 if ((GetThreadSpecNoCreate() != nullptr &&
135 GetThreadSpecNoCreate()->HasSpecification())) {
136 if (level == lldb::eDescriptionLevelVerbose) {
137 s->EOL();
138 s->IndentMore();
139 s->Indent();
140 s->PutCString("Watchpoint Options:\n");
141 s->IndentMore();
142 s->Indent();
143 } else
144 s->PutCString(" Options: ");
146 if (m_thread_spec_up)
147 m_thread_spec_up->GetDescription(s, level);
148 else if (level == eDescriptionLevelBrief)
149 s->PutCString("thread spec: no ");
150 if (level == lldb::eDescriptionLevelFull) {
151 s->IndentLess();
152 s->IndentMore();
156 GetCallbackDescription(s, level);
159 void WatchpointOptions::CommandBaton::GetDescription(
160 llvm::raw_ostream &s, lldb::DescriptionLevel level,
161 unsigned indentation) const {
162 const CommandData *data = getItem();
164 if (level == eDescriptionLevelBrief) {
165 s << ", commands = %s"
166 << ((data && data->user_source.GetSize() > 0) ? "yes" : "no");
167 return;
170 indentation += 2;
171 s.indent(indentation);
172 s << "watchpoint commands:\n";
174 indentation += 2;
175 if (data && data->user_source.GetSize() > 0) {
176 for (const std::string &line : data->user_source) {
177 s.indent(indentation);
178 s << line << "\n";
180 } else
181 s << "No commands.\n";