1 //===-- BreakpointOptions.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/BreakpointOptions.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 BreakpointOptions::NullCallback (void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
34 //----------------------------------------------------------------------
35 // BreakpointOptions constructor
36 //----------------------------------------------------------------------
37 BreakpointOptions::BreakpointOptions() :
38 m_callback (BreakpointOptions::NullCallback),
39 m_callback_baton_sp (),
40 m_callback_is_synchronous (false),
46 m_condition_text_hash (0)
50 //----------------------------------------------------------------------
51 // BreakpointOptions copy constructor
52 //----------------------------------------------------------------------
53 BreakpointOptions::BreakpointOptions(const BreakpointOptions& rhs) :
54 m_callback (rhs.m_callback),
55 m_callback_baton_sp (rhs.m_callback_baton_sp),
56 m_callback_is_synchronous (rhs.m_callback_is_synchronous),
57 m_enabled (rhs.m_enabled),
58 m_one_shot (rhs.m_one_shot),
59 m_ignore_count (rhs.m_ignore_count),
62 if (rhs.m_thread_spec_ap.get() != NULL)
63 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
64 m_condition_text = rhs.m_condition_text;
65 m_condition_text_hash = rhs.m_condition_text_hash;
68 //----------------------------------------------------------------------
69 // BreakpointOptions assignment operator
70 //----------------------------------------------------------------------
71 const BreakpointOptions&
72 BreakpointOptions::operator=(const BreakpointOptions& rhs)
74 m_callback = rhs.m_callback;
75 m_callback_baton_sp = rhs.m_callback_baton_sp;
76 m_callback_is_synchronous = rhs.m_callback_is_synchronous;
77 m_enabled = rhs.m_enabled;
78 m_one_shot = rhs.m_one_shot;
79 m_ignore_count = rhs.m_ignore_count;
80 if (rhs.m_thread_spec_ap.get() != NULL)
81 m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get()));
82 m_condition_text = rhs.m_condition_text;
83 m_condition_text_hash = rhs.m_condition_text_hash;
88 BreakpointOptions::CopyOptionsNoCallback (BreakpointOptions &orig)
90 BreakpointHitCallback orig_callback = orig.m_callback;
91 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
92 bool orig_is_sync = orig.m_callback_is_synchronous;
95 BreakpointOptions *ret_val = new BreakpointOptions(orig);
97 orig.SetCallback (orig_callback, orig_callback_baton_sp, orig_is_sync);
102 //----------------------------------------------------------------------
104 //----------------------------------------------------------------------
105 BreakpointOptions::~BreakpointOptions()
109 //------------------------------------------------------------------
111 //------------------------------------------------------------------
113 BreakpointOptions::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
115 m_callback_is_synchronous = callback_is_synchronous;
116 m_callback = callback;
117 m_callback_baton_sp = callback_baton_sp;
121 BreakpointOptions::ClearCallback ()
123 m_callback = BreakpointOptions::NullCallback;
124 m_callback_is_synchronous = false;
125 m_callback_baton_sp.reset();
129 BreakpointOptions::GetBaton ()
131 return m_callback_baton_sp.get();
135 BreakpointOptions::GetBaton () const
137 return m_callback_baton_sp.get();
141 BreakpointOptions::InvokeCallback (StoppointCallbackContext *context,
142 lldb::user_id_t break_id,
143 lldb::user_id_t break_loc_id)
145 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
147 return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL,
157 BreakpointOptions::HasCallback ()
159 return m_callback != BreakpointOptions::NullCallback;
163 BreakpointOptions::SetCondition (const char *condition)
168 m_condition_text.assign(condition);
169 std::hash<std::string> hasher;
170 m_condition_text_hash = hasher(m_condition_text);
174 BreakpointOptions::GetConditionText (size_t *hash) const
176 if (!m_condition_text.empty())
179 *hash = m_condition_text_hash;
181 return m_condition_text.c_str();
190 BreakpointOptions::GetThreadSpecNoCreate () const
192 return m_thread_spec_ap.get();
196 BreakpointOptions::GetThreadSpec ()
198 if (m_thread_spec_ap.get() == NULL)
199 m_thread_spec_ap.reset (new ThreadSpec());
201 return m_thread_spec_ap.get();
205 BreakpointOptions::SetThreadID (lldb::tid_t thread_id)
207 GetThreadSpec()->SetTID(thread_id);
211 BreakpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const
214 // Figure out if there are any options not at their default value, and only print
215 // anything if there are:
217 if (m_ignore_count != 0 || !m_enabled || m_one_shot || (GetThreadSpecNoCreate() != NULL && GetThreadSpecNoCreate()->HasSpecification ()))
219 if (level == lldb::eDescriptionLevelVerbose)
224 s->PutCString("Breakpoint Options:\n");
229 s->PutCString(" Options: ");
231 if (m_ignore_count > 0)
232 s->Printf("ignore: %d ", m_ignore_count);
233 s->Printf("%sabled ", m_enabled ? "en" : "dis");
236 s->Printf ("one-shot ");
238 if (m_thread_spec_ap.get())
239 m_thread_spec_ap->GetDescription (s, level);
240 else if (level == eDescriptionLevelBrief)
241 s->PutCString ("thread spec: no ");
242 if (level == lldb::eDescriptionLevelFull)
249 if (m_callback_baton_sp.get())
251 if (level != eDescriptionLevelBrief)
254 m_callback_baton_sp->GetDescription (s, level);
257 if (!m_condition_text.empty())
259 if (level != eDescriptionLevelBrief)
262 s->Printf("Condition: %s\n", m_condition_text.c_str());
268 BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
270 CommandData *data = (CommandData *)m_data;
272 if (level == eDescriptionLevelBrief)
274 s->Printf (", commands = %s", (data && data->user_source.GetSize() > 0) ? "yes" : "no");
279 s->Indent("Breakpoint commands:\n");
282 if (data && data->user_source.GetSize() > 0)
284 const size_t num_strings = data->user_source.GetSize();
285 for (size_t i = 0; i < num_strings; ++i)
287 s->Indent(data->user_source.GetStringAtIndex(i));
293 s->PutCString ("No commands.\n");