diff options
| author | Enrico Granata <granata.enrico@gmail.com> | 2011-08-16 16:49:25 +0000 |
|---|---|---|
| committer | Enrico Granata <granata.enrico@gmail.com> | 2011-08-16 16:49:25 +0000 |
| commit | be93a35a8a29376abab778bbe96d3060e79d4f8e (patch) | |
| tree | a2a1b5ebe5a8a3df82878448441d0a64403e3efb /lldb/source/Commands/CommandObjectPythonFunction.cpp | |
| parent | 5de2044f3d417831d2e64e7df089edce394ed14e (diff) | |
| download | bcm5719-llvm-be93a35a8a29376abab778bbe96d3060e79d4f8e.tar.gz bcm5719-llvm-be93a35a8a29376abab778bbe96d3060e79d4f8e.zip | |
Python commands:
It is now possible to use 'command alias --python' to define a command name that actually triggers execution of a Python function
(e.g. command alias --python foo foo_impl makes a command named 'foo' that runs Python function 'foo_impl')
The Python function foo_impl should have as signature: def foo_impl(debugger, args, stream, dict): where
debugger is an object wrapping an LLDB SBDebugger
args is the command line arguments, as an unparsed Python string
stream is an SBStream that represents the standard output
dict is an internal utility parameter and should be left untouched
The function should return None on no error, or an error string to describe any problems
llvm-svn: 137722
Diffstat (limited to 'lldb/source/Commands/CommandObjectPythonFunction.cpp')
| -rw-r--r-- | lldb/source/Commands/CommandObjectPythonFunction.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectPythonFunction.cpp b/lldb/source/Commands/CommandObjectPythonFunction.cpp new file mode 100644 index 00000000000..b1bb2af8a51 --- /dev/null +++ b/lldb/source/Commands/CommandObjectPythonFunction.cpp @@ -0,0 +1,88 @@ +//===-- CommandObjectPythonFunction.cpp --------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "CommandObjectPythonFunction.h" + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes + +#include "lldb/API/SBStream.h" + +#include "lldb/Core/Debugger.h" + +#include "lldb/Interpreter/Args.h" +#include "lldb/Interpreter/Options.h" + +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/CommandReturnObject.h" + +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreterPython.h" + +using namespace lldb; +using namespace lldb_private; + +//------------------------------------------------------------------------- +// CommandObjectApropos +//------------------------------------------------------------------------- + +CommandObjectPythonFunction::CommandObjectPythonFunction (CommandInterpreter &interpreter, + std::string name, + std::string funct) : + CommandObject (interpreter, + name.c_str(), + (std::string("Run Python function ") + funct).c_str(), + NULL), + m_function_name(funct) +{ + CommandArgumentEntry arg; + CommandArgumentData search_word_arg; + + // Define the first (and only) variant of this arg. + search_word_arg.arg_type = eArgTypeSearchWord; + search_word_arg.arg_repetition = eArgRepeatPlain; + + // There is only one variant this argument could be; put it into the argument entry. + arg.push_back (search_word_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); +} + +CommandObjectPythonFunction::~CommandObjectPythonFunction() +{ +} + +bool +CommandObjectPythonFunction::ExecuteRawCommandString (const char *raw_command_line, + CommandReturnObject &result) +{ + ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter(); + + Error error; + + lldb::SBStream stream; + + if (scripter->RunScriptBasedCommand(m_function_name.c_str(), + raw_command_line, + stream, + error) == false) + { + result.AppendError(error.AsCString()); + result.SetStatus(eReturnStatusFailed); + } + else + result.SetStatus(eReturnStatusSuccessFinishNoResult); + + result.GetOutputStream() << stream.GetData(); + + return result.Succeeded(); +} |

