From 579e70c9b0a0826daae6f4fbf704ad54b8e068a6 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Sat, 19 Mar 2016 00:03:59 +0000 Subject: Add a DiagnosticManager replace error streams in the expression parser. We want to do a better job presenting errors that occur when evaluating expressions. Key to this effort is getting away from a model where all errors are spat out onto a stream where the client has to take or leave all of them. To this end, this patch adds a new class, DiagnosticManager, which contains errors produced by the compiler or by LLDB as an expression is created. The DiagnosticManager can dump itself to a log as well as to a string. Clients will (in the future) be able to filter out the errors they're interested in by ID or present subsets of these errors to the user. This patch is not intended to change the *users* of errors - only to thread DiagnosticManagers to all the places where streams are used. I also attempt to standardize our use of errors a bit, removing trailing newlines and making clients omit 'error:', 'warning:' etc. and instead pass the Severity flag. The patch is testsuite-neutral, with modifications to one part of the MI tests because it relied on "error: error:" being erroneously printed. This patch fixes the MI variable handling and the testcase. llvm-svn: 263859 --- .../MacOSX/AppleGetThreadItemInfoHandler.cpp | 46 +++++++++++++--------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp') diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp index ba03f51152c..a528dafb97a 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp @@ -14,12 +14,12 @@ // Other libraries and framework includes // Project includes -#include "lldb/lldb-private.h" #include "lldb/Core/ConstString.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/Value.h" +#include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/Expression.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" @@ -30,6 +30,7 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/lldb-private.h" using namespace lldb; using namespace lldb_private; @@ -141,10 +142,10 @@ AppleGetThreadItemInfoHandler::Detach () lldb::addr_t AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, ValueList &get_thread_item_info_arglist) { - ExecutionContext exe_ctx (thread.shared_from_this()); + ExecutionContext exe_ctx(thread.shared_from_this()); Address impl_code_address; - StreamString errors; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME)); + DiagnosticManager diagnostics; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); lldb::addr_t args_addr = LLDB_INVALID_ADDRESS; FunctionCaller *get_thread_item_info_caller = nullptr; @@ -171,11 +172,15 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V m_get_thread_item_info_impl_code.reset(); return args_addr; } - - if (!m_get_thread_item_info_impl_code->Install(errors, exe_ctx)) + + if (!m_get_thread_item_info_impl_code->Install(diagnostics, exe_ctx)) { if (log) - log->Printf ("Failed to install get-thread-item-info introspection: %s.", errors.GetData()); + { + log->Printf("Failed to install get-thread-item-info introspection."); + diagnostics.Dump(log); + } + m_get_thread_item_info_impl_code.reset(); return args_addr; } @@ -184,10 +189,9 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V { if (log) log->Printf("No get-thread-item-info introspection code found."); - errors.Printf ("No get-thread-item-info introspection code found."); return LLDB_INVALID_ADDRESS; } - + // Also make the FunctionCaller for this UtilityFunction: ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext(); @@ -210,20 +214,24 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V get_thread_item_info_caller = m_get_thread_item_info_impl_code->GetFunctionCaller(); } } - - errors.Clear(); - + + diagnostics.Clear(); + // Now write down the argument values for this particular call. This looks like it might be a race condition // if other threads were calling into here, but actually it isn't because we allocate a new args structure for // this call by passing args_addr = LLDB_INVALID_ADDRESS... - if (!get_thread_item_info_caller->WriteFunctionArguments (exe_ctx, args_addr, get_thread_item_info_arglist, errors)) + if (!get_thread_item_info_caller->WriteFunctionArguments(exe_ctx, args_addr, get_thread_item_info_arglist, + diagnostics)) { if (log) - log->Printf ("Error writing get-thread-item-info function arguments: \"%s\".", errors.GetData()); + { + log->Printf("Error writing get-thread-item-info function arguments"); + diagnostics.Dump(log); + } return args_addr; } - + return args_addr; } @@ -324,13 +332,13 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo (Thread &thread, tid_t thread_i page_to_free_size_value.GetScalar() = page_to_free_size; argument_values.PushValue (page_to_free_size_value); - addr_t args_addr = SetupGetThreadItemInfoFunction (thread, argument_values); + addr_t args_addr = SetupGetThreadItemInfoFunction(thread, argument_values); - StreamString errors; + DiagnosticManager diagnostics; ExecutionContext exe_ctx; EvaluateExpressionOptions options; FunctionCaller *get_thread_item_info_caller = nullptr; - + options.SetUnwindOnError (true); options.SetIgnoreBreakpoints (true); options.SetStopOthers (true); @@ -354,7 +362,7 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo (Thread &thread, tid_t thread_i ExpressionResults func_call_ret; Value results; - func_call_ret = get_thread_item_info_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results); + func_call_ret = get_thread_item_info_caller->ExecuteFunction(exe_ctx, &args_addr, options, diagnostics, results); if (func_call_ret != eExpressionCompleted || !error.Success()) { if (log) -- cgit v1.2.3