blob: 4f664c4692fecbe622e080dfbafb432e710e23ec [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"
19
20using namespace lldb;
21using namespace lldb_private;
22
23bool
24BreakpointOptions::NullCallback (void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
25{
26 return true;
27}
28
29//----------------------------------------------------------------------
30// BreakpointOptions constructor
31//----------------------------------------------------------------------
32BreakpointOptions::BreakpointOptions() :
33 m_callback (BreakpointOptions::NullCallback),
34 m_callback_is_synchronous (false),
35 m_callback_baton_sp (),
36 m_enabled (true),
37 m_ignore_count (0),
38 m_thread_id (LLDB_INVALID_THREAD_ID)
39{
40}
41
42//----------------------------------------------------------------------
43// BreakpointOptions copy constructor
44//----------------------------------------------------------------------
45BreakpointOptions::BreakpointOptions(const BreakpointOptions& rhs) :
46 m_callback (rhs.m_callback),
47 m_callback_baton_sp (rhs.m_callback_baton_sp),
48 m_callback_is_synchronous (rhs.m_callback_is_synchronous),
49 m_enabled (rhs.m_enabled),
50 m_ignore_count (rhs.m_ignore_count),
51 m_thread_id (rhs.m_thread_id)
52{
53}
54
55//----------------------------------------------------------------------
56// BreakpointOptions assignment operator
57//----------------------------------------------------------------------
58const BreakpointOptions&
59BreakpointOptions::operator=(const BreakpointOptions& rhs)
60{
61 m_callback = rhs.m_callback;
62 m_callback_baton_sp = rhs.m_callback_baton_sp;
63 m_callback_is_synchronous = rhs.m_callback_is_synchronous;
64 m_enabled = rhs.m_enabled;
65 m_ignore_count = rhs.m_ignore_count;
66 m_thread_id = rhs.m_thread_id;
67 return *this;
68}
69
70//----------------------------------------------------------------------
71// Destructor
72//----------------------------------------------------------------------
73BreakpointOptions::~BreakpointOptions()
74{
75}
76
77//------------------------------------------------------------------
78// Callbacks
79//------------------------------------------------------------------
80void
81BreakpointOptions::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool callback_is_synchronous)
82{
83 m_callback_is_synchronous = callback_is_synchronous;
84 m_callback = callback;
85 m_callback_baton_sp = callback_baton_sp;
86}
87
88void
89BreakpointOptions::ClearCallback ()
90{
91 m_callback = NULL;
92 m_callback_baton_sp.reset();
93}
94
95Baton *
96BreakpointOptions::GetBaton ()
97{
98 return m_callback_baton_sp.get();
99}
100
101bool
102BreakpointOptions::InvokeCallback (StoppointCallbackContext *context,
103 lldb::user_id_t break_id,
104 lldb::user_id_t break_loc_id)
105{
106 if (m_callback && context->is_synchronous == IsCallbackSynchronous())
107 {
108 return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL,
109 context,
110 break_id,
111 break_loc_id);
112 }
113 else
114 return true;
115}
116
117//------------------------------------------------------------------
118// Enabled/Ignore Count
119//------------------------------------------------------------------
120bool
121BreakpointOptions::IsEnabled () const
122{
123 return m_enabled;
124}
125
126void
127BreakpointOptions::SetEnabled (bool enabled)
128{
129 m_enabled = enabled;
130}
131
132int32_t
133BreakpointOptions::GetIgnoreCount () const
134{
135 return m_ignore_count;
136}
137
138void
139BreakpointOptions::SetIgnoreCount (int32_t n)
140{
141 m_ignore_count = n;
142}
143
144void
145BreakpointOptions::SetThreadID (lldb::tid_t thread_id)
146{
147 m_thread_id = thread_id;
148}
149
150lldb::tid_t
151BreakpointOptions::GetThreadID () const
152{
153 return m_thread_id;
154}
155
156
157
158void
159BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const
160{
161 s->Indent("Breakpoint commands:\n");
162 CommandData *data = (CommandData *)m_data;
163
164 s->IndentMore ();
165 if (data && data->user_source.GetSize() > 0)
166 {
167 const size_t num_strings = data->user_source.GetSize();
168 for (size_t i = 0; i < num_strings; ++i)
169 {
170 s->Indent(data->user_source.GetStringAtIndex(i));
171 s->EOL();
172 }
173 }
174 else
175 {
176 s->PutCString ("No commands.\n");
177 }
178 s->IndentLess ();
179}
180