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
28 lines
900 B
C++
28 lines
900 B
C++
//===-- ClangExpressionUtil.cpp -------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ClangExpressionUtil.h"
|
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
#include "lldb/Target/StackFrame.h"
|
|
#include "lldb/Utility/ConstString.h"
|
|
|
|
namespace lldb_private {
|
|
namespace ClangExpressionUtil {
|
|
lldb::ValueObjectSP GetLambdaValueObject(StackFrame *frame) {
|
|
assert(frame);
|
|
|
|
if (auto this_val_sp = frame->FindVariable(ConstString("this")))
|
|
if (this_val_sp->GetChildMemberWithName(ConstString("this"), true))
|
|
return this_val_sp;
|
|
|
|
return nullptr;
|
|
}
|
|
} // namespace ClangExpressionUtil
|
|
} // namespace lldb_private
|