1 //===-- WatchpointOptions.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/Breakpoint/WatchpointOptions.h"
16 #include "lldb/Core/Stream.h"
17 #include "lldb/Core/StringList.h"
18 #include "lldb/Core/Value.h"
19 #include "lldb/Breakpoint/StoppointCallbackContext.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/Target/ThreadSpec.h"
25 using namespace lldb_private;
28 WatchpointOptions::NullCallback (void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
33 //----------------------------------------------------------------------
34 // WatchpointOptions constructor
35 //----------------------------------------------------------------------
36 WatchpointOptions::WatchpointOptions() :
37 m_callback (WatchpointOptions::NullCallback),
38 m_callback_baton_sp (),
39 m_callback_is_synchronous (false),
44 //----------------------------------------------------------------------
45 // WatchpointOptions copy constructor
46 //----------------------------------------------------------------------
47 WatchpointOptions::WatchpointOptions(const WatchpointOptions& rhs) :
48 m_callback (rhs.m_callback),
49 m_callback_baton_sp (rhs.m_callback_baton_sp),
50 m_callback_is_synchronous (rhs.m_callback_is_synchronous),
53 if (rhs.m_thread_spec_ap.get() != nullptr)
54 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
57 //----------------------------------------------------------------------
58 // WatchpointOptions assignment operator
59 //----------------------------------------------------------------------
60 const WatchpointOptions&
61 WatchpointOptions::operator=(const WatchpointOptions& rhs)
63 m_callback = rhs.m_callback;
64 m_callback_baton_sp = rhs.m_callback_baton_sp;
65 m_callback_is_synchronous = rhs.m_callback_is_synchronous;
66 if (rhs.m_thread_spec_ap.get() != nullptr)
67 m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get()));
72 WatchpointOptions::CopyOptionsNoCallback (WatchpointOptions &orig)
74 WatchpointHitCallback orig_callback = orig.m_callback;
75 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
76 bool orig_is_sync = orig.m_callback_is_synchronous;
79 WatchpointOptions *ret_val = new WatchpointOptions(orig);
81 orig.SetCallback (orig_callback, orig_callback_baton_sp, orig_is_sync);
86 //----------------------------------------------------------------------
88 //----------------------------------------------------------------------
89 WatchpointOptions::~WatchpointOptions() = default;
91 //------------------------------------------------------------------
93 //------------------------------------------------------------------
95 WatchpointOptions::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
97 m_callback_is_synchronous = callback_is_synchronous;
98 m_callback = callback;
99 m_callback_baton_sp = callback_baton_sp;
103 WatchpointOptions::ClearCallback ()
105 m_callback = WatchpointOptions::NullCallback;
106 m_callback_is_synchronous = false;
107 m_callback_baton_sp.reset();
111 WatchpointOptions::GetBaton ()
113 return m_callback_baton_sp.get();
117 WatchpointOptions::GetBaton () const
119 return m_callback_baton_sp.get();
123 WatchpointOptions::InvokeCallback (StoppointCallbackContext *context,
124 lldb::user_id_t watch_id)
126 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
128 return m_callback(m_callback_baton_sp ? m_callback_baton_sp->m_data : nullptr,
137 WatchpointOptions::HasCallback ()
139 return m_callback != WatchpointOptions::NullCallback;
143 WatchpointOptions::GetThreadSpecNoCreate () const
145 return m_thread_spec_ap.get();
149 WatchpointOptions::GetThreadSpec ()
151 if (m_thread_spec_ap.get() == nullptr)
152 m_thread_spec_ap.reset (new ThreadSpec());
154 return m_thread_spec_ap.get();
158 WatchpointOptions::SetThreadID (lldb::tid_t thread_id)
160 GetThreadSpec()->SetTID(thread_id);
164 WatchpointOptions::GetCallbackDescription (Stream *s, lldb::DescriptionLevel level) const
166 if (m_callback_baton_sp.get())
169 m_callback_baton_sp->GetDescription (s, level);
174 WatchpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const
176 // Figure out if there are any options not at their default value, and only print
177 // anything if there are:
179 if ((GetThreadSpecNoCreate() != nullptr && GetThreadSpecNoCreate()->HasSpecification ()))
181 if (level == lldb::eDescriptionLevelVerbose)
186 s->PutCString("Watchpoint Options:\n");
191 s->PutCString(" Options: ");
193 if (m_thread_spec_ap.get())
194 m_thread_spec_ap->GetDescription (s, level);
195 else if (level == eDescriptionLevelBrief)
196 s->PutCString ("thread spec: no ");
197 if (level == lldb::eDescriptionLevelFull)
204 GetCallbackDescription(s, level);
208 WatchpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
210 CommandData *data = (CommandData *)m_data;
212 if (level == eDescriptionLevelBrief)
214 s->Printf (", commands = %s", (data && data->user_source.GetSize() > 0) ? "yes" : "no");
219 s->Indent("watchpoint commands:\n");
222 if (data && data->user_source.GetSize() > 0)
224 const size_t num_strings = data->user_source.GetSize();
225 for (size_t i = 0; i < num_strings; ++i)
227 s->Indent(data->user_source.GetStringAtIndex(i));
233 s->PutCString ("No commands.\n");