Summary: The ClangModulesDeclVendor is currently interpreting all injected `@import` statements in our expression wrapper as modules that the user has explicitly requested to be persistently loaded. As we inject `@import` statements with our std module prototype, the ClangModulesDeclVendor will start compiling and loading unrelated C++ modules because it thinks the user has requested that it should load them. As the ClangModulesDeclVendor is lacking the setup to compile these modules (e.g. it lacks the include paths), it will then actually just fail to compile them and cause the whole expression evaluation to fail. This causes these tests to fail on systems that enable the ClangModulesDeclVendor (such as macOS). This patch fixes this by preventing the ClangModulesDeclVendor from interpreting `@import` statements in the wrapper source code. This is done by check if the import happens in the fake source file containing our wrapper code (which implies it was generated by LLDB). This patch doesn't reenable the tests as there is more work needed to get the tests running on macOS (D67760) Reviewers: aprantl, shafik, jingham Subscribers: lldb-commits Tags: #c_modules_in_lldb, #lldb Differential Revision: https://reviews.llvm.org/D61565 llvm-svn: 372690
81 lines
3.2 KiB
C++
81 lines
3.2 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:
|
|
/// The file name we use for the wrapper code that we inject before
|
|
/// the user expression.
|
|
static const llvm::StringRef g_prefix_file_name;
|
|
static const char *g_expression_prefix;
|
|
|
|
static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename,
|
|
llvm::StringRef prefix,
|
|
llvm::StringRef body) {
|
|
return new ClangExpressionSourceCode(filename, "$__lldb_expr", prefix, body,
|
|
Wrap);
|
|
}
|
|
|
|
/// 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.
|
|
bool GetOriginalBodyBounds(std::string transformed_text,
|
|
lldb::LanguageType wrapping_language,
|
|
size_t &start_loc, size_t &end_loc);
|
|
|
|
protected:
|
|
ClangExpressionSourceCode(llvm::StringRef filename, llvm::StringRef name,
|
|
llvm::StringRef prefix, llvm::StringRef body,
|
|
Wrapping wrap);
|
|
|
|
private:
|
|
/// String marking the start of the user expression.
|
|
std::string m_start_marker;
|
|
/// String marking the end of the user expression.
|
|
std::string m_end_marker;
|
|
};
|
|
|
|
} // namespace lldb_private
|
|
|
|
#endif
|