LLDB mainline
WatchpointOptions.cpp
Go to the documentation of this file.
1//===-- WatchpointOptions.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
10
12#include "lldb/Core/Value.h"
13#include "lldb/Target/Process.h"
14#include "lldb/Target/Target.h"
16#include "lldb/Utility/Stream.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
24 lldb::user_id_t watch_id) {
25 return true;
26}
27
28// WatchpointOptions constructor
30 : m_callback(WatchpointOptions::NullCallback) {}
31
32// WatchpointOptions copy constructor
34 : m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
35 m_callback_is_synchronous(rhs.m_callback_is_synchronous) {
36 if (rhs.m_thread_spec_up != nullptr)
37 m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
38}
39
40// WatchpointOptions assignment operator
42operator=(const WatchpointOptions &rhs) {
46 if (rhs.m_thread_spec_up != nullptr)
47 m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
48 return *this;
49}
50
53 WatchpointHitCallback orig_callback = orig.m_callback;
54 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
55 bool orig_is_sync = orig.m_callback_is_synchronous;
56
57 orig.ClearCallback();
58 WatchpointOptions *ret_val = new WatchpointOptions(orig);
59
60 orig.SetCallback(orig_callback, orig_callback_baton_sp, orig_is_sync);
61
62 return ret_val;
63}
64
65// Destructor
67
68// Callbacks
70 const BatonSP &callback_baton_sp,
71 bool callback_is_synchronous) {
72 m_callback_is_synchronous = callback_is_synchronous;
73 m_callback = callback;
74 m_callback_baton_sp = callback_baton_sp;
75}
76
80 m_callback_baton_sp.reset();
81}
82
84
86 return m_callback_baton_sp.get();
87}
88
90 lldb::user_id_t watch_id) {
91 if (m_callback && context->is_synchronous == IsCallbackSynchronous()) {
93 : nullptr,
94 context, watch_id);
95 } else
96 return true;
97}
98
101}
102
104 return m_thread_spec_up.get();
105}
106
108 if (m_thread_spec_up == nullptr)
109 m_thread_spec_up = std::make_unique<ThreadSpec>();
110
111 return m_thread_spec_up.get();
112}
113
115 GetThreadSpec()->SetTID(thread_id);
116}
117
119 Stream *s, lldb::DescriptionLevel level) const {
120 if (m_callback_baton_sp.get()) {
121 s->EOL();
122 m_callback_baton_sp->GetDescription(s->AsRawOstream(), level,
123 s->GetIndentLevel());
124 }
125}
126
128 lldb::DescriptionLevel level) const {
129 // Figure out if there are any options not at their default value, and only
130 // print anything if there are:
131
132 if ((GetThreadSpecNoCreate() != nullptr &&
133 GetThreadSpecNoCreate()->HasSpecification())) {
134 if (level == lldb::eDescriptionLevelVerbose) {
135 s->EOL();
136 s->IndentMore();
137 s->Indent();
138 s->PutCString("Watchpoint Options:\n");
139 s->IndentMore();
140 s->Indent();
141 } else
142 s->PutCString(" Options: ");
143
145 m_thread_spec_up->GetDescription(s, level);
146 else if (level == eDescriptionLevelBrief)
147 s->PutCString("thread spec: no ");
148 if (level == lldb::eDescriptionLevelFull) {
149 s->IndentLess();
150 s->IndentMore();
151 }
152 }
153
154 GetCallbackDescription(s, level);
155}
156
158 llvm::raw_ostream &s, lldb::DescriptionLevel level,
159 unsigned indentation) const {
160 const CommandData *data = getItem();
161
162 if (level == eDescriptionLevelBrief) {
163 s << ", commands = %s"
164 << ((data && data->user_source.GetSize() > 0) ? "yes" : "no");
165 return;
166 }
167
168 indentation += 2;
169 s.indent(indentation);
170 s << "watchpoint commands:\n";
171
172 indentation += 2;
173 if (data && data->user_source.GetSize() > 0) {
174 for (const std::string &line : data->user_source) {
175 s.indent(indentation);
176 s << line << "\n";
177 }
178 } else
179 s << "No commands.\n";
180}
A class designed to wrap callback batons so they can cleanup any acquired resources.
Definition: Baton.h:35
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:157
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:195
unsigned GetIndentLevel() const
Get the current indentation level.
Definition: Stream.cpp:187
void SetTID(lldb::tid_t tid)
Definition: ThreadSpec.h:47
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level, unsigned indentation) const override
"lldb/Breakpoint/WatchpointOptions.h" Class that manages the options on a watchpoint.
const WatchpointOptions & operator=(const WatchpointOptions &rhs)
static WatchpointOptions * CopyOptionsNoCallback(WatchpointOptions &rhs)
void SetThreadID(lldb::tid_t thread_id)
void ClearCallback()
Remove the callback from this option set.
bool HasCallback()
Returns true if the watchpoint option has a callback set.
std::unique_ptr< ThreadSpec > m_thread_spec_up
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
static bool NullCallback(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
This is the default empty callback.
bool InvokeCallback(StoppointCallbackContext *context, lldb::user_id_t watch_id)
Use this function to invoke the callback for a specific stop.
void SetCallback(WatchpointHitCallback callback, const lldb::BatonSP &baton_sp, bool synchronous=false)
Adds a callback to the watchpoint option set.
WatchpointHitCallback m_callback
void GetCallbackDescription(Stream *s, lldb::DescriptionLevel level) const
Get description for callback only.
WatchpointOptions()
Default constructor.
const ThreadSpec * GetThreadSpecNoCreate() const
Return the current thread spec for this option.
bool IsCallbackSynchronous()
Used in InvokeCallback to tell whether it is the right time to run this kind of callback.
Baton * GetBaton()
Fetch the baton from the callback.
ThreadSpec * GetThreadSpec()
Returns a pointer to the ThreadSpec for this option, creating it if it hasn't been created already.
A class that represents a running process on the host machine.
bool(* WatchpointHitCallback)(void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::Baton > BatonSP
Definition: lldb-forward.h:317
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t tid_t
Definition: lldb-types.h:84