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" |
| 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | bool |
| 24 | BreakpointOptions::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 | //---------------------------------------------------------------------- |
| 32 | BreakpointOptions::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 | //---------------------------------------------------------------------- |
| 45 | BreakpointOptions::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 | //---------------------------------------------------------------------- |
| 58 | const BreakpointOptions& |
| 59 | BreakpointOptions::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 | //---------------------------------------------------------------------- |
| 73 | BreakpointOptions::~BreakpointOptions() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | //------------------------------------------------------------------ |
| 78 | // Callbacks |
| 79 | //------------------------------------------------------------------ |
| 80 | void |
| 81 | BreakpointOptions::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 | |
| 88 | void |
| 89 | BreakpointOptions::ClearCallback () |
| 90 | { |
| 91 | m_callback = NULL; |
| 92 | m_callback_baton_sp.reset(); |
| 93 | } |
| 94 | |
| 95 | Baton * |
| 96 | BreakpointOptions::GetBaton () |
| 97 | { |
| 98 | return m_callback_baton_sp.get(); |
| 99 | } |
| 100 | |
| 101 | bool |
| 102 | BreakpointOptions::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 | //------------------------------------------------------------------ |
| 120 | bool |
| 121 | BreakpointOptions::IsEnabled () const |
| 122 | { |
| 123 | return m_enabled; |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | BreakpointOptions::SetEnabled (bool enabled) |
| 128 | { |
| 129 | m_enabled = enabled; |
| 130 | } |
| 131 | |
| 132 | int32_t |
| 133 | BreakpointOptions::GetIgnoreCount () const |
| 134 | { |
| 135 | return m_ignore_count; |
| 136 | } |
| 137 | |
| 138 | void |
| 139 | BreakpointOptions::SetIgnoreCount (int32_t n) |
| 140 | { |
| 141 | m_ignore_count = n; |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | BreakpointOptions::SetThreadID (lldb::tid_t thread_id) |
| 146 | { |
| 147 | m_thread_id = thread_id; |
| 148 | } |
| 149 | |
| 150 | lldb::tid_t |
| 151 | BreakpointOptions::GetThreadID () const |
| 152 | { |
| 153 | return m_thread_id; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | |
| 158 | void |
| 159 | BreakpointOptions::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 | |