blob: 0c839004601ccb9317d8f55591eb64ab23038c69 [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/lldb-types.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Core/SourceManager.h"
14#include "lldb/Core/Listener.h"
15#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata21dfcd92012-09-28 23:57:51 +000016#include "lldb/Interpreter/CommandObjectMultiword.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Interpreter/CommandReturnObject.h"
18#include "lldb/Target/Target.h"
19
Eli Friedmanca93cc12010-06-09 07:37:52 +000020#include "lldb/API/SBBroadcaster.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000021#include "lldb/API/SBCommandReturnObject.h"
Eli Friedmanca93cc12010-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 Ticeceb6b132010-10-26 03:11:13 +000026#include "lldb/API/SBStream.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000027#include "lldb/API/SBStringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29using namespace lldb;
30using namespace lldb_private;
31
Enrico Granata21dfcd92012-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 Clayton3a18e312012-10-08 22:41:53 +000045 IsRemovable() const { return true; }
Enrico Granata21dfcd92012-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 Lattner30fdc8d2010-06-08 16:52:24 +000060
Greg Clayton66111032010-06-23 01:19:29 +000061SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) :
62 m_opaque_ptr (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063{
Greg Clayton5160ce52013-03-27 23:08:40 +000064 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000065
66 if (log)
Greg Clayton48381312010-10-30 04:51:46 +000067 log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)"
68 " => SBCommandInterpreter(%p)", interpreter, m_opaque_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069}
70
Greg Claytonefabb122010-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 Lattner30fdc8d2010-06-08 16:52:24 +000083SBCommandInterpreter::~SBCommandInterpreter ()
84{
85}
86
87bool
Greg Clayton66111032010-06-23 01:19:29 +000088SBCommandInterpreter::IsValid() const
89{
90 return m_opaque_ptr != NULL;
91}
92
93
94bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095SBCommandInterpreter::CommandExists (const char *cmd)
96{
Johnny Chen872e0622011-12-19 21:16:29 +000097 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +000098 return m_opaque_ptr->CommandExists (cmd);
99 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100}
101
102bool
103SBCommandInterpreter::AliasExists (const char *cmd)
104{
Johnny Chen872e0622011-12-19 21:16:29 +0000105 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000106 return m_opaque_ptr->AliasExists (cmd);
107 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108}
109
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110lldb::ReturnStatus
111SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
112{
Greg Clayton5160ce52013-03-27 23:08:40 +0000113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000114
115 if (log)
Greg Claytoncfd1ace2010-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 Ticeceb6b132010-10-26 03:11:13 +0000118
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119 result.Clear();
Johnny Chen872e0622011-12-19 21:16:29 +0000120 if (command_line && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000121 {
Enrico Granata5f5ab602012-05-31 01:09:06 +0000122 m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref());
Greg Clayton66111032010-06-23 01:19:29 +0000123 }
124 else
125 {
Johnny Chen872e0622011-12-19 21:16:29 +0000126 result->AppendError ("SBCommandInterpreter or the command line is not valid");
Greg Clayton66111032010-06-23 01:19:29 +0000127 result->SetStatus (eReturnStatusFailed);
128 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000129
Caroline Tice7b9da4a2010-10-27 21:23:37 +0000130 // We need to get the value again, in case the command disabled the log!
131 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000132 if (log)
133 {
134 SBStream sstr;
135 result.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000136 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i",
137 m_opaque_ptr, command_line, result.get(), sstr.GetData(), add_to_history, result.GetStatus());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000138 }
139
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140 return result.GetStatus();
141}
142
143int
144SBCommandInterpreter::HandleCompletion (const char *current_line,
145 const char *cursor,
146 const char *last_char,
147 int match_start_point,
148 int max_return_elements,
149 SBStringList &matches)
150{
Greg Clayton5160ce52013-03-27 23:08:40 +0000151 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton66111032010-06-23 01:19:29 +0000152 int num_completions = 0;
Jim Inghamac012602011-12-05 19:24:15 +0000153
154 // Sanity check the arguments that are passed in:
155 // cursor & last_char have to be within the current_line.
156 if (current_line == NULL || cursor == NULL || last_char == NULL)
157 return 0;
158
159 if (cursor < current_line || last_char < current_line)
160 return 0;
161
162 size_t current_line_size = strlen (current_line);
163 if (cursor - current_line > current_line_size || last_char - current_line > current_line_size)
164 return 0;
165
Jim Ingham389512d2012-06-26 01:21:59 +0000166 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000167 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)",
Jason Molenda24a83782012-07-17 01:57:24 +0000168 m_opaque_ptr, current_line, (uint64_t) (cursor - current_line), (uint64_t) (last_char - current_line), match_start_point, max_return_elements);
Jim Ingham389512d2012-06-26 01:21:59 +0000169
Greg Clayton66111032010-06-23 01:19:29 +0000170 if (m_opaque_ptr)
171 {
172 lldb_private::StringList lldb_matches;
173 num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point,
174 max_return_elements, lldb_matches);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175
Greg Clayton66111032010-06-23 01:19:29 +0000176 SBStringList temp_list (&lldb_matches);
177 matches.AppendList (temp_list);
178 }
Jim Ingham389512d2012-06-26 01:21:59 +0000179 if (log)
180 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", m_opaque_ptr, num_completions);
181
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 return num_completions;
183}
184
Jim Ingham969795f2011-09-21 01:17:13 +0000185int
186SBCommandInterpreter::HandleCompletion (const char *current_line,
187 uint32_t cursor_pos,
188 int match_start_point,
189 int max_return_elements,
190 lldb::SBStringList &matches)
191{
192 const char *cursor = current_line + cursor_pos;
193 const char *last_char = current_line + strlen (current_line);
194 return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches);
195}
196
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197bool
198SBCommandInterpreter::HasCommands ()
199{
Greg Clayton66111032010-06-23 01:19:29 +0000200 if (m_opaque_ptr)
201 return m_opaque_ptr->HasCommands();
202 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203}
204
205bool
206SBCommandInterpreter::HasAliases ()
207{
Greg Clayton66111032010-06-23 01:19:29 +0000208 if (m_opaque_ptr)
209 return m_opaque_ptr->HasAliases();
210 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
213bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214SBCommandInterpreter::HasAliasOptions ()
215{
Greg Clayton66111032010-06-23 01:19:29 +0000216 if (m_opaque_ptr)
217 return m_opaque_ptr->HasAliasOptions ();
218 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219}
220
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221SBProcess
222SBCommandInterpreter::GetProcess ()
223{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000224 SBProcess sb_process;
225 ProcessSP process_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000226 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000228 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
229 if (target_sp)
230 {
231 Mutex::Locker api_locker(target_sp->GetAPIMutex());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000232 process_sp = target_sp->GetProcessSP();
233 sb_process.SetSP(process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000234 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000236 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000237
238 if (log)
239 log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
Greg Claytonb9556ac2012-01-30 07:41:31 +0000240 m_opaque_ptr, process_sp.get());
Greg Clayton48381312010-10-30 04:51:46 +0000241
242
Greg Claytonb9556ac2012-01-30 07:41:31 +0000243 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244}
245
Enrico Granata21dfcd92012-09-28 23:57:51 +0000246SBDebugger
247SBCommandInterpreter::GetDebugger ()
248{
249 SBDebugger sb_debugger;
250 if (m_opaque_ptr)
251 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
Greg Clayton5160ce52013-03-27 23:08:40 +0000252 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata21dfcd92012-09-28 23:57:51 +0000253
254 if (log)
255 log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)",
256 m_opaque_ptr, sb_debugger.get());
257
258
259 return sb_debugger;
260}
261
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262CommandInterpreter *
Greg Clayton66111032010-06-23 01:19:29 +0000263SBCommandInterpreter::get ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264{
Greg Clayton66111032010-06-23 01:19:29 +0000265 return m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266}
267
268CommandInterpreter &
Greg Clayton66111032010-06-23 01:19:29 +0000269SBCommandInterpreter::ref ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270{
Greg Clayton66111032010-06-23 01:19:29 +0000271 assert (m_opaque_ptr);
272 return *m_opaque_ptr;
273}
274
275void
276SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
277{
278 m_opaque_ptr = interpreter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279}
280
281void
282SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
283{
284 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000285 if (m_opaque_ptr)
286 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000287 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
288 Mutex::Locker api_locker;
289 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000290 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000291 m_opaque_ptr->SourceInitFile (false, result.ref());
292 }
293 else
294 {
295 result->AppendError ("SBCommandInterpreter is not valid");
296 result->SetStatus (eReturnStatusFailed);
297 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000298 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000299
300 if (log)
301 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))",
302 m_opaque_ptr, result.get());
303
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304}
305
306void
307SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
308{
309 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000310 if (m_opaque_ptr)
311 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000312 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
313 Mutex::Locker api_locker;
314 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000315 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000316 m_opaque_ptr->SourceInitFile (true, result.ref());
317 }
318 else
319 {
320 result->AppendError ("SBCommandInterpreter is not valid");
321 result->SetStatus (eReturnStatusFailed);
322 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000323 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000324
325 if (log)
326 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))",
327 m_opaque_ptr, result.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328}
329
330SBBroadcaster
331SBCommandInterpreter::GetBroadcaster ()
332{
Greg Clayton5160ce52013-03-27 23:08:40 +0000333 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000334
Greg Clayton66111032010-06-23 01:19:29 +0000335 SBBroadcaster broadcaster (m_opaque_ptr, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000336
337 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000338 log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)",
Caroline Tice750cd172010-10-26 23:49:36 +0000339 m_opaque_ptr, broadcaster.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000340
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341 return broadcaster;
342}
343
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000344const char *
345SBCommandInterpreter::GetBroadcasterClass ()
346{
347 return Communication::GetStaticBroadcasterClass().AsCString();
348}
349
Greg Clayton9d0402b2011-02-20 02:15:07 +0000350const char *
351SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
352{
353 return CommandObject::GetArgumentTypeAsCString (arg_type);
354}
355
356const char *
357SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
358{
359 return CommandObject::GetArgumentDescriptionAsCString (arg_type);
360}
361
Greg Claytona9f7b792012-02-29 04:21:24 +0000362bool
363SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name,
364 lldb::CommandOverrideCallback callback,
365 void *baton)
366{
367 if (command_name && command_name[0] && m_opaque_ptr)
368 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000369 std::string command_name_str (command_name);
370 CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
Greg Claytona9f7b792012-02-29 04:21:24 +0000371 if (cmd_obj)
372 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000373 assert(command_name_str.empty());
Greg Claytona9f7b792012-02-29 04:21:24 +0000374 cmd_obj->SetOverrideCallback (callback, baton);
375 return true;
376 }
377 }
378 return false;
379}
Greg Clayton9d0402b2011-02-20 02:15:07 +0000380
Greg Claytondce502e2011-11-04 03:34:56 +0000381#ifndef LLDB_DISABLE_PYTHON
Enrico Granatabe93a352011-08-16 16:49:25 +0000382
Greg Claytondce502e2011-11-04 03:34:56 +0000383// Defined in the SWIG source file
384extern "C" void
385init_lldb(void);
386
Greg Claytondce502e2011-11-04 03:34:56 +0000387#else
Enrico Granatabe93a352011-08-16 16:49:25 +0000388
Greg Claytonfc36f7912011-03-22 01:14:58 +0000389extern "C" void init_lldb(void);
390
Greg Claytondce502e2011-11-04 03:34:56 +0000391// Usually defined in the SWIG source file, but we have sripting disabled
392extern "C" void
393init_lldb(void)
394{
395}
396
397#endif
398
Greg Claytonfc36f7912011-03-22 01:14:58 +0000399void
400SBCommandInterpreter::InitializeSWIG ()
401{
402 static bool g_initialized = false;
403 if (!g_initialized)
404 {
405 g_initialized = true;
Greg Claytondce502e2011-11-04 03:34:56 +0000406#ifndef LLDB_DISABLE_PYTHON
Enrico Granata7bc0ec32012-02-29 03:28:49 +0000407 ScriptInterpreter::InitializeInterpreter (init_lldb);
Greg Claytondce502e2011-11-04 03:34:56 +0000408#endif
Greg Claytonfc36f7912011-03-22 01:14:58 +0000409 }
410}
Greg Claytona9f7b792012-02-29 04:21:24 +0000411
Enrico Granata21dfcd92012-09-28 23:57:51 +0000412lldb::SBCommand
413SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help)
414{
415 CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help);
416 new_command->SetRemovable (true);
417 lldb::CommandObjectSP new_command_sp(new_command);
418 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
419 return lldb::SBCommand(new_command_sp);
420 return lldb::SBCommand();
421}
422
423lldb::SBCommand
424SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help)
425{
426 lldb::CommandObjectSP new_command_sp;
427 new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help));
428
429 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
430 return lldb::SBCommand(new_command_sp);
431 return lldb::SBCommand();
432}
433
434SBCommand::SBCommand ()
435{}
436
437SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp)
438{}
439
440bool
441SBCommand::IsValid ()
442{
443 return (bool)m_opaque_sp;
444}
445
446const char*
447SBCommand::GetName ()
448{
449 if (IsValid ())
450 return m_opaque_sp->GetCommandName ();
451 return NULL;
452}
453
454const char*
455SBCommand::GetHelp ()
456{
457 if (IsValid ())
458 return m_opaque_sp->GetHelp ();
459 return NULL;
460}
461
462lldb::SBCommand
463SBCommand::AddMultiwordCommand (const char* name, const char* help)
464{
465 if (!IsValid ())
466 return lldb::SBCommand();
467 if (m_opaque_sp->IsMultiwordObject() == false)
468 return lldb::SBCommand();
469 CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help);
470 new_command->SetRemovable (true);
471 lldb::CommandObjectSP new_command_sp(new_command);
472 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
473 return lldb::SBCommand(new_command_sp);
474 return lldb::SBCommand();
475}
476
477lldb::SBCommand
478SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help)
479{
480 if (!IsValid ())
481 return lldb::SBCommand();
482 if (m_opaque_sp->IsMultiwordObject() == false)
483 return lldb::SBCommand();
484 lldb::CommandObjectSP new_command_sp;
485 new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help));
486 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
487 return lldb::SBCommand(new_command_sp);
488 return lldb::SBCommand();
489}
490