Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBCommandInterpreter.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/lldb-types.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "lldb/Core/SourceManager.h" |
| 12 | #include "lldb/Core/Listener.h" |
| 13 | #include "lldb/Interpreter/CommandInterpreter.h" |
Enrico Granata | 6d10188 | 2012-09-28 23:57:51 +0000 | [diff] [blame^] | 14 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 16 | #include "lldb/Target/Target.h" |
| 17 | |
Eli Friedman | d6ec8aa | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBBroadcaster.h" |
Eli Friedman | d6ec8aa | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBCommandReturnObject.h" |
Eli Friedman | d6ec8aa | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBCommandInterpreter.h" |
| 21 | #include "lldb/API/SBProcess.h" |
| 22 | #include "lldb/API/SBTarget.h" |
| 23 | #include "lldb/API/SBListener.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 24 | #include "lldb/API/SBStream.h" |
Eli Friedman | d6ec8aa | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 25 | #include "lldb/API/SBStringList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace lldb; |
| 28 | using namespace lldb_private; |
| 29 | |
Enrico Granata | 6d10188 | 2012-09-28 23:57:51 +0000 | [diff] [blame^] | 30 | class CommandPluginInterfaceImplementation : public CommandObjectParsed |
| 31 | { |
| 32 | public: |
| 33 | CommandPluginInterfaceImplementation (CommandInterpreter &interpreter, |
| 34 | const char *name, |
| 35 | lldb::SBCommandPluginInterface* backend, |
| 36 | const char *help = NULL, |
| 37 | const char *syntax = NULL, |
| 38 | uint32_t flags = 0) : |
| 39 | CommandObjectParsed (interpreter, name, help, syntax, flags), |
| 40 | m_backend(backend) {} |
| 41 | |
| 42 | virtual bool |
| 43 | IsRemovable() { return true; } |
| 44 | |
| 45 | protected: |
| 46 | virtual bool |
| 47 | DoExecute (Args& command, CommandReturnObject &result) |
| 48 | { |
| 49 | SBCommandReturnObject sb_return(&result); |
| 50 | SBCommandInterpreter sb_interpreter(&m_interpreter); |
| 51 | SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); |
| 52 | bool ret = m_backend->DoExecute (debugger_sb,(char**)command.GetArgumentVector(), sb_return); |
| 53 | sb_return.Release(); |
| 54 | return ret; |
| 55 | } |
| 56 | lldb::SBCommandPluginInterface* m_backend; |
| 57 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 59 | SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) : |
| 60 | m_opaque_ptr (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 62 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 63 | |
| 64 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 65 | log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)" |
| 66 | " => SBCommandInterpreter(%p)", interpreter, m_opaque_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 69 | SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) : |
| 70 | m_opaque_ptr (rhs.m_opaque_ptr) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | const SBCommandInterpreter & |
| 75 | SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs) |
| 76 | { |
| 77 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 78 | return *this; |
| 79 | } |
| 80 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | SBCommandInterpreter::~SBCommandInterpreter () |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 86 | SBCommandInterpreter::IsValid() const |
| 87 | { |
| 88 | return m_opaque_ptr != NULL; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | SBCommandInterpreter::CommandExists (const char *cmd) |
| 94 | { |
Johnny Chen | bab8cc9 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 95 | if (cmd && m_opaque_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 96 | return m_opaque_ptr->CommandExists (cmd); |
| 97 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | bool |
| 101 | SBCommandInterpreter::AliasExists (const char *cmd) |
| 102 | { |
Johnny Chen | bab8cc9 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 103 | if (cmd && m_opaque_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 104 | return m_opaque_ptr->AliasExists (cmd); |
| 105 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | lldb::ReturnStatus |
| 109 | SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history) |
| 110 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 111 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 112 | |
| 113 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 114 | log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)", |
| 115 | m_opaque_ptr, command_line, result.get(), add_to_history); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 116 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | result.Clear(); |
Johnny Chen | bab8cc9 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 118 | if (command_line && m_opaque_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 119 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 120 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 121 | Mutex::Locker api_locker; |
| 122 | if (target_sp) |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 123 | api_locker.Lock(target_sp->GetAPIMutex()); |
Enrico Granata | 01bc2d4 | 2012-05-31 01:09:06 +0000 | [diff] [blame] | 124 | m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 125 | } |
| 126 | else |
| 127 | { |
Johnny Chen | bab8cc9 | 2011-12-19 21:16:29 +0000 | [diff] [blame] | 128 | result->AppendError ("SBCommandInterpreter or the command line is not valid"); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 129 | result->SetStatus (eReturnStatusFailed); |
| 130 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 131 | |
Caroline Tice | 7de24cc | 2010-10-27 21:23:37 +0000 | [diff] [blame] | 132 | // We need to get the value again, in case the command disabled the log! |
| 133 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 134 | if (log) |
| 135 | { |
| 136 | SBStream sstr; |
| 137 | result.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 138 | log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i", |
| 139 | m_opaque_ptr, command_line, result.get(), sstr.GetData(), add_to_history, result.GetStatus()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | return result.GetStatus(); |
| 143 | } |
| 144 | |
| 145 | int |
| 146 | SBCommandInterpreter::HandleCompletion (const char *current_line, |
| 147 | const char *cursor, |
| 148 | const char *last_char, |
| 149 | int match_start_point, |
| 150 | int max_return_elements, |
| 151 | SBStringList &matches) |
| 152 | { |
Jim Ingham | bc8c499 | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 153 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 154 | int num_completions = 0; |
Jim Ingham | 3cbf848 | 2011-12-05 19:24:15 +0000 | [diff] [blame] | 155 | |
| 156 | // Sanity check the arguments that are passed in: |
| 157 | // cursor & last_char have to be within the current_line. |
| 158 | if (current_line == NULL || cursor == NULL || last_char == NULL) |
| 159 | return 0; |
| 160 | |
| 161 | if (cursor < current_line || last_char < current_line) |
| 162 | return 0; |
| 163 | |
| 164 | size_t current_line_size = strlen (current_line); |
| 165 | if (cursor - current_line > current_line_size || last_char - current_line > current_line_size) |
| 166 | return 0; |
| 167 | |
Jim Ingham | bc8c499 | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 168 | if (log) |
Jason Molenda | a092d90 | 2012-07-17 01:57:24 +0000 | [diff] [blame] | 169 | log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %lld, last char at: %lld, match_start_point: %d, max_return_elements: %d)", |
| 170 | m_opaque_ptr, current_line, (uint64_t) (cursor - current_line), (uint64_t) (last_char - current_line), match_start_point, max_return_elements); |
Jim Ingham | bc8c499 | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 171 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 172 | if (m_opaque_ptr) |
| 173 | { |
| 174 | lldb_private::StringList lldb_matches; |
| 175 | num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point, |
| 176 | max_return_elements, lldb_matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 178 | SBStringList temp_list (&lldb_matches); |
| 179 | matches.AppendList (temp_list); |
| 180 | } |
Jim Ingham | bc8c499 | 2012-06-26 01:21:59 +0000 | [diff] [blame] | 181 | if (log) |
| 182 | log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", m_opaque_ptr, num_completions); |
| 183 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | return num_completions; |
| 185 | } |
| 186 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 187 | int |
| 188 | SBCommandInterpreter::HandleCompletion (const char *current_line, |
| 189 | uint32_t cursor_pos, |
| 190 | int match_start_point, |
| 191 | int max_return_elements, |
| 192 | lldb::SBStringList &matches) |
| 193 | { |
| 194 | const char *cursor = current_line + cursor_pos; |
| 195 | const char *last_char = current_line + strlen (current_line); |
| 196 | return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches); |
| 197 | } |
| 198 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | bool |
| 200 | SBCommandInterpreter::HasCommands () |
| 201 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 202 | if (m_opaque_ptr) |
| 203 | return m_opaque_ptr->HasCommands(); |
| 204 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | bool |
| 208 | SBCommandInterpreter::HasAliases () |
| 209 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 210 | if (m_opaque_ptr) |
| 211 | return m_opaque_ptr->HasAliases(); |
| 212 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | SBCommandInterpreter::HasAliasOptions () |
| 217 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 218 | if (m_opaque_ptr) |
| 219 | return m_opaque_ptr->HasAliasOptions (); |
| 220 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | SBProcess |
| 224 | SBCommandInterpreter::GetProcess () |
| 225 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 226 | SBProcess sb_process; |
| 227 | ProcessSP process_sp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 228 | if (m_opaque_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 230 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 231 | if (target_sp) |
| 232 | { |
| 233 | Mutex::Locker api_locker(target_sp->GetAPIMutex()); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 234 | process_sp = target_sp->GetProcessSP(); |
| 235 | sb_process.SetSP(process_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 236 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 237 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 238 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 239 | |
| 240 | if (log) |
| 241 | log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 242 | m_opaque_ptr, process_sp.get()); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 243 | |
| 244 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 245 | return sb_process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Enrico Granata | 6d10188 | 2012-09-28 23:57:51 +0000 | [diff] [blame^] | 248 | SBDebugger |
| 249 | SBCommandInterpreter::GetDebugger () |
| 250 | { |
| 251 | SBDebugger sb_debugger; |
| 252 | if (m_opaque_ptr) |
| 253 | sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); |
| 254 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 255 | |
| 256 | if (log) |
| 257 | log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)", |
| 258 | m_opaque_ptr, sb_debugger.get()); |
| 259 | |
| 260 | |
| 261 | return sb_debugger; |
| 262 | } |
| 263 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | CommandInterpreter * |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 265 | SBCommandInterpreter::get () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 266 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 267 | return m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | CommandInterpreter & |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 271 | SBCommandInterpreter::ref () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 273 | assert (m_opaque_ptr); |
| 274 | return *m_opaque_ptr; |
| 275 | } |
| 276 | |
| 277 | void |
| 278 | SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter) |
| 279 | { |
| 280 | m_opaque_ptr = interpreter; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void |
| 284 | SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result) |
| 285 | { |
| 286 | result.Clear(); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 287 | if (m_opaque_ptr) |
| 288 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 289 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 290 | Mutex::Locker api_locker; |
| 291 | if (target_sp) |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 292 | api_locker.Lock(target_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 293 | m_opaque_ptr->SourceInitFile (false, result.ref()); |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | result->AppendError ("SBCommandInterpreter is not valid"); |
| 298 | result->SetStatus (eReturnStatusFailed); |
| 299 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 300 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 301 | |
| 302 | if (log) |
| 303 | log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))", |
| 304 | m_opaque_ptr, result.get()); |
| 305 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void |
| 309 | SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result) |
| 310 | { |
| 311 | result.Clear(); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 312 | if (m_opaque_ptr) |
| 313 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 314 | TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); |
| 315 | Mutex::Locker api_locker; |
| 316 | if (target_sp) |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 317 | api_locker.Lock(target_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 318 | m_opaque_ptr->SourceInitFile (true, result.ref()); |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | result->AppendError ("SBCommandInterpreter is not valid"); |
| 323 | result->SetStatus (eReturnStatusFailed); |
| 324 | } |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 325 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 326 | |
| 327 | if (log) |
| 328 | log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))", |
| 329 | m_opaque_ptr, result.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | SBBroadcaster |
| 333 | SBCommandInterpreter::GetBroadcaster () |
| 334 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 335 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 336 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 337 | SBBroadcaster broadcaster (m_opaque_ptr, false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 338 | |
| 339 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 340 | log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 341 | m_opaque_ptr, broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 342 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | return broadcaster; |
| 344 | } |
| 345 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 346 | const char * |
| 347 | SBCommandInterpreter::GetBroadcasterClass () |
| 348 | { |
| 349 | return Communication::GetStaticBroadcasterClass().AsCString(); |
| 350 | } |
| 351 | |
Greg Clayton | aa378b1 | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 352 | const char * |
| 353 | SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) |
| 354 | { |
| 355 | return CommandObject::GetArgumentTypeAsCString (arg_type); |
| 356 | } |
| 357 | |
| 358 | const char * |
| 359 | SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) |
| 360 | { |
| 361 | return CommandObject::GetArgumentDescriptionAsCString (arg_type); |
| 362 | } |
| 363 | |
Greg Clayton | f125250 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 364 | bool |
| 365 | SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name, |
| 366 | lldb::CommandOverrideCallback callback, |
| 367 | void *baton) |
| 368 | { |
| 369 | if (command_name && command_name[0] && m_opaque_ptr) |
| 370 | { |
Greg Clayton | 5f2b926 | 2012-05-08 04:29:20 +0000 | [diff] [blame] | 371 | std::string command_name_str (command_name); |
| 372 | CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str); |
Greg Clayton | f125250 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 373 | if (cmd_obj) |
| 374 | { |
Greg Clayton | 5f2b926 | 2012-05-08 04:29:20 +0000 | [diff] [blame] | 375 | assert(command_name_str.empty()); |
Greg Clayton | f125250 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 376 | cmd_obj->SetOverrideCallback (callback, baton); |
| 377 | return true; |
| 378 | } |
| 379 | } |
| 380 | return false; |
| 381 | } |
Greg Clayton | aa378b1 | 2011-02-20 02:15:07 +0000 | [diff] [blame] | 382 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 383 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | c2a2825 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 384 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 385 | // Defined in the SWIG source file |
| 386 | extern "C" void |
| 387 | init_lldb(void); |
| 388 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 389 | #else |
Enrico Granata | c2a2825 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 390 | |
Greg Clayton | e86cbb9 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 391 | extern "C" void init_lldb(void); |
| 392 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 393 | // Usually defined in the SWIG source file, but we have sripting disabled |
| 394 | extern "C" void |
| 395 | init_lldb(void) |
| 396 | { |
| 397 | } |
| 398 | |
| 399 | #endif |
| 400 | |
Greg Clayton | e86cbb9 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 401 | void |
| 402 | SBCommandInterpreter::InitializeSWIG () |
| 403 | { |
| 404 | static bool g_initialized = false; |
| 405 | if (!g_initialized) |
| 406 | { |
| 407 | g_initialized = true; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 408 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | 1328b14 | 2012-02-29 03:28:49 +0000 | [diff] [blame] | 409 | ScriptInterpreter::InitializeInterpreter (init_lldb); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 410 | #endif |
Greg Clayton | e86cbb9 | 2011-03-22 01:14:58 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
Greg Clayton | f125250 | 2012-02-29 04:21:24 +0000 | [diff] [blame] | 413 | |
Enrico Granata | 6d10188 | 2012-09-28 23:57:51 +0000 | [diff] [blame^] | 414 | lldb::SBCommand |
| 415 | SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help) |
| 416 | { |
| 417 | CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help); |
| 418 | new_command->SetRemovable (true); |
| 419 | lldb::CommandObjectSP new_command_sp(new_command); |
| 420 | if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) |
| 421 | return lldb::SBCommand(new_command_sp); |
| 422 | return lldb::SBCommand(); |
| 423 | } |
| 424 | |
| 425 | lldb::SBCommand |
| 426 | SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help) |
| 427 | { |
| 428 | lldb::CommandObjectSP new_command_sp; |
| 429 | new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help)); |
| 430 | |
| 431 | if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) |
| 432 | return lldb::SBCommand(new_command_sp); |
| 433 | return lldb::SBCommand(); |
| 434 | } |
| 435 | |
| 436 | SBCommand::SBCommand () |
| 437 | {} |
| 438 | |
| 439 | SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp) |
| 440 | {} |
| 441 | |
| 442 | bool |
| 443 | SBCommand::IsValid () |
| 444 | { |
| 445 | return (bool)m_opaque_sp; |
| 446 | } |
| 447 | |
| 448 | const char* |
| 449 | SBCommand::GetName () |
| 450 | { |
| 451 | if (IsValid ()) |
| 452 | return m_opaque_sp->GetCommandName (); |
| 453 | return NULL; |
| 454 | } |
| 455 | |
| 456 | const char* |
| 457 | SBCommand::GetHelp () |
| 458 | { |
| 459 | if (IsValid ()) |
| 460 | return m_opaque_sp->GetHelp (); |
| 461 | return NULL; |
| 462 | } |
| 463 | |
| 464 | lldb::SBCommand |
| 465 | SBCommand::AddMultiwordCommand (const char* name, const char* help) |
| 466 | { |
| 467 | if (!IsValid ()) |
| 468 | return lldb::SBCommand(); |
| 469 | if (m_opaque_sp->IsMultiwordObject() == false) |
| 470 | return lldb::SBCommand(); |
| 471 | CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help); |
| 472 | new_command->SetRemovable (true); |
| 473 | lldb::CommandObjectSP new_command_sp(new_command); |
| 474 | if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) |
| 475 | return lldb::SBCommand(new_command_sp); |
| 476 | return lldb::SBCommand(); |
| 477 | } |
| 478 | |
| 479 | lldb::SBCommand |
| 480 | SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help) |
| 481 | { |
| 482 | if (!IsValid ()) |
| 483 | return lldb::SBCommand(); |
| 484 | if (m_opaque_sp->IsMultiwordObject() == false) |
| 485 | return lldb::SBCommand(); |
| 486 | lldb::CommandObjectSP new_command_sp; |
| 487 | new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help)); |
| 488 | if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) |
| 489 | return lldb::SBCommand(new_command_sp); |
| 490 | return lldb::SBCommand(); |
| 491 | } |
| 492 | |