diff options
Diffstat (limited to 'source/Expression/UserExpression.cpp')
-rw-r--r-- | source/Expression/UserExpression.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/source/Expression/UserExpression.cpp b/source/Expression/UserExpression.cpp index 34945fdcbfa1..a72e2a07599e 100644 --- a/source/Expression/UserExpression.cpp +++ b/source/Expression/UserExpression.cpp @@ -1,9 +1,8 @@ //===-- UserExpression.cpp ---------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -16,12 +15,11 @@ #include <map> #include <string> -#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Expression/DiagnosticManager.h" -#include "lldb/Expression/ExpressionSourceCode.h" +#include "lldb/Expression/ExpressionVariable.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRInterpreter.h" #include "lldb/Expression/Materializer.h" @@ -50,8 +48,9 @@ UserExpression::UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, ResultType desired_type, - const EvaluateExpressionOptions &options) - : Expression(exe_scope), m_expr_text(expr), m_expr_prefix(prefix), + const EvaluateExpressionOptions &options, + ExpressionKind kind) + : Expression(exe_scope, kind), m_expr_text(expr), m_expr_prefix(prefix), m_language(language), m_desired_type(desired_type), m_options(options) {} UserExpression::~UserExpression() {} @@ -140,11 +139,23 @@ lldb::addr_t UserExpression::GetObjectPointer(lldb::StackFrameSP frame_sp, lldb::ExpressionResults UserExpression::Evaluate( ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr, llvm::StringRef prefix, - lldb::ValueObjectSP &result_valobj_sp, Status &error, uint32_t line_offset, - std::string *fixed_expression, lldb::ModuleSP *jit_module_sp_ptr) { + lldb::ValueObjectSP &result_valobj_sp, Status &error, + std::string *fixed_expression, lldb::ModuleSP *jit_module_sp_ptr, + ValueObject *ctx_obj) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); + if (ctx_obj) { + static unsigned const ctx_type_mask = + lldb::TypeFlags::eTypeIsClass | lldb::TypeFlags::eTypeIsStructUnion; + if (!(ctx_obj->GetTypeInfo() & ctx_type_mask)) { + LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of " + "an invalid type, can't run expressions."); + error.SetErrorString("a context object of an invalid type passed"); + return lldb::eExpressionSetupError; + } + } + lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy(); lldb::LanguageType language = options.GetLanguage(); const ResultType desired_type = options.DoesCoerceToId() @@ -163,7 +174,7 @@ lldb::ExpressionResults UserExpression::Evaluate( Process *process = exe_ctx.GetProcessPtr(); - if (process == NULL || process->GetState() != lldb::eStateStopped) { + if (process == nullptr || process->GetState() != lldb::eStateStopped) { if (execution_policy == eExecutionPolicyAlways) { if (log) log->Printf("== [UserExpression::Evaluate] Expression may not run, but " @@ -175,7 +186,7 @@ lldb::ExpressionResults UserExpression::Evaluate( } } - if (process == NULL || !process->CanJIT()) + if (process == nullptr || !process->CanJIT()) execution_policy = eExecutionPolicyNever; // We need to set the expression execution thread here, turns out parse can @@ -209,7 +220,8 @@ lldb::ExpressionResults UserExpression::Evaluate( lldb::UserExpressionSP user_expression_sp( target->GetUserExpressionForLanguage(expr, full_prefix, language, - desired_type, options, error)); + desired_type, options, ctx_obj, + error)); if (error.Fail()) { if (log) log->Printf("== [UserExpression::Evaluate] Getting expression: %s ==", @@ -254,7 +266,8 @@ lldb::ExpressionResults UserExpression::Evaluate( lldb::UserExpressionSP fixed_expression_sp( target->GetUserExpressionForLanguage(fixed_expression->c_str(), full_prefix, language, - desired_type, options, error)); + desired_type, options, ctx_obj, + error)); DiagnosticManager fixed_diagnostic_manager; parse_success = fixed_expression_sp->Parse( fixed_diagnostic_manager, exe_ctx, execution_policy, @@ -362,7 +375,7 @@ lldb::ExpressionResults UserExpression::Evaluate( return lldb::eExpressionInterrupted; } - if (result_valobj_sp.get() == NULL) { + if (result_valobj_sp.get() == nullptr) { result_valobj_sp = ValueObjectConstResult::Create( exe_ctx.GetBestExecutionContextScope(), error); } |