blob: b1bb2af8a510fb4d3567bfea0a4e931ccc2ae936 [file] [log] [blame]
Enrico Granatac2a28252011-08-16 16:49:25 +00001//===-- CommandObjectPythonFunction.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
10#include "CommandObjectPythonFunction.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17#include "lldb/API/SBStream.h"
18
19#include "lldb/Core/Debugger.h"
20
21#include "lldb/Interpreter/Args.h"
22#include "lldb/Interpreter/Options.h"
23
24#include "lldb/Interpreter/CommandInterpreter.h"
25#include "lldb/Interpreter/CommandReturnObject.h"
26
27#include "lldb/Interpreter/ScriptInterpreter.h"
28#include "lldb/Interpreter/ScriptInterpreterPython.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33//-------------------------------------------------------------------------
34// CommandObjectApropos
35//-------------------------------------------------------------------------
36
37CommandObjectPythonFunction::CommandObjectPythonFunction (CommandInterpreter &interpreter,
38 std::string name,
39 std::string funct) :
40 CommandObject (interpreter,
41 name.c_str(),
42 (std::string("Run Python function ") + funct).c_str(),
43 NULL),
44 m_function_name(funct)
45{
46 CommandArgumentEntry arg;
47 CommandArgumentData search_word_arg;
48
49 // Define the first (and only) variant of this arg.
50 search_word_arg.arg_type = eArgTypeSearchWord;
51 search_word_arg.arg_repetition = eArgRepeatPlain;
52
53 // There is only one variant this argument could be; put it into the argument entry.
54 arg.push_back (search_word_arg);
55
56 // Push the data for the first argument into the m_arguments vector.
57 m_arguments.push_back (arg);
58}
59
60CommandObjectPythonFunction::~CommandObjectPythonFunction()
61{
62}
63
64bool
65CommandObjectPythonFunction::ExecuteRawCommandString (const char *raw_command_line,
66 CommandReturnObject &result)
67{
68 ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
69
70 Error error;
71
72 lldb::SBStream stream;
73
74 if (scripter->RunScriptBasedCommand(m_function_name.c_str(),
75 raw_command_line,
76 stream,
77 error) == false)
78 {
79 result.AppendError(error.AsCString());
80 result.SetStatus(eReturnStatusFailed);
81 }
82 else
83 result.SetStatus(eReturnStatusSuccessFinishNoResult);
84
85 result.GetOutputStream() << stream.GetData();
86
87 return result.Succeeded();
88}