diff options
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
10 files changed, 221 insertions, 144 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index d91fb7a443b..0952fec80fa 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -11,7 +11,9 @@ // C++ Includes // Other libraries and framework includes #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTDiagnostic.h" #include "clang/AST/ExternalASTSource.h" +#include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TargetInfo.h" @@ -64,20 +66,21 @@ #include "lldb/Core/Module.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StringList.h" #include "lldb/Core/StreamString.h" -#include "lldb/Expression/IRExecutionUnit.h" +#include "lldb/Core/StringList.h" #include "lldb/Expression/IRDynamicChecks.h" +#include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRInterpreter.h" #include "lldb/Host/File.h" #include "lldb/Host/HostInfo.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Language.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" -#include "lldb/Target/Language.h" +#include "lldb/Utility/LLDBAssert.h" using namespace clang; using namespace llvm; @@ -141,6 +144,76 @@ public: } }; +class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer +{ +public: + ClangDiagnosticManagerAdapter() : m_passthrough(new clang::TextDiagnosticBuffer) {} + + ClangDiagnosticManagerAdapter(const std::shared_ptr<clang::TextDiagnosticBuffer> &passthrough) + : m_passthrough(passthrough) + { + } + + void + ResetManager(DiagnosticManager *manager = nullptr) + { + m_manager = manager; + } + + void + HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) + { + if (m_manager) + { + llvm::SmallVector<char, 32> diag_str; + Info.FormatDiagnostic(diag_str); + diag_str.push_back('\0'); + const char *data = diag_str.data(); + + switch (DiagLevel) + { + case DiagnosticsEngine::Level::Fatal: + case DiagnosticsEngine::Level::Error: + m_manager->AddDiagnostic(data, eDiagnosticSeverityError, eDiagnosticOriginClang, Info.getID()); + break; + case DiagnosticsEngine::Level::Warning: + m_manager->AddDiagnostic(data, eDiagnosticSeverityWarning, eDiagnosticOriginClang, Info.getID()); + break; + case DiagnosticsEngine::Level::Remark: + case DiagnosticsEngine::Level::Ignored: + m_manager->AddDiagnostic(data, eDiagnosticSeverityRemark, eDiagnosticOriginClang, Info.getID()); + break; + case DiagnosticsEngine::Level::Note: + m_manager->AppendMessageToDiagnostic(data); + } + } + + m_passthrough->HandleDiagnostic(DiagLevel, Info); + } + + void + FlushDiagnostics(DiagnosticsEngine &Diags) + { + m_passthrough->FlushDiagnostics(Diags); + } + + DiagnosticConsumer * + clone(DiagnosticsEngine &Diags) const + { + return new ClangDiagnosticManagerAdapter(m_passthrough); + } + + clang::TextDiagnosticBuffer * + GetPassthrough() + { + return m_passthrough.get(); + } + +private: + DiagnosticManager *m_manager = nullptr; + std::shared_ptr<clang::TextDiagnosticBuffer> m_passthrough; +}; + //===----------------------------------------------------------------------===// // Implementation of ClangExpressionParser //===----------------------------------------------------------------------===// @@ -371,7 +444,7 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, // 6. Set up the diagnostic buffer for reporting errors - m_compiler->getDiagnostics().setClient(new clang::TextDiagnosticBuffer); + m_compiler->getDiagnostics().setClient(new ClangDiagnosticManagerAdapter); // 7. Set up the source management objects inside the compiler @@ -435,11 +508,15 @@ ClangExpressionParser::~ClangExpressionParser() } unsigned -ClangExpressionParser::Parse(Stream &stream) +ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager) { - TextDiagnosticBuffer *diag_buf = static_cast<TextDiagnosticBuffer *>(m_compiler->getDiagnostics().getClient()); + ClangDiagnosticManagerAdapter *adapter = + static_cast<ClangDiagnosticManagerAdapter *>(m_compiler->getDiagnostics().getClient()); + clang::TextDiagnosticBuffer *diag_buf = adapter->GetPassthrough(); diag_buf->FlushDiagnostics(m_compiler->getDiagnostics()); + adapter->ResetManager(&diagnostic_manager); + const char *expr_text = m_expr.Text(); clang::SourceManager &source_mgr = m_compiler->getSourceManager(); @@ -511,30 +588,21 @@ ClangExpressionParser::Parse(Stream &stream) if (m_pp_callbacks && m_pp_callbacks->hasErrors()) { num_errors++; - stream.PutCString(m_pp_callbacks->getErrorString().c_str()); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "while importing modules:"); + diagnostic_manager.AppendMessageToDiagnostic(m_pp_callbacks->getErrorString().c_str()); } - for (TextDiagnosticBuffer::const_iterator warn = diag_buf->warn_begin(), warn_end = diag_buf->warn_end(); - warn != warn_end; ++warn) - stream.Printf("warning: %s\n", warn->second.c_str()); - - for (TextDiagnosticBuffer::const_iterator err = diag_buf->err_begin(), err_end = diag_buf->err_end(); - err != err_end; ++err) - stream.Printf("error: %s\n", err->second.c_str()); - - for (TextDiagnosticBuffer::const_iterator note = diag_buf->note_begin(), note_end = diag_buf->note_end(); - note != note_end; ++note) - stream.Printf("note: %s\n", note->second.c_str()); - if (!num_errors) { if (type_system_helper->DeclMap() && !type_system_helper->DeclMap()->ResolveUnknownTypes()) { - stream.Printf("error: Couldn't infer the type of a variable\n"); + diagnostic_manager.Printf(eDiagnosticSeverityError, "Couldn't infer the type of a variable"); num_errors++; } } + adapter->ResetManager(); + return num_errors; } @@ -663,14 +731,14 @@ ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_addr, { DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions(); - StreamString install_errors; + DiagnosticManager install_diagnostics; - if (!dynamic_checkers->Install(install_errors, exe_ctx)) + if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) { - if (install_errors.GetString().empty()) - err.SetErrorString ("couldn't install checkers, unknown error"); + if (install_diagnostics.Diagnostics().size()) + err.SetErrorString("couldn't install checkers, unknown error"); else - err.SetErrorString (install_errors.GetString().c_str()); + err.SetErrorString(install_diagnostics.GetString().c_str()); return err; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h index 3c055380b83..832dce7ec57 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h @@ -10,11 +10,12 @@ #ifndef liblldb_ClangExpressionParser_h_ #define liblldb_ClangExpressionParser_h_ -#include "lldb/lldb-public.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ClangForward.h" #include "lldb/Core/Error.h" +#include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/ExpressionParser.h" +#include "lldb/lldb-public.h" #include <string> #include <vector> @@ -63,16 +64,16 @@ public: /// Parse a single expression and convert it to IR using Clang. Don't /// wrap the expression in anything at all. /// - /// @param[in] stream - /// The stream to print errors to. + /// @param[in] diagnostic_manager + /// The diagnostic manager to report errors to. /// /// @return /// The number of errors encountered during parsing. 0 means /// success. //------------------------------------------------------------------ unsigned - Parse (Stream &stream) override; - + Parse(DiagnosticManager &diagnostic_manager) override; + //------------------------------------------------------------------ /// Ready an already-parsed expression for execution, possibly /// evaluating it statically. @@ -98,7 +99,7 @@ public: /// /// @param[out] const_result /// If the result of the expression is constant, and the - /// expression has no side effects, this is set to the result of the + /// expression has no side effects, this is set to the result of the /// expression. /// /// @param[in] execution_policy diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp index 0d0d7475a00..a82394592c4 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp @@ -74,11 +74,11 @@ ClangFunctionCaller::~ClangFunctionCaller() } unsigned -ClangFunctionCaller::CompileFunction (Stream &errors) +ClangFunctionCaller::CompileFunction(DiagnosticManager &diagnostic_manager) { if (m_compiled) return 0; - + // FIXME: How does clang tell us there's no return value? We need to handle that case. unsigned num_errors = 0; @@ -143,8 +143,9 @@ ClangFunctionCaller::CompileFunction (Stream &errors) type_name = clang_qual_type.GetTypeName().AsCString(""); } else - { - errors.Printf("Could not determine type of input value %" PRIu64 ".", (uint64_t)i); + { + diagnostic_manager.Printf(eDiagnosticSeverityError, + "Could not determine type of input value %" PRIu64 ".", (uint64_t)i); return 1; } } @@ -195,15 +196,15 @@ ClangFunctionCaller::CompileFunction (Stream &errors) { const bool generate_debug_info = true; m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, generate_debug_info)); - - num_errors = m_parser->Parse (errors); + + num_errors = m_parser->Parse(diagnostic_manager); } else { - errors.Printf("no process - unable to inject function"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "no process - unable to inject function"); num_errors = 1; } - + m_compiled = (num_errors == 0); if (!m_compiled) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h index 3e30f818a93..f37c3b30472 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h @@ -137,17 +137,17 @@ public: //------------------------------------------------------------------ /// Compile the wrapper function /// - /// @param[in] errors - /// The stream to print parser errors to. + /// @param[in] diagnostic_manager + /// The diagnostic manager to report parser errors to. /// /// @return /// The number of errors. //------------------------------------------------------------------ unsigned - CompileFunction (Stream &errors) override; - + CompileFunction(DiagnosticManager &diagnostic_manager) override; + ExpressionTypeSystemHelper * - GetTypeSystemHelper () override + GetTypeSystemHelper() override { return &m_type_system_helper; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 11f7f84ff5f..25ac0e21711 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -326,11 +326,9 @@ ApplyObjcCastHack(std::string &expr) } bool -ClangUserExpression::Parse (Stream &error_stream, - ExecutionContext &exe_ctx, - lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, - bool generate_debug_info) +ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, + bool generate_debug_info) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); @@ -346,13 +344,13 @@ ClangUserExpression::Parse (Stream &error_stream, } else { - error_stream.PutCString ("error: couldn't start parsing (no persistent data)"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't start parsing (no persistent data)"); return false; } } else { - error_stream.PutCString ("error: couldn't start parsing (no target)"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "error: couldn't start parsing (no target)"); return false; } @@ -360,7 +358,7 @@ ClangUserExpression::Parse (Stream &error_stream, if (!err.Success()) { - error_stream.Printf("warning: %s\n", err.AsCString()); + diagnostic_manager.PutCString(eDiagnosticSeverityWarning, err.AsCString()); } StreamString m_transformed_stream; @@ -418,7 +416,7 @@ ClangUserExpression::Parse (Stream &error_stream, if (!source_code->GetText(m_transformed_text, lang_type, m_const_object, m_in_static_method, exe_ctx)) { - error_stream.PutCString ("error: couldn't construct expression body"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "couldn't construct expression body"); return false; } @@ -433,7 +431,7 @@ ClangUserExpression::Parse (Stream &error_stream, if (!target) { - error_stream.PutCString ("error: invalid target\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target"); return false; } @@ -467,7 +465,8 @@ ClangUserExpression::Parse (Stream &error_stream, if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) { - error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, + "current process state is unsuitable for expression parsing"); ResetDeclMap(); // We are being careful here in the case of breakpoint conditions. @@ -482,11 +481,12 @@ ClangUserExpression::Parse (Stream &error_stream, ClangExpressionParser parser(exe_scope, *this, generate_debug_info); - unsigned num_errors = parser.Parse (error_stream); + unsigned num_errors = parser.Parse(diagnostic_manager); if (num_errors) { - error_stream.Printf ("error: %d errors parsing expression\n", num_errors); + diagnostic_manager.Printf(eDiagnosticSeverityError, "%u error%s parsing expression", num_errors, + num_errors == 1 ? "" : "s"); ResetDeclMap(); // We are being careful here in the case of breakpoint conditions. @@ -547,22 +547,20 @@ ClangUserExpression::Parse (Stream &error_stream, { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) - error_stream.Printf ("error: %s\n", error_cstr); + diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr); else - error_stream.Printf ("error: expression can't be interpreted or run\n"); + diagnostic_manager.Printf(eDiagnosticSeverityError, "expression can't be interpreted or run"); return false; } } bool -ClangUserExpression::AddArguments (ExecutionContext &exe_ctx, - std::vector<lldb::addr_t> &args, - lldb::addr_t struct_address, - Stream &error_stream) +ClangUserExpression::AddArguments(ExecutionContext &exe_ctx, std::vector<lldb::addr_t> &args, + lldb::addr_t struct_address, DiagnosticManager &diagnostic_manager) { lldb::addr_t object_ptr = LLDB_INVALID_ADDRESS; - lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS; - + lldb::addr_t cmd_ptr = LLDB_INVALID_ADDRESS; + if (m_needs_object_ptr) { lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP(); @@ -581,7 +579,7 @@ ClangUserExpression::AddArguments (ExecutionContext &exe_ctx, } else { - error_stream.Printf("Need object pointer but don't know the language\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "need object pointer but don't know the language"); return false; } @@ -591,7 +589,9 @@ ClangUserExpression::AddArguments (ExecutionContext &exe_ctx, if (!object_ptr_error.Success()) { - error_stream.Printf("warning: couldn't get required object pointer (substituting NULL): %s\n", object_ptr_error.AsCString()); + diagnostic_manager.Printf(eDiagnosticSeverityWarning, + "couldn't get required object pointer (substituting NULL): %s", + object_ptr_error.AsCString()); object_ptr = 0; } @@ -603,7 +603,9 @@ ClangUserExpression::AddArguments (ExecutionContext &exe_ctx, if (!object_ptr_error.Success()) { - error_stream.Printf("warning: couldn't get cmd pointer (substituting NULL): %s\n", object_ptr_error.AsCString()); + diagnostic_manager.Printf(eDiagnosticSeverityWarning, + "couldn't get cmd pointer (substituting NULL): %s", + object_ptr_error.AsCString()); cmd_ptr = 0; } } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h index f2bfe31dce0..3177da358af 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h @@ -126,8 +126,8 @@ public: //------------------------------------------------------------------ /// Parse the expression /// - /// @param[in] error_stream - /// A stream to print parse errors and warnings to. + /// @param[in] diagnostic_manager + /// A diagnostic manager to report parse errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to use when looking up entities that @@ -145,11 +145,9 @@ public: /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool - Parse (Stream &error_stream, - ExecutionContext &exe_ctx, - lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, - bool generate_debug_info) override; + Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, + bool generate_debug_info) override; ExpressionTypeSystemHelper * GetTypeSystemHelper () override @@ -188,13 +186,11 @@ private: lldb_private::Error &err) override; bool - AddArguments (ExecutionContext &exe_ctx, - std::vector<lldb::addr_t> &args, - lldb::addr_t struct_address, - Stream &error_stream) override; - - ClangUserExpressionHelper m_type_system_helper; - + AddArguments(ExecutionContext &exe_ctx, std::vector<lldb::addr_t> &args, lldb::addr_t struct_address, + DiagnosticManager &diagnostic_manager) override; + + ClangUserExpressionHelper m_type_system_helper; + class ResultDelegate : public Materializer::PersistentVariableDelegate { public: diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp index fe044c17ac7..2a11be679fd 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp @@ -55,8 +55,8 @@ ClangUtilityFunction::~ClangUtilityFunction () //------------------------------------------------------------------ /// Install the utility function into a process /// -/// @param[in] error_stream -/// A stream to print parse errors and warnings to. +/// @param[in] diagnostic_manager +/// A diagnostic manager to report errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. @@ -65,35 +65,34 @@ ClangUtilityFunction::~ClangUtilityFunction () /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool -ClangUtilityFunction::Install (Stream &error_stream, - ExecutionContext &exe_ctx) +ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) { if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { - error_stream.PutCString("error: already installed\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityWarning, "already installed"); return false; } - + //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); - + if (!target) { - error_stream.PutCString ("error: invalid target\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target"); return false; } - + Process *process = exe_ctx.GetProcessPtr(); - + if (!process) { - error_stream.PutCString ("error: invalid process\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid process"); return false; } - + ////////////////////////// // Parse the expression // @@ -101,24 +100,26 @@ ClangUtilityFunction::Install (Stream &error_stream, bool keep_result_in_memory = false; ResetDeclMap(exe_ctx, keep_result_in_memory); - + if (!DeclMap()->WillParse(exe_ctx, NULL)) { - error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, + "current process state is unsuitable for expression parsing"); return false; } - + const bool generate_debug_info = true; ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this, generate_debug_info); - - unsigned num_errors = parser.Parse (error_stream); - + + unsigned num_errors = parser.Parse(diagnostic_manager); + if (num_errors) { - error_stream.Printf ("error: %d errors parsing expression\n", num_errors); - + diagnostic_manager.Printf(eDiagnosticSeverityError, "%d error%s parsing expression", num_errors, + num_errors == 1 ? "" : "s"); + ResetDeclMap(); - + return false; } @@ -175,9 +176,13 @@ ClangUtilityFunction::Install (Stream &error_stream, { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) - error_stream.Printf ("error: %s\n", error_cstr); + { + diagnostic_manager.Printf(eDiagnosticSeverityError, "%s", error_cstr); + } else - error_stream.Printf ("error: expression can't be interpreted or run\n"); + { + diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression can't be interpreted or run"); + } return false; } } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h index 74839717946..d4ed37eee04 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h @@ -124,12 +124,12 @@ public: { m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory); } - + bool - Install (Stream &error_stream, ExecutionContext &exe_ctx) override; - + Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override; + private: - ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when parsing and materializing the expression. + ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when parsing and materializing the expression. }; } // namespace lldb_private diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp index 0b074f87c16..0457bfe0f32 100644 --- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp @@ -26,7 +26,6 @@ // Project includes #include "GoUserExpression.h" -#include "lldb/lldb-private.h" #include "lldb/Core/ConstString.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/DataEncoder.h" @@ -37,10 +36,11 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectRegister.h" +#include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/ExpressionVariable.h" -#include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/GoASTContext.h" #include "lldb/Symbol/SymbolFile.h" +#include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/VariableList.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" @@ -49,6 +49,7 @@ #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" +#include "lldb/lldb-private.h" #include "Plugins/ExpressionParser/Go/GoAST.h" #include "Plugins/ExpressionParser/Go/GoParser.h" @@ -247,8 +248,9 @@ GoUserExpression::GoUserExpression(ExecutionContextScope &exe_scope, const char } bool -GoUserExpression::Parse(Stream &error_stream, ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, bool generate_debug_info) +GoUserExpression::Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, + bool generate_debug_info) { InstallContext(exe_ctx); m_interpreter.reset(new GoInterpreter(exe_ctx, GetUserText())); @@ -256,15 +258,16 @@ GoUserExpression::Parse(Stream &error_stream, ExecutionContext &exe_ctx, lldb_pr return true; const char *error_cstr = m_interpreter->error().AsCString(); if (error_cstr && error_cstr[0]) - error_stream.Printf("error: %s\n", error_cstr); + diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr); else - error_stream.Printf("error: expression can't be interpreted or run\n"); + diagnostic_manager.Printf(eDiagnosticSeverityError, "expression can't be interpreted or run"); return false; } lldb::ExpressionResults -GoUserExpression::Execute(Stream &error_stream, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, - lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result) +GoUserExpression::Execute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, + lldb::ExpressionVariableSP &result) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); @@ -281,7 +284,7 @@ GoUserExpression::Execute(Stream &error_stream, ExecutionContext &exe_ctx, const if (log) log->Printf("== [GoUserExpression::Evaluate] Expression may not run, but is not constant =="); - error_stream.Printf("expression needed to run but couldn't"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression needed to run but couldn't"); return execution_results; } @@ -296,9 +299,9 @@ GoUserExpression::Execute(Stream &error_stream, ExecutionContext &exe_ctx, const { const char *error_cstr = err.AsCString(); if (error_cstr && error_cstr[0]) - error_stream.Printf("error: %s\n", error_cstr); + diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr); else - error_stream.Printf("error: expression can't be interpreted or run\n"); + diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression can't be interpreted or run"); return lldb::eExpressionDiscarded; } result.reset(new ExpressionVariable(ExpressionVariable::eKindGo)); diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h index b429c68f023..4d6cdd2fcd1 100644 --- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h @@ -62,30 +62,31 @@ class GoPersistentExpressionState : public PersistentExpressionState class GoUserExpression : public UserExpression { public: - GoUserExpression(ExecutionContextScope &exe_scope, const char *expr, const char *expr_prefix, - lldb::LanguageType language, ResultType desired_type, const EvaluateExpressionOptions &options); - - bool - Parse(Stream &error_stream, ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, bool generate_debug_info) override; - - lldb::ExpressionResults - Execute(Stream &error_stream, ExecutionContext &exe_ctx, - const EvaluateExpressionOptions &options, - lldb::UserExpressionSP &shared_ptr_to_me, - lldb::ExpressionVariableSP &result) override; - - bool - CanInterpret() override - { - return true; - } - bool - FinalizeJITExecution(Stream &error_stream, ExecutionContext &exe_ctx, lldb::ExpressionVariableSP &result, - lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS, - lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override - { - return true; + GoUserExpression(ExecutionContextScope &exe_scope, const char *expr, const char *expr_prefix, + lldb::LanguageType language, ResultType desired_type, const EvaluateExpressionOptions &options); + + bool + Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, + bool generate_debug_info) override; + + lldb::ExpressionResults + Execute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, + lldb::ExpressionVariableSP &result) override; + + bool + CanInterpret() override + { + return true; + } + bool + FinalizeJITExecution(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + lldb::ExpressionVariableSP &result, + lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS, + lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override + { + return true; } private: |