blob: ac387331917404a1966afb284bee442f958ca190 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/lldb-types.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/Core/SourceManager.h"
14#include "lldb/Core/Listener.h"
15#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata6d101882012-09-28 23:57:51 +000016#include "lldb/Interpreter/CommandObjectMultiword.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Interpreter/CommandReturnObject.h"
18#include "lldb/Target/Target.h"
19
Eli Friedmand6ec8aa2010-06-09 07:37:52 +000020#include "lldb/API/SBBroadcaster.h"
Eli Friedmand6ec8aa2010-06-09 07:37:52 +000021#include "lldb/API/SBCommandReturnObject.h"
Eli Friedmand6ec8aa2010-06-09 07:37:52 +000022#include "lldb/API/SBCommandInterpreter.h"
23#include "lldb/API/SBProcess.h"
24#include "lldb/API/SBTarget.h"
25#include "lldb/API/SBListener.h"
Caroline Tice7826c882010-10-26 03:11:13 +000026#include "lldb/API/SBStream.h"
Eli Friedmand6ec8aa2010-06-09 07:37:52 +000027#include "lldb/API/SBStringList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028
29using namespace lldb;
30using namespace lldb_private;
31
Enrico Granata6d101882012-09-28 23:57:51 +000032class CommandPluginInterfaceImplementation : public CommandObjectParsed
33{
34public:
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 Claytonf737d372012-10-08 22:41:53 +000045 IsRemovable() const { return true; }
Enrico Granata6d101882012-09-28 23:57:51 +000046
47protected:
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 Lattner24943d22010-06-08 16:52:24 +000060
Greg Clayton63094e02010-06-23 01:19:29 +000061SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) :
62 m_opaque_ptr (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +000063{
Greg Claytone005f2c2010-11-06 01:53:30 +000064 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000065
66 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000067 log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)"
68 " => SBCommandInterpreter(%p)", interpreter, m_opaque_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +000069}
70
Greg Clayton538eb822010-11-05 23:17:00 +000071SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) :
72 m_opaque_ptr (rhs.m_opaque_ptr)
73{
74}
75
76const SBCommandInterpreter &
77SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs)
78{
79 m_opaque_ptr = rhs.m_opaque_ptr;
80 return *this;
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083SBCommandInterpreter::~SBCommandInterpreter ()
84{
85}
86
87bool
Greg Clayton63094e02010-06-23 01:19:29 +000088SBCommandInterpreter::IsValid() const
89{
90 return m_opaque_ptr != NULL;
91}
92
93
94bool
Chris Lattner24943d22010-06-08 16:52:24 +000095SBCommandInterpreter::CommandExists (const char *cmd)
96{
Johnny Chenbab8cc92011-12-19 21:16:29 +000097 if (cmd && m_opaque_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000098 return m_opaque_ptr->CommandExists (cmd);
99 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000100}
101
102bool
103SBCommandInterpreter::AliasExists (const char *cmd)
104{
Johnny Chenbab8cc92011-12-19 21:16:29 +0000105 if (cmd && m_opaque_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +0000106 return m_opaque_ptr->AliasExists (cmd);
107 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000108}
109
Chris Lattner24943d22010-06-08 16:52:24 +0000110lldb::ReturnStatus
111SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
112{
Greg Claytone005f2c2010-11-06 01:53:30 +0000113 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000114
115 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000116 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 Tice7826c882010-10-26 03:11:13 +0000118
Chris Lattner24943d22010-06-08 16:52:24 +0000119 result.Clear();
Johnny Chenbab8cc92011-12-19 21:16:29 +0000120 if (command_line && m_opaque_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +0000121 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000122 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
123 Mutex::Locker api_locker;
124 if (target_sp)
Jim Ingham1b584eb2012-05-04 23:02:50 +0000125 api_locker.Lock(target_sp->GetAPIMutex());
Enrico Granata01bc2d42012-05-31 01:09:06 +0000126 m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref());
Greg Clayton63094e02010-06-23 01:19:29 +0000127 }
128 else
129 {
Johnny Chenbab8cc92011-12-19 21:16:29 +0000130 result->AppendError ("SBCommandInterpreter or the command line is not valid");
Greg Clayton63094e02010-06-23 01:19:29 +0000131 result->SetStatus (eReturnStatusFailed);
132 }
Caroline Tice7826c882010-10-26 03:11:13 +0000133
Caroline Tice7de24cc2010-10-27 21:23:37 +0000134 // We need to get the value again, in case the command disabled the log!
135 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000136 if (log)
137 {
138 SBStream sstr;
139 result.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000140 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 Tice7826c882010-10-26 03:11:13 +0000142 }
143
Chris Lattner24943d22010-06-08 16:52:24 +0000144 return result.GetStatus();
145}
146
147int
148SBCommandInterpreter::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 Inghambc8c4992012-06-26 01:21:59 +0000155 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton63094e02010-06-23 01:19:29 +0000156 int num_completions = 0;
Jim Ingham3cbf8482011-12-05 19:24:15 +0000157
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 Inghambc8c4992012-06-26 01:21:59 +0000170 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000171 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)",
Jason Molendaa092d902012-07-17 01:57:24 +0000172 m_opaque_ptr, current_line, (uint64_t) (cursor - current_line), (uint64_t) (last_char - current_line), match_start_point, max_return_elements);
Jim Inghambc8c4992012-06-26 01:21:59 +0000173
Greg Clayton63094e02010-06-23 01:19:29 +0000174 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 Lattner24943d22010-06-08 16:52:24 +0000179
Greg Clayton63094e02010-06-23 01:19:29 +0000180 SBStringList temp_list (&lldb_matches);
181 matches.AppendList (temp_list);
182 }
Jim Inghambc8c4992012-06-26 01:21:59 +0000183 if (log)
184 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", m_opaque_ptr, num_completions);
185
Chris Lattner24943d22010-06-08 16:52:24 +0000186 return num_completions;
187}
188
Jim Ingham03c8ee52011-09-21 01:17:13 +0000189int
190SBCommandInterpreter::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 Lattner24943d22010-06-08 16:52:24 +0000201bool
202SBCommandInterpreter::HasCommands ()
203{
Greg Clayton63094e02010-06-23 01:19:29 +0000204 if (m_opaque_ptr)
205 return m_opaque_ptr->HasCommands();
206 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000207}
208
209bool
210SBCommandInterpreter::HasAliases ()
211{
Greg Clayton63094e02010-06-23 01:19:29 +0000212 if (m_opaque_ptr)
213 return m_opaque_ptr->HasAliases();
214 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000215}
216
217bool
Chris Lattner24943d22010-06-08 16:52:24 +0000218SBCommandInterpreter::HasAliasOptions ()
219{
Greg Clayton63094e02010-06-23 01:19:29 +0000220 if (m_opaque_ptr)
221 return m_opaque_ptr->HasAliasOptions ();
222 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000223}
224
Chris Lattner24943d22010-06-08 16:52:24 +0000225SBProcess
226SBCommandInterpreter::GetProcess ()
227{
Greg Clayton334d33a2012-01-30 07:41:31 +0000228 SBProcess sb_process;
229 ProcessSP process_sp;
Greg Clayton63094e02010-06-23 01:19:29 +0000230 if (m_opaque_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +0000231 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000232 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
233 if (target_sp)
234 {
235 Mutex::Locker api_locker(target_sp->GetAPIMutex());
Greg Clayton334d33a2012-01-30 07:41:31 +0000236 process_sp = target_sp->GetProcessSP();
237 sb_process.SetSP(process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000238 }
Chris Lattner24943d22010-06-08 16:52:24 +0000239 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000241
242 if (log)
243 log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000244 m_opaque_ptr, process_sp.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000245
246
Greg Clayton334d33a2012-01-30 07:41:31 +0000247 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000248}
249
Enrico Granata6d101882012-09-28 23:57:51 +0000250SBDebugger
251SBCommandInterpreter::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 Lattner24943d22010-06-08 16:52:24 +0000266CommandInterpreter *
Greg Clayton63094e02010-06-23 01:19:29 +0000267SBCommandInterpreter::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000268{
Greg Clayton63094e02010-06-23 01:19:29 +0000269 return m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000270}
271
272CommandInterpreter &
Greg Clayton63094e02010-06-23 01:19:29 +0000273SBCommandInterpreter::ref ()
Chris Lattner24943d22010-06-08 16:52:24 +0000274{
Greg Clayton63094e02010-06-23 01:19:29 +0000275 assert (m_opaque_ptr);
276 return *m_opaque_ptr;
277}
278
279void
280SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
281{
282 m_opaque_ptr = interpreter;
Chris Lattner24943d22010-06-08 16:52:24 +0000283}
284
285void
286SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
287{
288 result.Clear();
Greg Clayton63094e02010-06-23 01:19:29 +0000289 if (m_opaque_ptr)
290 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000291 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
292 Mutex::Locker api_locker;
293 if (target_sp)
Jim Ingham1b584eb2012-05-04 23:02:50 +0000294 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000295 m_opaque_ptr->SourceInitFile (false, result.ref());
296 }
297 else
298 {
299 result->AppendError ("SBCommandInterpreter is not valid");
300 result->SetStatus (eReturnStatusFailed);
301 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000302 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000303
304 if (log)
305 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))",
306 m_opaque_ptr, result.get());
307
Chris Lattner24943d22010-06-08 16:52:24 +0000308}
309
310void
311SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
312{
313 result.Clear();
Greg Clayton63094e02010-06-23 01:19:29 +0000314 if (m_opaque_ptr)
315 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000316 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
317 Mutex::Locker api_locker;
318 if (target_sp)
Jim Ingham1b584eb2012-05-04 23:02:50 +0000319 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000320 m_opaque_ptr->SourceInitFile (true, result.ref());
321 }
322 else
323 {
324 result->AppendError ("SBCommandInterpreter is not valid");
325 result->SetStatus (eReturnStatusFailed);
326 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000327 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000328
329 if (log)
330 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))",
331 m_opaque_ptr, result.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000332}
333
334SBBroadcaster
335SBCommandInterpreter::GetBroadcaster ()
336{
Greg Claytone005f2c2010-11-06 01:53:30 +0000337 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000338
Greg Clayton63094e02010-06-23 01:19:29 +0000339 SBBroadcaster broadcaster (m_opaque_ptr, false);
Caroline Tice7826c882010-10-26 03:11:13 +0000340
341 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000342 log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000343 m_opaque_ptr, broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000344
Chris Lattner24943d22010-06-08 16:52:24 +0000345 return broadcaster;
346}
347
Jim Ingham5a15e692012-02-16 06:50:00 +0000348const char *
349SBCommandInterpreter::GetBroadcasterClass ()
350{
351 return Communication::GetStaticBroadcasterClass().AsCString();
352}
353
Greg Claytonaa378b12011-02-20 02:15:07 +0000354const char *
355SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
356{
357 return CommandObject::GetArgumentTypeAsCString (arg_type);
358}
359
360const char *
361SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
362{
363 return CommandObject::GetArgumentDescriptionAsCString (arg_type);
364}
365
Greg Claytonf1252502012-02-29 04:21:24 +0000366bool
367SBCommandInterpreter::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 Clayton5f2b9262012-05-08 04:29:20 +0000373 std::string command_name_str (command_name);
374 CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
Greg Claytonf1252502012-02-29 04:21:24 +0000375 if (cmd_obj)
376 {
Greg Clayton5f2b9262012-05-08 04:29:20 +0000377 assert(command_name_str.empty());
Greg Claytonf1252502012-02-29 04:21:24 +0000378 cmd_obj->SetOverrideCallback (callback, baton);
379 return true;
380 }
381 }
382 return false;
383}
Greg Claytonaa378b12011-02-20 02:15:07 +0000384
Greg Clayton3e4238d2011-11-04 03:34:56 +0000385#ifndef LLDB_DISABLE_PYTHON
Enrico Granatac2a28252011-08-16 16:49:25 +0000386
Greg Clayton3e4238d2011-11-04 03:34:56 +0000387// Defined in the SWIG source file
388extern "C" void
389init_lldb(void);
390
Greg Clayton3e4238d2011-11-04 03:34:56 +0000391#else
Enrico Granatac2a28252011-08-16 16:49:25 +0000392
Greg Claytone86cbb92011-03-22 01:14:58 +0000393extern "C" void init_lldb(void);
394
Greg Clayton3e4238d2011-11-04 03:34:56 +0000395// Usually defined in the SWIG source file, but we have sripting disabled
396extern "C" void
397init_lldb(void)
398{
399}
400
401#endif
402
Greg Claytone86cbb92011-03-22 01:14:58 +0000403void
404SBCommandInterpreter::InitializeSWIG ()
405{
406 static bool g_initialized = false;
407 if (!g_initialized)
408 {
409 g_initialized = true;
Greg Clayton3e4238d2011-11-04 03:34:56 +0000410#ifndef LLDB_DISABLE_PYTHON
Enrico Granata1328b142012-02-29 03:28:49 +0000411 ScriptInterpreter::InitializeInterpreter (init_lldb);
Greg Clayton3e4238d2011-11-04 03:34:56 +0000412#endif
Greg Claytone86cbb92011-03-22 01:14:58 +0000413 }
414}
Greg Claytonf1252502012-02-29 04:21:24 +0000415
Enrico Granata6d101882012-09-28 23:57:51 +0000416lldb::SBCommand
417SBCommandInterpreter::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
427lldb::SBCommand
428SBCommandInterpreter::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
438SBCommand::SBCommand ()
439{}
440
441SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp)
442{}
443
444bool
445SBCommand::IsValid ()
446{
447 return (bool)m_opaque_sp;
448}
449
450const char*
451SBCommand::GetName ()
452{
453 if (IsValid ())
454 return m_opaque_sp->GetCommandName ();
455 return NULL;
456}
457
458const char*
459SBCommand::GetHelp ()
460{
461 if (IsValid ())
462 return m_opaque_sp->GetHelp ();
463 return NULL;
464}
465
466lldb::SBCommand
467SBCommand::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
481lldb::SBCommand
482SBCommand::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