From 71569d0d523465203ba465a89c37d75075a5e2c2 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Thu, 2 May 2019 10:12:56 +0000 Subject: Inject only relevant local variables in the expression evaluation context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: In r259902, LLDB started injecting all the locals in every expression evaluation. This fixed a bunch of issues, but also caused others, mostly performance regressions on some codebases. The regressions were bad enough that we added a setting in r274783 to control the behavior and we have been shipping with the setting off to avoid the perf regressions. This patch changes the logic injecting the local variables to only inject the ones present in the expression typed by the user. The approach is fairly simple and just scans the typed expression for every local name. Hopefully this gives us the best of both world as it just realizes the types of the variables really used by the expression. Landing this requires the 2 other issues I pointed out today to be addressed but I wanted to gather comments right away. Original patch by Frédéric Riss! Reviewers: jingham, clayborg, friss, shafik Reviewed By: jingham, clayborg Subscribers: teemperor, labath, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D46551 llvm-svn: 359773 --- .../Plugins/ExpressionParser/Clang/ClangUserExpression.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp') diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 8e08d4d7554..9fcf2d49845 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -386,7 +386,7 @@ static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) { void ClangUserExpression::UpdateLanguageForExpr( DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, - std::vector modules_to_import) { + std::vector modules_to_import, bool for_completion) { m_expr_lang = lldb::LanguageType::eLanguageTypeUnknown; std::string prefix = m_expr_prefix; @@ -407,7 +407,7 @@ void ClangUserExpression::UpdateLanguageForExpr( if (!source_code->GetText(m_transformed_text, m_expr_lang, m_in_static_method, exe_ctx, !m_ctx_obj, - modules_to_import)) { + for_completion, modules_to_import)) { diagnostic_manager.PutString(eDiagnosticSeverityError, "couldn't construct expression body"); return; @@ -482,7 +482,8 @@ ClangUserExpression::GetModulesToImport(ExecutionContext &exe_ctx) { } bool ClangUserExpression::PrepareForParsing( - DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) { + DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, + bool for_completion) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); InstallContext(exe_ctx); @@ -511,7 +512,8 @@ bool ClangUserExpression::PrepareForParsing( LLDB_LOG(log, "List of imported modules in expression: {0}", llvm::make_range(used_modules.begin(), used_modules.end())); - UpdateLanguageForExpr(diagnostic_manager, exe_ctx, used_modules); + UpdateLanguageForExpr(diagnostic_manager, exe_ctx, used_modules, + for_completion); return true; } @@ -522,7 +524,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, bool generate_debug_info) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - if (!PrepareForParsing(diagnostic_manager, exe_ctx)) + if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ false)) return false; if (log) @@ -721,7 +723,7 @@ bool ClangUserExpression::Complete(ExecutionContext &exe_ctx, // correct. DiagnosticManager diagnostic_manager; - if (!PrepareForParsing(diagnostic_manager, exe_ctx)) + if (!PrepareForParsing(diagnostic_manager, exe_ctx, /*for_completion*/ true)) return false; if (log) -- cgit v1.2.3