blob: f1faa13ba981c8f1e5b307f9cd77bd131f659639 [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
Greg Clayton44d93782014-01-27 23:43:24 +0000110bool
111SBCommandInterpreter::IsActive ()
112{
113 if (m_opaque_ptr)
114 return m_opaque_ptr->IsActive ();
115 return false;
116}
117
118const char *
119SBCommandInterpreter::GetIOHandlerControlSequence(char ch)
120{
121 if (m_opaque_ptr)
122 return m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence (ch).GetCString();
123 return NULL;
124}
125
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126lldb::ReturnStatus
127SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
128{
Greg Clayton5160ce52013-03-27 23:08:40 +0000129 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000130
131 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000132 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)",
133 m_opaque_ptr, command_line, result.get(), add_to_history);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000134
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 result.Clear();
Johnny Chen872e0622011-12-19 21:16:29 +0000136 if (command_line && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000137 {
Enrico Granata5f5ab602012-05-31 01:09:06 +0000138 m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref());
Greg Clayton66111032010-06-23 01:19:29 +0000139 }
140 else
141 {
Johnny Chen872e0622011-12-19 21:16:29 +0000142 result->AppendError ("SBCommandInterpreter or the command line is not valid");
Greg Clayton66111032010-06-23 01:19:29 +0000143 result->SetStatus (eReturnStatusFailed);
144 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000145
Caroline Tice7b9da4a2010-10-27 21:23:37 +0000146 // We need to get the value again, in case the command disabled the log!
147 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000148 if (log)
149 {
150 SBStream sstr;
151 result.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000152 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i",
153 m_opaque_ptr, command_line, result.get(), sstr.GetData(), add_to_history, result.GetStatus());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000154 }
155
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 return result.GetStatus();
157}
158
159int
160SBCommandInterpreter::HandleCompletion (const char *current_line,
161 const char *cursor,
162 const char *last_char,
163 int match_start_point,
164 int max_return_elements,
165 SBStringList &matches)
166{
Greg Clayton5160ce52013-03-27 23:08:40 +0000167 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton66111032010-06-23 01:19:29 +0000168 int num_completions = 0;
Jim Inghamac012602011-12-05 19:24:15 +0000169
170 // Sanity check the arguments that are passed in:
171 // cursor & last_char have to be within the current_line.
172 if (current_line == NULL || cursor == NULL || last_char == NULL)
173 return 0;
174
175 if (cursor < current_line || last_char < current_line)
176 return 0;
177
178 size_t current_line_size = strlen (current_line);
179 if (cursor - current_line > current_line_size || last_char - current_line > current_line_size)
180 return 0;
181
Jim Ingham389512d2012-06-26 01:21:59 +0000182 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000183 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 +0000184 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 +0000185
Greg Clayton66111032010-06-23 01:19:29 +0000186 if (m_opaque_ptr)
187 {
188 lldb_private::StringList lldb_matches;
189 num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point,
190 max_return_elements, lldb_matches);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191
Greg Clayton66111032010-06-23 01:19:29 +0000192 SBStringList temp_list (&lldb_matches);
193 matches.AppendList (temp_list);
194 }
Jim Ingham389512d2012-06-26 01:21:59 +0000195 if (log)
196 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", m_opaque_ptr, num_completions);
197
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 return num_completions;
199}
200
Jim Ingham969795f2011-09-21 01:17:13 +0000201int
202SBCommandInterpreter::HandleCompletion (const char *current_line,
203 uint32_t cursor_pos,
204 int match_start_point,
205 int max_return_elements,
206 lldb::SBStringList &matches)
207{
208 const char *cursor = current_line + cursor_pos;
209 const char *last_char = current_line + strlen (current_line);
210 return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches);
211}
212
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213bool
214SBCommandInterpreter::HasCommands ()
215{
Greg Clayton66111032010-06-23 01:19:29 +0000216 if (m_opaque_ptr)
217 return m_opaque_ptr->HasCommands();
218 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219}
220
221bool
222SBCommandInterpreter::HasAliases ()
223{
Greg Clayton66111032010-06-23 01:19:29 +0000224 if (m_opaque_ptr)
225 return m_opaque_ptr->HasAliases();
226 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227}
228
229bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230SBCommandInterpreter::HasAliasOptions ()
231{
Greg Clayton66111032010-06-23 01:19:29 +0000232 if (m_opaque_ptr)
233 return m_opaque_ptr->HasAliasOptions ();
234 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235}
236
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237SBProcess
238SBCommandInterpreter::GetProcess ()
239{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000240 SBProcess sb_process;
241 ProcessSP process_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000242 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000244 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
245 if (target_sp)
246 {
247 Mutex::Locker api_locker(target_sp->GetAPIMutex());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000248 process_sp = target_sp->GetProcessSP();
249 sb_process.SetSP(process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000250 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000252 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000253
254 if (log)
255 log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
Greg Claytonb9556ac2012-01-30 07:41:31 +0000256 m_opaque_ptr, process_sp.get());
Greg Clayton48381312010-10-30 04:51:46 +0000257
258
Greg Claytonb9556ac2012-01-30 07:41:31 +0000259 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000260}
261
Enrico Granata21dfcd92012-09-28 23:57:51 +0000262SBDebugger
263SBCommandInterpreter::GetDebugger ()
264{
265 SBDebugger sb_debugger;
266 if (m_opaque_ptr)
267 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
Greg Clayton5160ce52013-03-27 23:08:40 +0000268 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata21dfcd92012-09-28 23:57:51 +0000269
270 if (log)
271 log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)",
272 m_opaque_ptr, sb_debugger.get());
273
274
275 return sb_debugger;
276}
277
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278CommandInterpreter *
Greg Clayton66111032010-06-23 01:19:29 +0000279SBCommandInterpreter::get ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280{
Greg Clayton66111032010-06-23 01:19:29 +0000281 return m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
284CommandInterpreter &
Greg Clayton66111032010-06-23 01:19:29 +0000285SBCommandInterpreter::ref ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286{
Greg Clayton66111032010-06-23 01:19:29 +0000287 assert (m_opaque_ptr);
288 return *m_opaque_ptr;
289}
290
291void
292SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
293{
294 m_opaque_ptr = interpreter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295}
296
297void
298SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
299{
300 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000301 if (m_opaque_ptr)
302 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000303 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
304 Mutex::Locker api_locker;
305 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000306 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000307 m_opaque_ptr->SourceInitFile (false, result.ref());
308 }
309 else
310 {
311 result->AppendError ("SBCommandInterpreter is not valid");
312 result->SetStatus (eReturnStatusFailed);
313 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000314 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000315
316 if (log)
317 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))",
318 m_opaque_ptr, result.get());
319
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320}
321
322void
323SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
324{
325 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000326 if (m_opaque_ptr)
327 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000328 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
329 Mutex::Locker api_locker;
330 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000331 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000332 m_opaque_ptr->SourceInitFile (true, result.ref());
333 }
334 else
335 {
336 result->AppendError ("SBCommandInterpreter is not valid");
337 result->SetStatus (eReturnStatusFailed);
338 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000339 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000340
341 if (log)
342 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))",
343 m_opaque_ptr, result.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344}
345
346SBBroadcaster
347SBCommandInterpreter::GetBroadcaster ()
348{
Greg Clayton5160ce52013-03-27 23:08:40 +0000349 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000350
Greg Clayton66111032010-06-23 01:19:29 +0000351 SBBroadcaster broadcaster (m_opaque_ptr, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000352
353 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000354 log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)",
Caroline Tice750cd172010-10-26 23:49:36 +0000355 m_opaque_ptr, broadcaster.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000356
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357 return broadcaster;
358}
359
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000360const char *
361SBCommandInterpreter::GetBroadcasterClass ()
362{
363 return Communication::GetStaticBroadcasterClass().AsCString();
364}
365
Greg Clayton9d0402b2011-02-20 02:15:07 +0000366const char *
367SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
368{
369 return CommandObject::GetArgumentTypeAsCString (arg_type);
370}
371
372const char *
373SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
374{
375 return CommandObject::GetArgumentDescriptionAsCString (arg_type);
376}
377
Greg Claytona9f7b792012-02-29 04:21:24 +0000378bool
379SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name,
380 lldb::CommandOverrideCallback callback,
381 void *baton)
382{
383 if (command_name && command_name[0] && m_opaque_ptr)
384 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000385 std::string command_name_str (command_name);
386 CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
Greg Claytona9f7b792012-02-29 04:21:24 +0000387 if (cmd_obj)
388 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000389 assert(command_name_str.empty());
Greg Claytona9f7b792012-02-29 04:21:24 +0000390 cmd_obj->SetOverrideCallback (callback, baton);
391 return true;
392 }
393 }
394 return false;
395}
Greg Clayton9d0402b2011-02-20 02:15:07 +0000396
Greg Claytondce502e2011-11-04 03:34:56 +0000397#ifndef LLDB_DISABLE_PYTHON
Enrico Granatabe93a352011-08-16 16:49:25 +0000398
Greg Claytondce502e2011-11-04 03:34:56 +0000399// Defined in the SWIG source file
400extern "C" void
401init_lldb(void);
402
Greg Clayton8afa5432013-10-17 00:27:14 +0000403// these are the Pythonic implementations of the required callbacks
404// these are scripting-language specific, which is why they belong here
405// we still need to use function pointers to them instead of relying
406// on linkage-time resolution because the SWIG stuff and this file
407// get built at different times
408extern "C" bool
409LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
410 const char *session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000411 const lldb::StackFrameSP& sb_frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000412 const lldb::BreakpointLocationSP& sb_bp_loc);
Enrico Granatabe93a352011-08-16 16:49:25 +0000413
Greg Clayton8afa5432013-10-17 00:27:14 +0000414extern "C" bool
415LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
416 const char *session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000417 const lldb::StackFrameSP& sb_frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000418 const lldb::WatchpointSP& sb_wp);
Greg Claytonfc36f7912011-03-22 01:14:58 +0000419
Greg Clayton8afa5432013-10-17 00:27:14 +0000420extern "C" bool
421LLDBSwigPythonCallTypeScript (const char *python_function_name,
422 void *session_dictionary,
423 const lldb::ValueObjectSP& valobj_sp,
424 void** pyfunct_wrapper,
425 std::string& retval);
426
427extern "C" void*
428LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
429 const char *session_dictionary_name,
430 const lldb::ValueObjectSP& valobj_sp);
431
432
433extern "C" uint32_t
434LLDBSwigPython_CalculateNumChildren (void *implementor);
435
436extern "C" void *
437LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
438
439extern "C" int
440LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
441
442extern "C" void *
443LLDBSWIGPython_CastPyObjectToSBValue (void* data);
444
445extern lldb::ValueObjectSP
446LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
447
448extern "C" bool
449LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
450
451extern "C" bool
452LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
453
454extern "C" bool
455LLDBSwigPythonCallCommand (const char *python_function_name,
456 const char *session_dictionary_name,
457 lldb::DebuggerSP& debugger,
458 const char* args,
459 lldb_private::CommandReturnObject &cmd_retobj);
460
461extern "C" bool
462LLDBSwigPythonCallModuleInit (const char *python_module_name,
463 const char *session_dictionary_name,
464 lldb::DebuggerSP& debugger);
465
466extern "C" void*
467LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
468 const char *session_dictionary_name,
469 const lldb::ProcessSP& process_sp);
470
471extern "C" bool
472LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
473 const char* session_dictionary_name,
474 lldb::ProcessSP& process,
475 std::string& output);
476
477extern "C" bool
478LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
479 const char* session_dictionary_name,
480 lldb::ThreadSP& thread,
481 std::string& output);
482
483extern "C" bool
484LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
485 const char* session_dictionary_name,
486 lldb::TargetSP& target,
487 std::string& output);
488
489extern "C" bool
490LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
491 const char* session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000492 lldb::StackFrameSP& frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000493 std::string& output);
494
495extern "C" void*
496LLDBSWIGPython_GetDynamicSetting (void* module,
497 const char* setting,
498 const lldb::TargetSP& target_sp);
499
Greg Claytondce502e2011-11-04 03:34:56 +0000500
501#endif
502
Greg Claytonfc36f7912011-03-22 01:14:58 +0000503void
504SBCommandInterpreter::InitializeSWIG ()
505{
506 static bool g_initialized = false;
507 if (!g_initialized)
508 {
509 g_initialized = true;
Greg Claytondce502e2011-11-04 03:34:56 +0000510#ifndef LLDB_DISABLE_PYTHON
Greg Clayton8afa5432013-10-17 00:27:14 +0000511 ScriptInterpreter::InitializeInterpreter (init_lldb,
512 LLDBSwigPythonBreakpointCallbackFunction,
513 LLDBSwigPythonWatchpointCallbackFunction,
514 LLDBSwigPythonCallTypeScript,
515 LLDBSwigPythonCreateSyntheticProvider,
516 LLDBSwigPython_CalculateNumChildren,
517 LLDBSwigPython_GetChildAtIndex,
518 LLDBSwigPython_GetIndexOfChildWithName,
519 LLDBSWIGPython_CastPyObjectToSBValue,
520 LLDBSWIGPython_GetValueObjectSPFromSBValue,
521 LLDBSwigPython_UpdateSynthProviderInstance,
522 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
523 LLDBSwigPythonCallCommand,
524 LLDBSwigPythonCallModuleInit,
525 LLDBSWIGPythonCreateOSPlugin,
526 LLDBSWIGPythonRunScriptKeywordProcess,
527 LLDBSWIGPythonRunScriptKeywordThread,
528 LLDBSWIGPythonRunScriptKeywordTarget,
529 LLDBSWIGPythonRunScriptKeywordFrame,
530 LLDBSWIGPython_GetDynamicSetting);
Greg Claytondce502e2011-11-04 03:34:56 +0000531#endif
Greg Claytonfc36f7912011-03-22 01:14:58 +0000532 }
533}
Greg Claytona9f7b792012-02-29 04:21:24 +0000534
Enrico Granata21dfcd92012-09-28 23:57:51 +0000535lldb::SBCommand
536SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help)
537{
538 CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help);
539 new_command->SetRemovable (true);
540 lldb::CommandObjectSP new_command_sp(new_command);
541 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
542 return lldb::SBCommand(new_command_sp);
543 return lldb::SBCommand();
544}
545
546lldb::SBCommand
547SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help)
548{
549 lldb::CommandObjectSP new_command_sp;
550 new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help));
551
552 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
553 return lldb::SBCommand(new_command_sp);
554 return lldb::SBCommand();
555}
556
557SBCommand::SBCommand ()
558{}
559
560SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp)
561{}
562
563bool
564SBCommand::IsValid ()
565{
566 return (bool)m_opaque_sp;
567}
568
569const char*
570SBCommand::GetName ()
571{
572 if (IsValid ())
573 return m_opaque_sp->GetCommandName ();
574 return NULL;
575}
576
577const char*
578SBCommand::GetHelp ()
579{
580 if (IsValid ())
581 return m_opaque_sp->GetHelp ();
582 return NULL;
583}
584
585lldb::SBCommand
586SBCommand::AddMultiwordCommand (const char* name, const char* help)
587{
588 if (!IsValid ())
589 return lldb::SBCommand();
590 if (m_opaque_sp->IsMultiwordObject() == false)
591 return lldb::SBCommand();
592 CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help);
593 new_command->SetRemovable (true);
594 lldb::CommandObjectSP new_command_sp(new_command);
595 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
596 return lldb::SBCommand(new_command_sp);
597 return lldb::SBCommand();
598}
599
600lldb::SBCommand
601SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help)
602{
603 if (!IsValid ())
604 return lldb::SBCommand();
605 if (m_opaque_sp->IsMultiwordObject() == false)
606 return lldb::SBCommand();
607 lldb::CommandObjectSP new_command_sp;
608 new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help));
609 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
610 return lldb::SBCommand(new_command_sp);
611 return lldb::SBCommand();
612}
613