Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionUtil.h
Michael Buch 8184b252cd [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas
This patch adds support for evaluating expressions which reference
a captured `this` from within the context of a C++ lambda expression.
Currently LLDB doesn't provide Clang with enough information to
determine that we're inside a lambda expression and are allowed to
access variables on a captured `this`; instead Clang simply fails
to parse the expression.

There are two problems to solve here:
1. Make sure `clang::Sema` doesn't reject the expression due to an
illegal member access.
2. Materialize all the captured variables/member variables required
to evaluate the expression.

To address (1), we currently import the outer structure's AST context
onto `$__lldb_class`, making the `contextClass` and the `NamingClass`
match, a requirement by `clang::Sema::BuildPossibleImplicitMemberExpr`.

To address (2), we inject all captured variables as locals into the
expression source code.

**Testing**

* Added API test
2022-07-22 08:02:09 +01:00

31 lines
1.2 KiB
C++

//===-- ClangExpressionUtil.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 LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONUTIL_H
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONUTIL_H
#include "lldb/lldb-private.h"
namespace lldb_private {
namespace ClangExpressionUtil {
/// Returns a ValueObject for the lambda class in the current frame
///
/// To represent a lambda, Clang generates an artificial class
/// whose members are the captures and whose operator() is the
/// lambda implementation. If we capture a 'this' pointer,
/// the artifical class will contain a member variable named 'this'.
///
/// This method returns the 'this' pointer to the artificial lambda
/// class if a real 'this' was captured. Otherwise, returns nullptr.
lldb::ValueObjectSP GetLambdaValueObject(StackFrame *frame);
} // namespace ClangExpressionUtil
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONHELPER_H