CommandObjectScript.cpp revision 314564
1254721Semaste//===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "CommandObjectScript.h" 11254721Semaste 12254721Semaste// C Includes 13254721Semaste// C++ Includes 14254721Semaste// Other libraries and framework includes 15254721Semaste// Project includes 16254721Semaste 17254721Semaste#include "lldb/Core/Debugger.h" 18254721Semaste 19254721Semaste#include "lldb/DataFormatters/DataVisualization.h" 20254721Semaste 21254721Semaste#include "lldb/Interpreter/Args.h" 22254721Semaste#include "lldb/Interpreter/CommandInterpreter.h" 23254721Semaste#include "lldb/Interpreter/CommandReturnObject.h" 24254721Semaste#include "lldb/Interpreter/ScriptInterpreter.h" 25254721Semaste 26254721Semasteusing namespace lldb; 27254721Semasteusing namespace lldb_private; 28254721Semaste 29254721Semaste//------------------------------------------------------------------------- 30254721Semaste// CommandObjectScript 31254721Semaste//------------------------------------------------------------------------- 32254721Semaste 33314564SdimCommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter, 34314564Sdim ScriptLanguage script_lang) 35314564Sdim : CommandObjectRaw( 36314564Sdim interpreter, "script", 37314564Sdim "Invoke the script interpreter with provided code and display any " 38314564Sdim "results. Start the interactive interpreter if no code is supplied.", 39314564Sdim "script [<script-code>]") {} 40254721Semaste 41314564SdimCommandObjectScript::~CommandObjectScript() {} 42254721Semaste 43314564Sdimbool CommandObjectScript::DoExecute(const char *command, 44314564Sdim CommandReturnObject &result) { 45254721Semaste#ifdef LLDB_DISABLE_PYTHON 46314564Sdim // if we ever support languages other than Python this simple #ifdef won't 47314564Sdim // work 48314564Sdim result.AppendError("your copy of LLDB does not support scripting."); 49314564Sdim result.SetStatus(eReturnStatusFailed); 50314564Sdim return false; 51314564Sdim#else 52314564Sdim if (m_interpreter.GetDebugger().GetScriptLanguage() == 53314564Sdim lldb::eScriptLanguageNone) { 54314564Sdim result.AppendError( 55314564Sdim "the script-lang setting is set to none - scripting not available"); 56314564Sdim result.SetStatus(eReturnStatusFailed); 57254721Semaste return false; 58314564Sdim } 59254721Semaste 60314564Sdim ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter(); 61254721Semaste 62314564Sdim if (script_interpreter == nullptr) { 63314564Sdim result.AppendError("no script interpreter"); 64314564Sdim result.SetStatus(eReturnStatusFailed); 65314564Sdim return false; 66314564Sdim } 67254721Semaste 68314564Sdim DataVisualization::ForceUpdate(); // script might change Python code we use 69314564Sdim // for formatting.. make sure we keep up to 70314564Sdim // date with it 71254721Semaste 72314564Sdim if (command == nullptr || command[0] == '\0') { 73314564Sdim script_interpreter->ExecuteInterpreterLoop(); 74314564Sdim result.SetStatus(eReturnStatusSuccessFinishNoResult); 75254721Semaste return result.Succeeded(); 76314564Sdim } 77314564Sdim 78314564Sdim // We can do better when reporting the status of one-liner script execution. 79314564Sdim if (script_interpreter->ExecuteOneLine(command, &result)) 80314564Sdim result.SetStatus(eReturnStatusSuccessFinishNoResult); 81314564Sdim else 82314564Sdim result.SetStatus(eReturnStatusFailed); 83314564Sdim 84314564Sdim return result.Succeeded(); 85254721Semaste#endif 86254721Semaste} 87