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 //===----------------------------------------------------------------------===//
10 #include "lldb/Breakpoint/WatchpointOptions.h"
14 // Other libraries and framework includes
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"
23 #include "lldb/Expression/ClangUserExpression.h"
26 using namespace lldb_private;
29 WatchpointOptions::NullCallback (void *baton, StoppointCallbackContext *context, lldb::user_id_t watch_id)
34 //----------------------------------------------------------------------
35 // WatchpointOptions constructor
36 //----------------------------------------------------------------------
37 WatchpointOptions::WatchpointOptions() :
38 m_callback (WatchpointOptions::NullCallback),
39 m_callback_baton_sp (),
40 m_callback_is_synchronous (false),
45 //----------------------------------------------------------------------
46 // WatchpointOptions copy constructor
47 //----------------------------------------------------------------------
48 WatchpointOptions::WatchpointOptions(const WatchpointOptions& rhs) :
49 m_callback (rhs.m_callback),
50 m_callback_baton_sp (rhs.m_callback_baton_sp),
51 m_callback_is_synchronous (rhs.m_callback_is_synchronous),
54 if (rhs.m_thread_spec_ap.get() != NULL)
55 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
58 //----------------------------------------------------------------------
59 // WatchpointOptions assignment operator
60 //----------------------------------------------------------------------
61 const WatchpointOptions&
62 WatchpointOptions::operator=(const WatchpointOptions& rhs)
64 m_callback = rhs.m_callback;
65 m_callback_baton_sp = rhs.m_callback_baton_sp;
66 m_callback_is_synchronous = rhs.m_callback_is_synchronous;
67 if (rhs.m_thread_spec_ap.get() != NULL)
68 m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get()));
73 WatchpointOptions::CopyOptionsNoCallback (WatchpointOptions &orig)
75 WatchpointHitCallback orig_callback = orig.m_callback;
76 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
77 bool orig_is_sync = orig.m_callback_is_synchronous;
80 WatchpointOptions *ret_val = new WatchpointOptions(orig);
82 orig.SetCallback (orig_callback, orig_callback_baton_sp, orig_is_sync);
87 //----------------------------------------------------------------------
89 //----------------------------------------------------------------------
90 WatchpointOptions::~WatchpointOptions()
94 //------------------------------------------------------------------
96 //------------------------------------------------------------------
98 WatchpointOptions::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
100 m_callback_is_synchronous = callback_is_synchronous;
101 m_callback = callback;
102 m_callback_baton_sp = callback_baton_sp;
106 WatchpointOptions::ClearCallback ()
108 m_callback = WatchpointOptions::NullCallback;
109 m_callback_is_synchronous = false;
110 m_callback_baton_sp.reset();
114 WatchpointOptions::GetBaton ()
116 return m_callback_baton_sp.get();
120 WatchpointOptions::GetBaton () const
122 return m_callback_baton_sp.get();
126 WatchpointOptions::InvokeCallback (StoppointCallbackContext *context,
127 lldb::user_id_t watch_id)
129 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
131 return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL,
140 WatchpointOptions::HasCallback ()
142 return m_callback != WatchpointOptions::NullCallback;
146 WatchpointOptions::GetThreadSpecNoCreate () const
148 return m_thread_spec_ap.get();
152 WatchpointOptions::GetThreadSpec ()
154 if (m_thread_spec_ap.get() == NULL)
155 m_thread_spec_ap.reset (new ThreadSpec());
157 return m_thread_spec_ap.get();
161 WatchpointOptions::SetThreadID (lldb::tid_t thread_id)
163 GetThreadSpec()->SetTID(thread_id);
167 WatchpointOptions::GetCallbackDescription (Stream *s, lldb::DescriptionLevel level) const
169 if (m_callback_baton_sp.get())
172 m_callback_baton_sp->GetDescription (s, level);
176 WatchpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const
179 // Figure out if there are any options not at their default value, and only print
180 // anything if there are:
182 if ((GetThreadSpecNoCreate() != NULL && GetThreadSpecNoCreate()->HasSpecification ()))
184 if (level == lldb::eDescriptionLevelVerbose)
189 s->PutCString("Watchpoint Options:\n");
194 s->PutCString(" Options: ");
196 if (m_thread_spec_ap.get())
197 m_thread_spec_ap->GetDescription (s, level);
198 else if (level == eDescriptionLevelBrief)
199 s->PutCString ("thread spec: no ");
200 if (level == lldb::eDescriptionLevelFull)
207 GetCallbackDescription(s, level);
211 WatchpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
213 CommandData *data = (CommandData *)m_data;
215 if (level == eDescriptionLevelBrief)
217 s->Printf (", commands = %s", (data && data->user_source.GetSize() > 0) ? "yes" : "no");
222 s->Indent("watchpoint commands:\n");
225 if (data && data->user_source.GetSize() > 0)
227 const size_t num_strings = data->user_source.GetSize();
228 for (size_t i = 0; i < num_strings; ++i)
230 s->Indent(data->user_source.GetStringAtIndex(i));
236 s->PutCString ("No commands.\n");