Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 19 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | bool |
| 25 | BreakpointOptions::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 | //---------------------------------------------------------------------- |
| 33 | BreakpointOptions::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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 39 | m_thread_spec_ap (NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | //---------------------------------------------------------------------- |
| 44 | // BreakpointOptions copy constructor |
| 45 | //---------------------------------------------------------------------- |
| 46 | BreakpointOptions::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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 52 | m_thread_spec_ap (NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | { |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 54 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 55 | m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | //---------------------------------------------------------------------- |
| 59 | // BreakpointOptions assignment operator |
| 60 | //---------------------------------------------------------------------- |
| 61 | const BreakpointOptions& |
| 62 | BreakpointOptions::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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 69 | if (rhs.m_thread_spec_ap.get() != NULL) |
| 70 | m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | return *this; |
| 72 | } |
| 73 | |
| 74 | //---------------------------------------------------------------------- |
| 75 | // Destructor |
| 76 | //---------------------------------------------------------------------- |
| 77 | BreakpointOptions::~BreakpointOptions() |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | //------------------------------------------------------------------ |
| 82 | // Callbacks |
| 83 | //------------------------------------------------------------------ |
| 84 | void |
| 85 | BreakpointOptions::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 | |
| 92 | void |
| 93 | BreakpointOptions::ClearCallback () |
| 94 | { |
| 95 | m_callback = NULL; |
| 96 | m_callback_baton_sp.reset(); |
| 97 | } |
| 98 | |
| 99 | Baton * |
| 100 | BreakpointOptions::GetBaton () |
| 101 | { |
| 102 | return m_callback_baton_sp.get(); |
| 103 | } |
| 104 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 105 | const Baton * |
| 106 | BreakpointOptions::GetBaton () const |
| 107 | { |
| 108 | return m_callback_baton_sp.get(); |
| 109 | } |
| 110 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | bool |
| 112 | BreakpointOptions::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 | //------------------------------------------------------------------ |
| 130 | bool |
| 131 | BreakpointOptions::IsEnabled () const |
| 132 | { |
| 133 | return m_enabled; |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | BreakpointOptions::SetEnabled (bool enabled) |
| 138 | { |
| 139 | m_enabled = enabled; |
| 140 | } |
| 141 | |
| 142 | int32_t |
| 143 | BreakpointOptions::GetIgnoreCount () const |
| 144 | { |
| 145 | return m_ignore_count; |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | BreakpointOptions::SetIgnoreCount (int32_t n) |
| 150 | { |
| 151 | m_ignore_count = n; |
| 152 | } |
| 153 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 154 | const ThreadSpec * |
| 155 | BreakpointOptions::GetThreadSpec () const |
| 156 | { |
| 157 | return m_thread_spec_ap.get(); |
| 158 | } |
| 159 | |
| 160 | ThreadSpec * |
| 161 | BreakpointOptions::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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | void |
| 170 | BreakpointOptions::SetThreadID (lldb::tid_t thread_id) |
| 171 | { |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame^] | 172 | GetThreadSpec()->SetTID(thread_id); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | void |
| 176 | BreakpointOptions::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 | |