blob: c3625140d767c846f80b43b18f5316d961b73f4b [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- BreakpointOptions.cpp -----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Breakpoint/BreakpointOptions.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Stream.h"
17#include "lldb/Core/StringList.h"
18#include "lldb/Breakpoint/StoppointCallbackContext.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000019#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24bool
25BreakpointOptions::NullCallback (void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
26{
27 return true;
28}
29
30//----------------------------------------------------------------------
31// BreakpointOptions constructor
32//----------------------------------------------------------------------
33BreakpointOptions::BreakpointOptions() :
34 m_callback (BreakpointOptions::NullCallback),
35 m_callback_is_synchronous (false),
36 m_callback_baton_sp (),
37 m_enabled (true),
38 m_ignore_count (0),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000039 m_thread_spec_ap (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000040{
41}
42
43//----------------------------------------------------------------------
44// BreakpointOptions copy constructor
45//----------------------------------------------------------------------
46BreakpointOptions::BreakpointOptions(const BreakpointOptions& rhs) :
47 m_callback (rhs.m_callback),
48 m_callback_baton_sp (rhs.m_callback_baton_sp),
49 m_callback_is_synchronous (rhs.m_callback_is_synchronous),
50 m_enabled (rhs.m_enabled),
51 m_ignore_count (rhs.m_ignore_count),
Jim Ingham3c7b5b92010-06-16 02:00:15 +000052 m_thread_spec_ap (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Jim Ingham3c7b5b92010-06-16 02:00:15 +000054 if (rhs.m_thread_spec_ap.get() != NULL)
55 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58//----------------------------------------------------------------------
59// BreakpointOptions assignment operator
60//----------------------------------------------------------------------
61const BreakpointOptions&
62BreakpointOptions::operator=(const BreakpointOptions& rhs)
63{
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 m_enabled = rhs.m_enabled;
68 m_ignore_count = rhs.m_ignore_count;
Jim Ingham3c7b5b92010-06-16 02:00:15 +000069 if (rhs.m_thread_spec_ap.get() != NULL)
70 m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000071 return *this;
72}
73
Jim Ingham649492b2010-06-18 01:00:58 +000074BreakpointOptions *
75BreakpointOptions::CopyOptionsNoCallback (BreakpointOptions &orig)
76{
77 BreakpointHitCallback orig_callback = orig.m_callback;
78 lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
79 bool orig_is_sync = orig.m_callback_is_synchronous;
80
81 orig.ClearCallback();
82 BreakpointOptions *ret_val = new BreakpointOptions(orig);
83
84 orig.SetCallback (orig_callback, orig_callback_baton_sp, orig_is_sync);
85
86 return ret_val;
87}
88
Chris Lattner24943d22010-06-08 16:52:24 +000089//----------------------------------------------------------------------
90// Destructor
91//----------------------------------------------------------------------
92BreakpointOptions::~BreakpointOptions()
93{
94}
95
96//------------------------------------------------------------------
97// Callbacks
98//------------------------------------------------------------------
99void
100BreakpointOptions::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
101{
102 m_callback_is_synchronous = callback_is_synchronous;
103 m_callback = callback;
104 m_callback_baton_sp = callback_baton_sp;
105}
106
107void
108BreakpointOptions::ClearCallback ()
109{
110 m_callback = NULL;
111 m_callback_baton_sp.reset();
112}
113
114Baton *
115BreakpointOptions::GetBaton ()
116{
117 return m_callback_baton_sp.get();
118}
119
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000120const Baton *
121BreakpointOptions::GetBaton () const
122{
123 return m_callback_baton_sp.get();
124}
125
Chris Lattner24943d22010-06-08 16:52:24 +0000126bool
127BreakpointOptions::InvokeCallback (StoppointCallbackContext *context,
128 lldb::user_id_t break_id,
129 lldb::user_id_t break_loc_id)
130{
131 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
132 {
133 return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL,
134 context,
135 break_id,
136 break_loc_id);
137 }
138 else
139 return true;
140}
141
Jim Ingham649492b2010-06-18 01:00:58 +0000142bool
143BreakpointOptions::HasCallback ()
144{
145 return m_callback != BreakpointOptions::NullCallback;
146}
147
Chris Lattner24943d22010-06-08 16:52:24 +0000148//------------------------------------------------------------------
149// Enabled/Ignore Count
150//------------------------------------------------------------------
151bool
152BreakpointOptions::IsEnabled () const
153{
154 return m_enabled;
155}
156
157void
158BreakpointOptions::SetEnabled (bool enabled)
159{
160 m_enabled = enabled;
161}
162
163int32_t
164BreakpointOptions::GetIgnoreCount () const
165{
166 return m_ignore_count;
167}
168
169void
170BreakpointOptions::SetIgnoreCount (int32_t n)
171{
172 m_ignore_count = n;
173}
174
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000175const ThreadSpec *
176BreakpointOptions::GetThreadSpec () const
177{
178 return m_thread_spec_ap.get();
179}
180
181ThreadSpec *
182BreakpointOptions::GetThreadSpec ()
183{
184 if (m_thread_spec_ap.get() == NULL)
185 m_thread_spec_ap.reset (new ThreadSpec());
186
187 return m_thread_spec_ap.get();
188}
189
Chris Lattner24943d22010-06-08 16:52:24 +0000190void
191BreakpointOptions::SetThreadID (lldb::tid_t thread_id)
192{
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000193 GetThreadSpec()->SetTID(thread_id);
Chris Lattner24943d22010-06-08 16:52:24 +0000194}
195
Chris Lattner24943d22010-06-08 16:52:24 +0000196void
Jim Ingham649492b2010-06-18 01:00:58 +0000197BreakpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const
198{
199
200 // Figure out if there are any options not at their default value, and only print
201 // anything if there are:
202
203 if (m_ignore_count != 0 || !m_enabled || (GetThreadSpec() != NULL && GetThreadSpec()->HasSpecification ()))
204 {
205 if (level == lldb::eDescriptionLevelVerbose)
206 {
207 s->EOL ();
208 s->IndentMore();
209 s->Indent();
210 s->PutCString("Breakpoint Options:\n");
211 s->IndentMore();
212 s->Indent();
213 }
214 else
215 s->PutCString(" Options: ");
216
217 if (m_ignore_count > 0)
218 s->Printf("ignore: %d ", m_ignore_count);
219 s->Printf("%sabled ", m_enabled ? "en" : "dis");
220
221 if (m_thread_spec_ap.get())
222 m_thread_spec_ap->GetDescription (s, level);
223 else if (level == eDescriptionLevelBrief)
224 s->PutCString ("thread spec: no ");
225 if (level == lldb::eDescriptionLevelFull)
226 {
227 s->IndentLess();
228 s->IndentMore();
229 }
230 }
231
232 if (m_callback_baton_sp.get())
233 {
234 if (level != eDescriptionLevelBrief)
235 s->EOL();
236 m_callback_baton_sp->GetDescription (s, level);
237 }
238 else if (level == eDescriptionLevelBrief)
239 s->PutCString ("commands: no ");
240
241}
242
243void
Chris Lattner24943d22010-06-08 16:52:24 +0000244BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
245{
Chris Lattner24943d22010-06-08 16:52:24 +0000246 CommandData *data = (CommandData *)m_data;
Jim Ingham649492b2010-06-18 01:00:58 +0000247
248 if (level == eDescriptionLevelBrief)
249 {
250 if (data && data->user_source.GetSize() > 0)
251 s->PutCString("commands: yes ");
252 else
253 s->PutCString("commands: no ");
254 return;
255 }
256
257 s->IndentMore ();
258 s->Indent("Breakpoint commands:\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000259
260 s->IndentMore ();
261 if (data && data->user_source.GetSize() > 0)
262 {
263 const size_t num_strings = data->user_source.GetSize();
264 for (size_t i = 0; i < num_strings; ++i)
265 {
266 s->Indent(data->user_source.GetStringAtIndex(i));
267 s->EOL();
268 }
269 }
270 else
271 {
272 s->PutCString ("No commands.\n");
273 }
274 s->IndentLess ();
Jim Ingham649492b2010-06-18 01:00:58 +0000275 s->IndentLess ();
Chris Lattner24943d22010-06-08 16:52:24 +0000276}
277