blob: 388dff2a8aa391f8accb7a1190a4808559511a23 [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)"
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000068 " => SBCommandInterpreter(%p)",
69 static_cast<void*>(interpreter),
70 static_cast<void*>(m_opaque_ptr));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}
72
Greg Claytonefabb122010-11-05 23:17:00 +000073SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) :
74 m_opaque_ptr (rhs.m_opaque_ptr)
75{
76}
77
78const SBCommandInterpreter &
79SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs)
80{
81 m_opaque_ptr = rhs.m_opaque_ptr;
82 return *this;
83}
84
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085SBCommandInterpreter::~SBCommandInterpreter ()
86{
87}
88
89bool
Greg Clayton66111032010-06-23 01:19:29 +000090SBCommandInterpreter::IsValid() const
91{
92 return m_opaque_ptr != NULL;
93}
94
95
96bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097SBCommandInterpreter::CommandExists (const char *cmd)
98{
Johnny Chen872e0622011-12-19 21:16:29 +000099 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000100 return m_opaque_ptr->CommandExists (cmd);
101 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
104bool
105SBCommandInterpreter::AliasExists (const char *cmd)
106{
Johnny Chen872e0622011-12-19 21:16:29 +0000107 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000108 return m_opaque_ptr->AliasExists (cmd);
109 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
Greg Clayton44d93782014-01-27 23:43:24 +0000112bool
113SBCommandInterpreter::IsActive ()
114{
115 if (m_opaque_ptr)
116 return m_opaque_ptr->IsActive ();
117 return false;
118}
119
120const char *
121SBCommandInterpreter::GetIOHandlerControlSequence(char ch)
122{
123 if (m_opaque_ptr)
124 return m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence (ch).GetCString();
125 return NULL;
126}
127
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128lldb::ReturnStatus
129SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
130{
Greg Clayton5160ce52013-03-27 23:08:40 +0000131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000132
133 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000134 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)",
135 static_cast<void*>(m_opaque_ptr), command_line,
136 static_cast<void*>(result.get()), add_to_history);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000137
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 result.Clear();
Johnny Chen872e0622011-12-19 21:16:29 +0000139 if (command_line && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000140 {
Enrico Granata5f5ab602012-05-31 01:09:06 +0000141 m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref());
Greg Clayton66111032010-06-23 01:19:29 +0000142 }
143 else
144 {
Johnny Chen872e0622011-12-19 21:16:29 +0000145 result->AppendError ("SBCommandInterpreter or the command line is not valid");
Greg Clayton66111032010-06-23 01:19:29 +0000146 result->SetStatus (eReturnStatusFailed);
147 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000148
Caroline Tice7b9da4a2010-10-27 21:23:37 +0000149 // We need to get the value again, in case the command disabled the log!
150 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000151 if (log)
152 {
153 SBStream sstr;
154 result.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000155 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000156 static_cast<void*>(m_opaque_ptr), command_line,
157 static_cast<void*>(result.get()), sstr.GetData(),
158 add_to_history, result.GetStatus());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000159 }
160
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 return result.GetStatus();
162}
163
164int
165SBCommandInterpreter::HandleCompletion (const char *current_line,
166 const char *cursor,
167 const char *last_char,
168 int match_start_point,
169 int max_return_elements,
170 SBStringList &matches)
171{
Greg Clayton5160ce52013-03-27 23:08:40 +0000172 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton66111032010-06-23 01:19:29 +0000173 int num_completions = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000174
Jim Inghamac012602011-12-05 19:24:15 +0000175 // Sanity check the arguments that are passed in:
176 // cursor & last_char have to be within the current_line.
177 if (current_line == NULL || cursor == NULL || last_char == NULL)
178 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000179
Jim Inghamac012602011-12-05 19:24:15 +0000180 if (cursor < current_line || last_char < current_line)
181 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000182
Jim Inghamac012602011-12-05 19:24:15 +0000183 size_t current_line_size = strlen (current_line);
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000184 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) ||
185 last_char - current_line > static_cast<ptrdiff_t>(current_line_size))
Jim Inghamac012602011-12-05 19:24:15 +0000186 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000187
Jim Ingham389512d2012-06-26 01:21:59 +0000188 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000189 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000190 static_cast<void*>(m_opaque_ptr), current_line,
191 static_cast<uint64_t>(cursor - current_line),
192 static_cast<uint64_t>(last_char - current_line),
193 match_start_point, max_return_elements);
194
Greg Clayton66111032010-06-23 01:19:29 +0000195 if (m_opaque_ptr)
196 {
197 lldb_private::StringList lldb_matches;
198 num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point,
199 max_return_elements, lldb_matches);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200
Greg Clayton66111032010-06-23 01:19:29 +0000201 SBStringList temp_list (&lldb_matches);
202 matches.AppendList (temp_list);
203 }
Jim Ingham389512d2012-06-26 01:21:59 +0000204 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000205 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.",
206 static_cast<void*>(m_opaque_ptr), num_completions);
207
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 return num_completions;
209}
210
Jim Ingham969795f2011-09-21 01:17:13 +0000211int
212SBCommandInterpreter::HandleCompletion (const char *current_line,
213 uint32_t cursor_pos,
214 int match_start_point,
215 int max_return_elements,
216 lldb::SBStringList &matches)
217{
218 const char *cursor = current_line + cursor_pos;
219 const char *last_char = current_line + strlen (current_line);
220 return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches);
221}
222
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223bool
224SBCommandInterpreter::HasCommands ()
225{
Greg Clayton66111032010-06-23 01:19:29 +0000226 if (m_opaque_ptr)
227 return m_opaque_ptr->HasCommands();
228 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229}
230
231bool
232SBCommandInterpreter::HasAliases ()
233{
Greg Clayton66111032010-06-23 01:19:29 +0000234 if (m_opaque_ptr)
235 return m_opaque_ptr->HasAliases();
236 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
239bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240SBCommandInterpreter::HasAliasOptions ()
241{
Greg Clayton66111032010-06-23 01:19:29 +0000242 if (m_opaque_ptr)
243 return m_opaque_ptr->HasAliasOptions ();
244 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245}
246
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247SBProcess
248SBCommandInterpreter::GetProcess ()
249{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000250 SBProcess sb_process;
251 ProcessSP process_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000252 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000254 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
255 if (target_sp)
256 {
257 Mutex::Locker api_locker(target_sp->GetAPIMutex());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000258 process_sp = target_sp->GetProcessSP();
259 sb_process.SetSP(process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000260 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000262 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000263
264 if (log)
265 log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000266 static_cast<void*>(m_opaque_ptr),
267 static_cast<void*>(process_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000268
Greg Claytonb9556ac2012-01-30 07:41:31 +0000269 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
Enrico Granata21dfcd92012-09-28 23:57:51 +0000272SBDebugger
273SBCommandInterpreter::GetDebugger ()
274{
275 SBDebugger sb_debugger;
276 if (m_opaque_ptr)
277 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
Greg Clayton5160ce52013-03-27 23:08:40 +0000278 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000279
Enrico Granata21dfcd92012-09-28 23:57:51 +0000280 if (log)
281 log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000282 static_cast<void*>(m_opaque_ptr),
283 static_cast<void*>(sb_debugger.get()));
284
Enrico Granata21dfcd92012-09-28 23:57:51 +0000285 return sb_debugger;
286}
287
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288CommandInterpreter *
Greg Clayton66111032010-06-23 01:19:29 +0000289SBCommandInterpreter::get ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290{
Greg Clayton66111032010-06-23 01:19:29 +0000291 return m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292}
293
294CommandInterpreter &
Greg Clayton66111032010-06-23 01:19:29 +0000295SBCommandInterpreter::ref ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296{
Greg Clayton66111032010-06-23 01:19:29 +0000297 assert (m_opaque_ptr);
298 return *m_opaque_ptr;
299}
300
301void
302SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
303{
304 m_opaque_ptr = interpreter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305}
306
307void
308SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
309{
310 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000311 if (m_opaque_ptr)
312 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000313 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
314 Mutex::Locker api_locker;
315 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000316 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000317 m_opaque_ptr->SourceInitFile (false, result.ref());
318 }
319 else
320 {
321 result->AppendError ("SBCommandInterpreter is not valid");
322 result->SetStatus (eReturnStatusFailed);
323 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000324 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000325
326 if (log)
327 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000328 static_cast<void*>(m_opaque_ptr),
329 static_cast<void*>(result.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330}
331
332void
333SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
334{
335 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000336 if (m_opaque_ptr)
337 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000338 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
339 Mutex::Locker api_locker;
340 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000341 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000342 m_opaque_ptr->SourceInitFile (true, result.ref());
343 }
344 else
345 {
346 result->AppendError ("SBCommandInterpreter is not valid");
347 result->SetStatus (eReturnStatusFailed);
348 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000349 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000350
351 if (log)
352 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000353 static_cast<void*>(m_opaque_ptr),
354 static_cast<void*>(result.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355}
356
357SBBroadcaster
358SBCommandInterpreter::GetBroadcaster ()
359{
Greg Clayton5160ce52013-03-27 23:08:40 +0000360 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000361
Greg Clayton66111032010-06-23 01:19:29 +0000362 SBBroadcaster broadcaster (m_opaque_ptr, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000363
364 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000365 log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000366 static_cast<void*>(m_opaque_ptr), static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000367
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 return broadcaster;
369}
370
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000371const char *
372SBCommandInterpreter::GetBroadcasterClass ()
373{
374 return Communication::GetStaticBroadcasterClass().AsCString();
375}
376
Greg Clayton9d0402b2011-02-20 02:15:07 +0000377const char *
378SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
379{
380 return CommandObject::GetArgumentTypeAsCString (arg_type);
381}
382
383const char *
384SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
385{
386 return CommandObject::GetArgumentDescriptionAsCString (arg_type);
387}
388
Greg Claytona9f7b792012-02-29 04:21:24 +0000389bool
390SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name,
391 lldb::CommandOverrideCallback callback,
392 void *baton)
393{
394 if (command_name && command_name[0] && m_opaque_ptr)
395 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000396 std::string command_name_str (command_name);
397 CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
Greg Claytona9f7b792012-02-29 04:21:24 +0000398 if (cmd_obj)
399 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000400 assert(command_name_str.empty());
Greg Claytona9f7b792012-02-29 04:21:24 +0000401 cmd_obj->SetOverrideCallback (callback, baton);
402 return true;
403 }
404 }
405 return false;
406}
Greg Clayton9d0402b2011-02-20 02:15:07 +0000407
Greg Claytondce502e2011-11-04 03:34:56 +0000408#ifndef LLDB_DISABLE_PYTHON
Enrico Granatabe93a352011-08-16 16:49:25 +0000409
Greg Claytondce502e2011-11-04 03:34:56 +0000410// Defined in the SWIG source file
411extern "C" void
412init_lldb(void);
413
Greg Clayton8afa5432013-10-17 00:27:14 +0000414// these are the Pythonic implementations of the required callbacks
415// these are scripting-language specific, which is why they belong here
416// we still need to use function pointers to them instead of relying
417// on linkage-time resolution because the SWIG stuff and this file
418// get built at different times
419extern "C" bool
420LLDBSwigPythonBreakpointCallbackFunction (const char *python_function_name,
421 const char *session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000422 const lldb::StackFrameSP& sb_frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000423 const lldb::BreakpointLocationSP& sb_bp_loc);
Enrico Granatabe93a352011-08-16 16:49:25 +0000424
Greg Clayton8afa5432013-10-17 00:27:14 +0000425extern "C" bool
426LLDBSwigPythonWatchpointCallbackFunction (const char *python_function_name,
427 const char *session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000428 const lldb::StackFrameSP& sb_frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000429 const lldb::WatchpointSP& sb_wp);
Greg Claytonfc36f7912011-03-22 01:14:58 +0000430
Greg Clayton8afa5432013-10-17 00:27:14 +0000431extern "C" bool
432LLDBSwigPythonCallTypeScript (const char *python_function_name,
433 void *session_dictionary,
434 const lldb::ValueObjectSP& valobj_sp,
435 void** pyfunct_wrapper,
436 std::string& retval);
437
438extern "C" void*
439LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name,
440 const char *session_dictionary_name,
441 const lldb::ValueObjectSP& valobj_sp);
442
443
444extern "C" uint32_t
445LLDBSwigPython_CalculateNumChildren (void *implementor);
446
447extern "C" void *
448LLDBSwigPython_GetChildAtIndex (void *implementor, uint32_t idx);
449
450extern "C" int
451LLDBSwigPython_GetIndexOfChildWithName (void *implementor, const char* child_name);
452
453extern "C" void *
454LLDBSWIGPython_CastPyObjectToSBValue (void* data);
455
456extern lldb::ValueObjectSP
457LLDBSWIGPython_GetValueObjectSPFromSBValue (void* data);
458
459extern "C" bool
460LLDBSwigPython_UpdateSynthProviderInstance (void* implementor);
461
462extern "C" bool
463LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor);
464
465extern "C" bool
466LLDBSwigPythonCallCommand (const char *python_function_name,
467 const char *session_dictionary_name,
468 lldb::DebuggerSP& debugger,
469 const char* args,
470 lldb_private::CommandReturnObject &cmd_retobj);
471
472extern "C" bool
473LLDBSwigPythonCallModuleInit (const char *python_module_name,
474 const char *session_dictionary_name,
475 lldb::DebuggerSP& debugger);
476
477extern "C" void*
478LLDBSWIGPythonCreateOSPlugin (const char *python_class_name,
479 const char *session_dictionary_name,
480 const lldb::ProcessSP& process_sp);
481
482extern "C" bool
483LLDBSWIGPythonRunScriptKeywordProcess (const char* python_function_name,
484 const char* session_dictionary_name,
485 lldb::ProcessSP& process,
486 std::string& output);
487
488extern "C" bool
489LLDBSWIGPythonRunScriptKeywordThread (const char* python_function_name,
490 const char* session_dictionary_name,
491 lldb::ThreadSP& thread,
492 std::string& output);
493
494extern "C" bool
495LLDBSWIGPythonRunScriptKeywordTarget (const char* python_function_name,
496 const char* session_dictionary_name,
497 lldb::TargetSP& target,
498 std::string& output);
499
500extern "C" bool
501LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name,
502 const char* session_dictionary_name,
Jason Molendab57e4a12013-11-04 09:33:30 +0000503 lldb::StackFrameSP& frame,
Greg Clayton8afa5432013-10-17 00:27:14 +0000504 std::string& output);
505
506extern "C" void*
507LLDBSWIGPython_GetDynamicSetting (void* module,
508 const char* setting,
509 const lldb::TargetSP& target_sp);
510
Greg Claytondce502e2011-11-04 03:34:56 +0000511
512#endif
513
Greg Claytonfc36f7912011-03-22 01:14:58 +0000514void
515SBCommandInterpreter::InitializeSWIG ()
516{
517 static bool g_initialized = false;
518 if (!g_initialized)
519 {
520 g_initialized = true;
Greg Claytondce502e2011-11-04 03:34:56 +0000521#ifndef LLDB_DISABLE_PYTHON
Greg Clayton8afa5432013-10-17 00:27:14 +0000522 ScriptInterpreter::InitializeInterpreter (init_lldb,
523 LLDBSwigPythonBreakpointCallbackFunction,
524 LLDBSwigPythonWatchpointCallbackFunction,
525 LLDBSwigPythonCallTypeScript,
526 LLDBSwigPythonCreateSyntheticProvider,
527 LLDBSwigPython_CalculateNumChildren,
528 LLDBSwigPython_GetChildAtIndex,
529 LLDBSwigPython_GetIndexOfChildWithName,
530 LLDBSWIGPython_CastPyObjectToSBValue,
531 LLDBSWIGPython_GetValueObjectSPFromSBValue,
532 LLDBSwigPython_UpdateSynthProviderInstance,
533 LLDBSwigPython_MightHaveChildrenSynthProviderInstance,
534 LLDBSwigPythonCallCommand,
535 LLDBSwigPythonCallModuleInit,
536 LLDBSWIGPythonCreateOSPlugin,
537 LLDBSWIGPythonRunScriptKeywordProcess,
538 LLDBSWIGPythonRunScriptKeywordThread,
539 LLDBSWIGPythonRunScriptKeywordTarget,
540 LLDBSWIGPythonRunScriptKeywordFrame,
541 LLDBSWIGPython_GetDynamicSetting);
Greg Claytondce502e2011-11-04 03:34:56 +0000542#endif
Greg Claytonfc36f7912011-03-22 01:14:58 +0000543 }
544}
Greg Claytona9f7b792012-02-29 04:21:24 +0000545
Enrico Granata21dfcd92012-09-28 23:57:51 +0000546lldb::SBCommand
547SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help)
548{
549 CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help);
550 new_command->SetRemovable (true);
551 lldb::CommandObjectSP new_command_sp(new_command);
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
557lldb::SBCommand
558SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help)
559{
560 lldb::CommandObjectSP new_command_sp;
561 new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help));
562
563 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
564 return lldb::SBCommand(new_command_sp);
565 return lldb::SBCommand();
566}
567
568SBCommand::SBCommand ()
569{}
570
571SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp)
572{}
573
574bool
575SBCommand::IsValid ()
576{
577 return (bool)m_opaque_sp;
578}
579
580const char*
581SBCommand::GetName ()
582{
583 if (IsValid ())
584 return m_opaque_sp->GetCommandName ();
585 return NULL;
586}
587
588const char*
589SBCommand::GetHelp ()
590{
591 if (IsValid ())
592 return m_opaque_sp->GetHelp ();
593 return NULL;
594}
595
596lldb::SBCommand
597SBCommand::AddMultiwordCommand (const char* name, const char* help)
598{
599 if (!IsValid ())
600 return lldb::SBCommand();
601 if (m_opaque_sp->IsMultiwordObject() == false)
602 return lldb::SBCommand();
603 CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help);
604 new_command->SetRemovable (true);
605 lldb::CommandObjectSP new_command_sp(new_command);
606 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
607 return lldb::SBCommand(new_command_sp);
608 return lldb::SBCommand();
609}
610
611lldb::SBCommand
612SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help)
613{
614 if (!IsValid ())
615 return lldb::SBCommand();
616 if (m_opaque_sp->IsMultiwordObject() == false)
617 return lldb::SBCommand();
618 lldb::CommandObjectSP new_command_sp;
619 new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help));
620 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
621 return lldb::SBCommand(new_command_sp);
622 return lldb::SBCommand();
623}
624