Summary: This patch is the MVP version of importing the std module into the expression parser to improve C++ debugging. What happens in this patch is that we inject a `@import std` into our expression source code. We also modify our internal Clang instance for parsing this expression to work with modules and debug info at the same time (which is the main change in terms of LOC). We implicitly build the `std` module on the first use. The C++ include paths for building are extracted from the debug info, which means that this currently only works if the program is compiled with `-glldb -fmodules` and uses the std module. The C include paths are currently specified by LLDB. I enabled the tests currently only for libc++ and Linux because I could test this locally. I'll enable the tests for other platforms once this has landed and doesn't break any bots (and I implemented the platform-specific C include paths for them). With this patch we can now: * Build a libc++ as a module and import it into the expression parser. * Read from the module while also referencing declarations from the debug info. E.g. `std::abs(local_variable)`. What doesn't work (yet): * Merging debug info and C++ module declarations. E.g. `std::vector<CustomClass>` doesn't work. * Pretty much anything that involves the ASTImporter and templated code. As the ASTImporter is used for saving the result declaration, this means that we can't call yet any function that returns a non-trivial type. * Use libstdc++ for this, as it requires multiple include paths and Clang only emits one include path per module. Also libstdc++ doesn't support Clang modules without patches. Reviewers: aprantl, jingham, shafik, friss, davide, serge-sans-paille Reviewed By: aprantl Subscribers: labath, mgorny, abidh, jdoerfert, lldb-commits Tags: #c_modules_in_lldb, #lldb Differential Revision: https://reviews.llvm.org/D58125 llvm-svn: 355939
71 lines
2.7 KiB
C++
71 lines
2.7 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 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,
|
|
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
|