Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
Raphael Isemann 71569d0d52 Inject only relevant local variables in the expression evaluation context
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
2019-05-02 10:12:56 +00:00

72 lines
2.8 KiB
C++

//===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ClangExpressionSourceCode_h
#define liblldb_ClangExpressionSourceCode_h
#include "lldb/Expression/Expression.h"
#include "lldb/Expression/ExpressionSourceCode.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include <string>
namespace lldb_private {
class ExecutionContext;
class ClangExpressionSourceCode : public ExpressionSourceCode {
public:
static const char *g_expression_prefix;
static ClangExpressionSourceCode *CreateWrapped(const char *prefix,
const char *body) {
return new ClangExpressionSourceCode("$__lldb_expr", prefix, body, true);
}
uint32_t GetNumBodyLines();
/// Generates the source code that will evaluate the expression.
///
/// \param text output parameter containing the source code string.
/// \param wrapping_language If the expression is supossed to be wrapped,
/// then this is the language that should be used for that.
/// \param static_method True iff the expression is valuated inside a static
/// Objective-C method.
/// \param exe_ctx The execution context in which the expression will be
/// evaluated.
/// \param add_locals True iff local variables should be injected into the
/// expression source code.
/// \param force_add_all_locals True iff all local variables should be
/// injected even if they are not used in the expression.
/// \param modules A list of (C++) modules that the expression should import.
///
/// \return true iff the source code was successfully generated.
bool GetText(std::string &text, lldb::LanguageType wrapping_language,
bool static_method, ExecutionContext &exe_ctx, bool add_locals,
bool force_add_all_locals,
llvm::ArrayRef<std::string> modules) const;
// Given a string returned by GetText, find the beginning and end of the body
// passed to CreateWrapped. Return true if the bounds could be found. This
// will also work on text with FixItHints applied.
static bool GetOriginalBodyBounds(std::string transformed_text,
lldb::LanguageType wrapping_language,
size_t &start_loc, size_t &end_loc);
protected:
ClangExpressionSourceCode(const char *name, const char *prefix, const char *body,
bool wrap) :
ExpressionSourceCode(name, prefix, body, wrap) {}
};
} // namespace lldb_private
#endif