diff options
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python')
4 files changed, 78 insertions, 83 deletions
diff --git a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index f3453f2d011d..966bdff3ad95 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -17,10 +17,10 @@ #include "PythonDataObjects.h" #include "ScriptInterpreterPython.h" -#include "lldb/Core/Stream.h" #include "lldb/Host/File.h" #include "lldb/Host/FileSystem.h" #include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Utility/Stream.h" #include "llvm/Support/ConvertUTF.h" diff --git a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index b84996c928da..e613e3d6aa6c 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -19,11 +19,12 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/ConstString.h" -#include "lldb/Core/Flags.h" +#include "lldb/Utility/Flags.h" + #include "lldb/Core/StructuredData.h" #include "lldb/Host/File.h" #include "lldb/Interpreter/OptionValue.h" +#include "lldb/Utility/ConstString.h" #include "lldb/lldb-defines.h" #include "llvm/ADT/ArrayRef.h" diff --git a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 357b48e53c48..d6d695fc2e74 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -51,6 +51,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/FileSystem.h" using namespace lldb; using namespace lldb_private; @@ -142,14 +143,9 @@ public: ~InitializePythonRAII() { if (m_was_already_initialized) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT | - LIBLLDB_LOG_VERBOSE)); - - if (log) { - log->Printf("Releasing PyGILState. Returning to state = %slocked\n", - m_was_already_initialized == PyGILState_UNLOCKED ? "un" - : ""); - } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); + LLDB_LOGV(log, "Releasing PyGILState. Returning to state = {0}locked", + m_was_already_initialized == PyGILState_UNLOCKED ? "un" : ""); PyGILState_Release(m_gil_state); } else { // We initialized the threads in this function, just unlock the GIL. @@ -174,15 +170,12 @@ private: void InitializeThreadsPrivate() { if (PyEval_ThreadsInitialized()) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT | - LIBLLDB_LOG_VERBOSE)); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); m_was_already_initialized = true; m_gil_state = PyGILState_Ensure(); - if (log) { - log->Printf("Ensured PyGILState. Previous state = %slocked\n", - m_gil_state == PyGILState_UNLOCKED ? "un" : ""); - } + LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked\n", + m_gil_state == PyGILState_UNLOCKED ? "un" : ""); return; } @@ -212,12 +205,10 @@ ScriptInterpreterPython::Locker::Locker(ScriptInterpreterPython *py_interpreter, } bool ScriptInterpreterPython::Locker::DoAcquireLock() { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT | - LIBLLDB_LOG_VERBOSE)); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); m_GILState = PyGILState_Ensure(); - if (log) - log->Printf("Ensured PyGILState. Previous state = %slocked\n", - m_GILState == PyGILState_UNLOCKED ? "un" : ""); + LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked", + m_GILState == PyGILState_UNLOCKED ? "un" : ""); // we need to save the thread state when we first start the command // because we might decide to interrupt it while some action is taking @@ -239,11 +230,9 @@ bool ScriptInterpreterPython::Locker::DoInitSession(uint16_t on_entry_flags, } bool ScriptInterpreterPython::Locker::DoFreeLock() { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT | - LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf("Releasing PyGILState. Returning to state = %slocked\n", - m_GILState == PyGILState_UNLOCKED ? "un" : ""); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); + LLDB_LOGV(log, "Releasing PyGILState. Returning to state = {0}locked", + m_GILState == PyGILState_UNLOCKED ? "un" : ""); PyGILState_Release(m_GILState); m_python_interpreter->DecrementLockCount(); return true; @@ -338,9 +327,9 @@ ScriptInterpreterPython::~ScriptInterpreterPython() { } void ScriptInterpreterPython::Initialize() { - static std::once_flag g_once_flag; + static llvm::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + llvm::call_once(g_once_flag, []() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), lldb::eScriptLanguagePython, CreateInstance); @@ -734,7 +723,7 @@ bool ScriptInterpreterPython::ExecuteOneLine( // the result object Pipe pipe; - Error pipe_result = pipe.CreateNew(false); + Status pipe_result = pipe.CreateNew(false); if (pipe_result.Success()) { #if defined(_WIN32) lldb::file_t read_file = pipe.GetReadNativeHandle(); @@ -939,7 +928,8 @@ protected: }; void ScriptInterpreterPython::ExecuteInterpreterLoop() { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); Debugger &debugger = GetCommandInterpreter().GetDebugger(); @@ -1144,9 +1134,9 @@ bool ScriptInterpreterPython::ExecuteOneLineWithReturn( return ret_success; } -Error ScriptInterpreterPython::ExecuteMultipleLines( +Status ScriptInterpreterPython::ExecuteMultipleLines( const char *in_string, const ExecuteScriptOptions &options) { - Error error; + Status error; Locker locker(this, ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | @@ -1231,10 +1221,10 @@ void ScriptInterpreterPython::SetBreakpointCommandCallbackFunction( bp_options, oneliner.c_str()); } -Error ScriptInterpreterPython::SetBreakpointCommandCallback( +Status ScriptInterpreterPython::SetBreakpointCommandCallback( BreakpointOptions *bp_options, std::unique_ptr<BreakpointOptions::CommandData> &cmd_data_up) { - Error error; + Status error; error = GenerateBreakpointCommandCallbackData(cmd_data_up->user_source, cmd_data_up->script_source); if (error.Fail()) { @@ -1248,7 +1238,7 @@ Error ScriptInterpreterPython::SetBreakpointCommandCallback( } // Set a Python one-liner as the callback for the breakpoint. -Error ScriptInterpreterPython::SetBreakpointCommandCallback( +Status ScriptInterpreterPython::SetBreakpointCommandCallback( BreakpointOptions *bp_options, const char *command_body_text) { auto data_ap = llvm::make_unique<CommandDataPython>(); @@ -1259,8 +1249,8 @@ Error ScriptInterpreterPython::SetBreakpointCommandCallback( // the callback will actually invoke. data_ap->user_source.SplitIntoLines(command_body_text); - Error error = GenerateBreakpointCommandCallbackData(data_ap->user_source, - data_ap->script_source); + Status error = GenerateBreakpointCommandCallbackData(data_ap->user_source, + data_ap->script_source); if (error.Success()) { auto baton_sp = std::make_shared<BreakpointOptions::CommandBaton>(std::move(data_ap)); @@ -1296,20 +1286,20 @@ void ScriptInterpreterPython::SetWatchpointCommandCallback( return; } -Error ScriptInterpreterPython::ExportFunctionDefinitionToInterpreter( +Status ScriptInterpreterPython::ExportFunctionDefinitionToInterpreter( StringList &function_def) { // Convert StringList to one long, newline delimited, const char *. std::string function_def_string(function_def.CopyList()); - Error error = ExecuteMultipleLines( + Status error = ExecuteMultipleLines( function_def_string.c_str(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false)); return error; } -Error ScriptInterpreterPython::GenerateFunction(const char *signature, - const StringList &input) { - Error error; +Status ScriptInterpreterPython::GenerateFunction(const char *signature, + const StringList &input) { + Status error; int num_lines = input.GetSize(); if (num_lines == 0) { error.SetErrorString("No input data."); @@ -1841,7 +1831,7 @@ lldb::StateType ScriptInterpreterPython::ScriptedThreadPlanGetRunState( StructuredData::ObjectSP ScriptInterpreterPython::LoadPluginModule(const FileSpec &file_spec, - lldb_private::Error &error) { + lldb_private::Status &error) { if (!file_spec.Exists()) { error.SetErrorString("no such file"); return StructuredData::ObjectSP(); @@ -1858,7 +1848,7 @@ ScriptInterpreterPython::LoadPluginModule(const FileSpec &file_spec, StructuredData::DictionarySP ScriptInterpreterPython::GetDynamicSettings( StructuredData::ObjectSP plugin_module_sp, Target *target, - const char *setting_name, lldb_private::Error &error) { + const char *setting_name, lldb_private::Status &error) { if (!plugin_module_sp || !target || !setting_name || !setting_name[0] || !g_swig_plugin_get) return StructuredData::DictionarySP(); @@ -1954,12 +1944,12 @@ bool ScriptInterpreterPython::GenerateTypeSynthClass(const char *oneliner, return GenerateTypeSynthClass(input, output, name_token); } -Error ScriptInterpreterPython::GenerateBreakpointCommandCallbackData( +Status ScriptInterpreterPython::GenerateBreakpointCommandCallbackData( StringList &user_input, std::string &output) { static uint32_t num_created_functions = 0; user_input.RemoveBlankLines(); StreamString sstr; - Error error; + Status error; if (user_input.GetSize() == 0) { error.SetErrorString("No input data."); return error; @@ -2006,7 +1996,8 @@ bool ScriptInterpreterPython::GetScriptedSummary( StructuredData::ObjectSP &callee_wrapper_sp, const TypeSummaryOptions &options, std::string &retval) { - Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); if (!valobj.get()) { retval.assign("<no object>"); @@ -2030,8 +2021,8 @@ bool ScriptInterpreterPython::GetScriptedSummary( { TypeSummaryOptionsSP options_sp(new TypeSummaryOptions(options)); - Timer scoped_timer("g_swig_typescript_callback", - "g_swig_typescript_callback"); + static Timer::Category func_cat("g_swig_typescript_callback"); + Timer scoped_timer(func_cat, "g_swig_typescript_callback"); ret_val = g_swig_typescript_callback( python_function_name, GetSessionDictionary().get(), valobj, &new_callee, options_sp, retval); @@ -2406,7 +2397,7 @@ ConstString ScriptInterpreterPython::GetSyntheticTypeName( bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, Process *process, std::string &output, - Error &error) { + Status &error) { bool ret_val; if (!process) { error.SetErrorString("no process"); @@ -2435,7 +2426,7 @@ bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, Thread *thread, std::string &output, - Error &error) { + Status &error) { bool ret_val; if (!thread) { error.SetErrorString("no thread"); @@ -2464,7 +2455,7 @@ bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, Target *target, std::string &output, - Error &error) { + Status &error) { bool ret_val; if (!target) { error.SetErrorString("no thread"); @@ -2493,7 +2484,7 @@ bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, StackFrame *frame, std::string &output, - Error &error) { + Status &error) { bool ret_val; if (!frame) { error.SetErrorString("no frame"); @@ -2522,7 +2513,7 @@ bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, bool ScriptInterpreterPython::RunScriptFormatKeyword(const char *impl_function, ValueObject *value, std::string &output, - Error &error) { + Status &error) { bool ret_val; if (!value) { error.SetErrorString("no value"); @@ -2562,7 +2553,7 @@ uint64_t replace_all(std::string &str, const std::string &oldStr, bool ScriptInterpreterPython::LoadScriptingModule( const char *pathname, bool can_reload, bool init_session, - lldb_private::Error &error, StructuredData::ObjectSP *module_sp) { + lldb_private::Status &error, StructuredData::ObjectSP *module_sp) { if (!pathname || !pathname[0]) { error.SetErrorString("invalid pathname"); return false; @@ -2587,9 +2578,13 @@ bool ScriptInterpreterPython::LoadScriptingModule( Locker::NoSTDIN, Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0)); + namespace fs = llvm::sys::fs; + fs::file_status st; + std::error_code ec = status(target_file.GetPath(), st); - if (target_file.GetFileType() == FileSpec::eFileTypeInvalid || - target_file.GetFileType() == FileSpec::eFileTypeUnknown) { + if (ec || st.type() == fs::file_type::status_error || + st.type() == fs::file_type::type_unknown || + st.type() == fs::file_type::file_not_found) { // if not a valid file of any sort, check if it might be a filename still // dot can't be used but / and \ can, and if either is found, reject if (strchr(pathname, '\\') || strchr(pathname, '/')) { @@ -2598,9 +2593,7 @@ bool ScriptInterpreterPython::LoadScriptingModule( } basename = pathname; // not a filename, probably a package of some sort, // let it go through - } else if (target_file.GetFileType() == FileSpec::eFileTypeDirectory || - target_file.GetFileType() == FileSpec::eFileTypeRegular || - target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink) { + } else if (is_directory(st) || is_regular_file(st)) { std::string directory = target_file.GetDirectory().GetCString(); replace_all(directory, "\\", "\\\\"); replace_all(directory, "'", "\\'"); @@ -2751,7 +2744,7 @@ ScriptInterpreterPython::SynchronicityHandler::~SynchronicityHandler() { bool ScriptInterpreterPython::RunScriptBasedCommand( const char *impl_function, const char *args, ScriptedCommandSynchronicity synchronicity, - lldb_private::CommandReturnObject &cmd_retobj, Error &error, + lldb_private::CommandReturnObject &cmd_retobj, Status &error, const lldb_private::ExecutionContext &exe_ctx) { if (!impl_function) { error.SetErrorString("no function to execute"); @@ -2799,7 +2792,7 @@ bool ScriptInterpreterPython::RunScriptBasedCommand( bool ScriptInterpreterPython::RunScriptBasedCommand( StructuredData::GenericSP impl_obj_sp, const char *args, ScriptedCommandSynchronicity synchronicity, - lldb_private::CommandReturnObject &cmd_retobj, Error &error, + lldb_private::CommandReturnObject &cmd_retobj, Status &error, const lldb_private::ExecutionContext &exe_ctx) { if (!impl_obj_sp || !impl_obj_sp->IsValid()) { error.SetErrorString("no function to execute"); @@ -3111,7 +3104,8 @@ void ScriptInterpreterPython::InitializePrivate() { g_initialized = true; - Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); + static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); + Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); // RAII-based initialization which correctly handles multiple-initialization, // version- diff --git a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h index 7b0e1b000d6f..a71fcea7519c 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h +++ b/contrib/llvm/tools/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h @@ -161,11 +161,11 @@ public: void *ret_value, const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; - lldb_private::Error ExecuteMultipleLines( + lldb_private::Status ExecuteMultipleLines( const char *in_string, const ExecuteScriptOptions &options = ExecuteScriptOptions()) override; - Error + Status ExportFunctionDefinitionToInterpreter(StringList &function_def) override; bool GenerateTypeScriptFunction(StringList &input, std::string &output, @@ -229,12 +229,12 @@ public: StructuredData::ObjectSP LoadPluginModule(const FileSpec &file_spec, - lldb_private::Error &error) override; + lldb_private::Status &error) override; StructuredData::DictionarySP GetDynamicSettings(StructuredData::ObjectSP plugin_module_sp, Target *target, const char *setting_name, - lldb_private::Error &error) override; + lldb_private::Status &error) override; size_t CalculateNumChildren(const StructuredData::ObjectSP &implementor, uint32_t max) override; @@ -262,21 +262,21 @@ public: RunScriptBasedCommand(const char *impl_function, const char *args, ScriptedCommandSynchronicity synchronicity, lldb_private::CommandReturnObject &cmd_retobj, - Error &error, + Status &error, const lldb_private::ExecutionContext &exe_ctx) override; bool RunScriptBasedCommand(StructuredData::GenericSP impl_obj_sp, const char *args, ScriptedCommandSynchronicity synchronicity, lldb_private::CommandReturnObject &cmd_retobj, - Error &error, + Status &error, const lldb_private::ExecutionContext &exe_ctx) override; - Error GenerateFunction(const char *signature, - const StringList &input) override; + Status GenerateFunction(const char *signature, + const StringList &input) override; - Error GenerateBreakpointCommandCallbackData(StringList &input, - std::string &output) override; + Status GenerateBreakpointCommandCallbackData(StringList &input, + std::string &output) override; bool GenerateWatchpointCommandCallbackData(StringList &input, std::string &output) override; @@ -332,23 +332,23 @@ public: } bool RunScriptFormatKeyword(const char *impl_function, Process *process, - std::string &output, Error &error) override; + std::string &output, Status &error) override; bool RunScriptFormatKeyword(const char *impl_function, Thread *thread, - std::string &output, Error &error) override; + std::string &output, Status &error) override; bool RunScriptFormatKeyword(const char *impl_function, Target *target, - std::string &output, Error &error) override; + std::string &output, Status &error) override; bool RunScriptFormatKeyword(const char *impl_function, StackFrame *frame, - std::string &output, Error &error) override; + std::string &output, Status &error) override; bool RunScriptFormatKeyword(const char *impl_function, ValueObject *value, - std::string &output, Error &error) override; + std::string &output, Status &error) override; bool LoadScriptingModule(const char *filename, bool can_reload, bool init_session, - lldb_private::Error &error, + lldb_private::Status &error, StructuredData::ObjectSP *module_sp = nullptr) override; bool IsReservedWord(const char *word) override; @@ -364,14 +364,14 @@ public: CommandReturnObject &result) override; /// Set the callback body text into the callback for the breakpoint. - Error SetBreakpointCommandCallback(BreakpointOptions *bp_options, - const char *callback_body) override; + Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, + const char *callback_body) override; void SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options, const char *function_name) override; /// This one is for deserialization: - Error SetBreakpointCommandCallback( + Status SetBreakpointCommandCallback( BreakpointOptions *bp_options, std::unique_ptr<BreakpointOptions::CommandData> &data_up) override; |
