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