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 | |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 74 | BreakpointOptions * |
| 75 | BreakpointOptions::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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | //---------------------------------------------------------------------- |
| 90 | // Destructor |
| 91 | //---------------------------------------------------------------------- |
| 92 | BreakpointOptions::~BreakpointOptions() |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | //------------------------------------------------------------------ |
| 97 | // Callbacks |
| 98 | //------------------------------------------------------------------ |
| 99 | void |
| 100 | BreakpointOptions::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 | |
| 107 | void |
| 108 | BreakpointOptions::ClearCallback () |
| 109 | { |
| 110 | m_callback = NULL; |
| 111 | m_callback_baton_sp.reset(); |
| 112 | } |
| 113 | |
| 114 | Baton * |
| 115 | BreakpointOptions::GetBaton () |
| 116 | { |
| 117 | return m_callback_baton_sp.get(); |
| 118 | } |
| 119 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 120 | const Baton * |
| 121 | BreakpointOptions::GetBaton () const |
| 122 | { |
| 123 | return m_callback_baton_sp.get(); |
| 124 | } |
| 125 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | bool |
| 127 | BreakpointOptions::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 Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 142 | bool |
| 143 | BreakpointOptions::HasCallback () |
| 144 | { |
| 145 | return m_callback != BreakpointOptions::NullCallback; |
| 146 | } |
| 147 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | //------------------------------------------------------------------ |
| 149 | // Enabled/Ignore Count |
| 150 | //------------------------------------------------------------------ |
| 151 | bool |
| 152 | BreakpointOptions::IsEnabled () const |
| 153 | { |
| 154 | return m_enabled; |
| 155 | } |
| 156 | |
| 157 | void |
| 158 | BreakpointOptions::SetEnabled (bool enabled) |
| 159 | { |
| 160 | m_enabled = enabled; |
| 161 | } |
| 162 | |
| 163 | int32_t |
| 164 | BreakpointOptions::GetIgnoreCount () const |
| 165 | { |
| 166 | return m_ignore_count; |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | BreakpointOptions::SetIgnoreCount (int32_t n) |
| 171 | { |
| 172 | m_ignore_count = n; |
| 173 | } |
| 174 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 175 | const ThreadSpec * |
Jim Ingham | 9c6898b | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 176 | BreakpointOptions::GetThreadSpecNoCreate () const |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 177 | { |
| 178 | return m_thread_spec_ap.get(); |
| 179 | } |
| 180 | |
| 181 | ThreadSpec * |
| 182 | BreakpointOptions::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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 190 | void |
| 191 | BreakpointOptions::SetThreadID (lldb::tid_t thread_id) |
| 192 | { |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 193 | GetThreadSpec()->SetTID(thread_id); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | void |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 197 | BreakpointOptions::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 | |
Jim Ingham | 9c6898b | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 203 | if (m_ignore_count != 0 || !m_enabled || (GetThreadSpecNoCreate() != NULL && GetThreadSpecNoCreate()->HasSpecification ())) |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 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); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame^] | 237 | } |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 241 | BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 242 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | CommandData *data = (CommandData *)m_data; |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 244 | |
| 245 | if (level == eDescriptionLevelBrief) |
| 246 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame^] | 247 | s->Printf (", commands = %s", (data && data->user_source.GetSize() > 0) ? "yes" : "no"); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 248 | return; |
| 249 | } |
| 250 | |
| 251 | s->IndentMore (); |
| 252 | s->Indent("Breakpoint commands:\n"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | |
| 254 | s->IndentMore (); |
| 255 | if (data && data->user_source.GetSize() > 0) |
| 256 | { |
| 257 | const size_t num_strings = data->user_source.GetSize(); |
| 258 | for (size_t i = 0; i < num_strings; ++i) |
| 259 | { |
| 260 | s->Indent(data->user_source.GetStringAtIndex(i)); |
| 261 | s->EOL(); |
| 262 | } |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | s->PutCString ("No commands.\n"); |
| 267 | } |
| 268 | s->IndentLess (); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 269 | s->IndentLess (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |