1ac7ddfbfSEd Maste //===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "CommandObjectScript.h" 11ac7ddfbfSEd Maste 12ac7ddfbfSEd Maste // C Includes 13ac7ddfbfSEd Maste // C++ Includes 14ac7ddfbfSEd Maste // Other libraries and framework includes 15ac7ddfbfSEd Maste // Project includes 16ac7ddfbfSEd Maste 17ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h" 18ac7ddfbfSEd Maste 19ac7ddfbfSEd Maste #include "lldb/DataFormatters/DataVisualization.h" 20ac7ddfbfSEd Maste 21ac7ddfbfSEd Maste #include "lldb/Interpreter/Args.h" 22ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h" 23ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h" 24ac7ddfbfSEd Maste #include "lldb/Interpreter/ScriptInterpreter.h" 25ac7ddfbfSEd Maste 26ac7ddfbfSEd Maste using namespace lldb; 27ac7ddfbfSEd Maste using namespace lldb_private; 28ac7ddfbfSEd Maste 29ac7ddfbfSEd Maste //------------------------------------------------------------------------- 30ac7ddfbfSEd Maste // CommandObjectScript 31ac7ddfbfSEd Maste //------------------------------------------------------------------------- 32ac7ddfbfSEd Maste 334bb0738eSEd Maste CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter, ScriptLanguage script_lang) 344bb0738eSEd Maste : CommandObjectRaw(interpreter, "script", "Invoke the script interpreter with provided code and display any " 354bb0738eSEd Maste "results. Start the interactive interpreter if no code is supplied.", 364bb0738eSEd Maste "script [<script-code>]") 37ac7ddfbfSEd Maste { 38ac7ddfbfSEd Maste } 39ac7ddfbfSEd Maste 40ac7ddfbfSEd Maste CommandObjectScript::~CommandObjectScript () 41ac7ddfbfSEd Maste { 42ac7ddfbfSEd Maste } 43ac7ddfbfSEd Maste 44ac7ddfbfSEd Maste bool 45ac7ddfbfSEd Maste CommandObjectScript::DoExecute 46ac7ddfbfSEd Maste ( 47ac7ddfbfSEd Maste const char *command, 48ac7ddfbfSEd Maste CommandReturnObject &result 49ac7ddfbfSEd Maste ) 50ac7ddfbfSEd Maste { 51ac7ddfbfSEd Maste #ifdef LLDB_DISABLE_PYTHON 52ac7ddfbfSEd Maste // if we ever support languages other than Python this simple #ifdef won't work 53ac7ddfbfSEd Maste result.AppendError("your copy of LLDB does not support scripting."); 54ac7ddfbfSEd Maste result.SetStatus (eReturnStatusFailed); 55ac7ddfbfSEd Maste return false; 56ac7ddfbfSEd Maste #else 57ac7ddfbfSEd Maste if (m_interpreter.GetDebugger().GetScriptLanguage() == lldb::eScriptLanguageNone) 58ac7ddfbfSEd Maste { 59ac7ddfbfSEd Maste result.AppendError("the script-lang setting is set to none - scripting not available"); 60ac7ddfbfSEd Maste result.SetStatus (eReturnStatusFailed); 61ac7ddfbfSEd Maste return false; 62ac7ddfbfSEd Maste } 63ac7ddfbfSEd Maste 64ac7ddfbfSEd Maste ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter (); 65ac7ddfbfSEd Maste 660127ef0fSEd Maste if (script_interpreter == nullptr) 67ac7ddfbfSEd Maste { 68ac7ddfbfSEd Maste result.AppendError("no script interpreter"); 69ac7ddfbfSEd Maste result.SetStatus (eReturnStatusFailed); 70ac7ddfbfSEd Maste return false; 71ac7ddfbfSEd Maste } 72ac7ddfbfSEd Maste 73ac7ddfbfSEd Maste DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it 74ac7ddfbfSEd Maste 750127ef0fSEd Maste if (command == nullptr || command[0] == '\0') 76ac7ddfbfSEd Maste { 77ac7ddfbfSEd Maste script_interpreter->ExecuteInterpreterLoop (); 78ac7ddfbfSEd Maste result.SetStatus (eReturnStatusSuccessFinishNoResult); 79ac7ddfbfSEd Maste return result.Succeeded(); 80ac7ddfbfSEd Maste } 81ac7ddfbfSEd Maste 82ac7ddfbfSEd Maste // We can do better when reporting the status of one-liner script execution. 83ac7ddfbfSEd Maste if (script_interpreter->ExecuteOneLine (command, &result)) 84ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult); 85ac7ddfbfSEd Maste else 86ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed); 87ac7ddfbfSEd Maste 88ac7ddfbfSEd Maste return result.Succeeded(); 89ac7ddfbfSEd Maste #endif 90ac7ddfbfSEd Maste } 91