blob: 695f4ee5ccdf19a667aae9e7d6a53a9866dac397 [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
74//----------------------------------------------------------------------
75// Destructor
76//----------------------------------------------------------------------
77BreakpointOptions::~BreakpointOptions()
78{
79}
80
81//------------------------------------------------------------------
82// Callbacks
83//------------------------------------------------------------------
84void
85BreakpointOptions::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
86{
87 m_callback_is_synchronous = callback_is_synchronous;
88 m_callback = callback;
89 m_callback_baton_sp = callback_baton_sp;
90}
91
92void
93BreakpointOptions::ClearCallback ()
94{
95 m_callback = NULL;
96 m_callback_baton_sp.reset();
97}
98
99Baton *
100BreakpointOptions::GetBaton ()
101{
102 return m_callback_baton_sp.get();
103}
104
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000105const Baton *
106BreakpointOptions::GetBaton () const
107{
108 return m_callback_baton_sp.get();
109}
110
Chris Lattner24943d22010-06-08 16:52:24 +0000111bool
112BreakpointOptions::InvokeCallback (StoppointCallbackContext *context,
113 lldb::user_id_t break_id,
114 lldb::user_id_t break_loc_id)
115{
116 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
117 {
118 return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL,
119 context,
120 break_id,
121 break_loc_id);
122 }
123 else
124 return true;
125}
126
127//------------------------------------------------------------------
128// Enabled/Ignore Count
129//------------------------------------------------------------------
130bool
131BreakpointOptions::IsEnabled () const
132{
133 return m_enabled;
134}
135
136void
137BreakpointOptions::SetEnabled (bool enabled)
138{
139 m_enabled = enabled;
140}
141
142int32_t
143BreakpointOptions::GetIgnoreCount () const
144{
145 return m_ignore_count;
146}
147
148void
149BreakpointOptions::SetIgnoreCount (int32_t n)
150{
151 m_ignore_count = n;
152}
153
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000154const ThreadSpec *
155BreakpointOptions::GetThreadSpec () const
156{
157 return m_thread_spec_ap.get();
158}
159
160ThreadSpec *
161BreakpointOptions::GetThreadSpec ()
162{
163 if (m_thread_spec_ap.get() == NULL)
164 m_thread_spec_ap.reset (new ThreadSpec());
165
166 return m_thread_spec_ap.get();
167}
168
Chris Lattner24943d22010-06-08 16:52:24 +0000169void
170BreakpointOptions::SetThreadID (lldb::tid_t thread_id)
171{
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000172 GetThreadSpec()->SetTID(thread_id);
Chris Lattner24943d22010-06-08 16:52:24 +0000173}
174
Chris Lattner24943d22010-06-08 16:52:24 +0000175void
176BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
177{
178 s->Indent("Breakpoint commands:\n");
179 CommandData *data = (CommandData *)m_data;
180
181 s->IndentMore ();
182 if (data && data->user_source.GetSize() > 0)
183 {
184 const size_t num_strings = data->user_source.GetSize();
185 for (size_t i = 0; i < num_strings; ++i)
186 {
187 s->Indent(data->user_source.GetStringAtIndex(i));
188 s->EOL();
189 }
190 }
191 else
192 {
193 s->PutCString ("No commands.\n");
194 }
195 s->IndentLess ();
196}
197