Path: blob/main/contrib/llvm-project/lldb/source/Target/ThreadPlanCallUserExpression.cpp
39587 views
//===-- ThreadPlanCallUserExpression.cpp ----------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Target/ThreadPlanCallUserExpression.h"910#include "lldb/Breakpoint/Breakpoint.h"11#include "lldb/Breakpoint/BreakpointLocation.h"12#include "lldb/Core/Address.h"13#include "lldb/Expression/DiagnosticManager.h"14#include "lldb/Expression/DynamicCheckerFunctions.h"15#include "lldb/Expression/UserExpression.h"16#include "lldb/Host/HostInfo.h"17#include "lldb/Target/LanguageRuntime.h"18#include "lldb/Target/Process.h"19#include "lldb/Target/RegisterContext.h"20#include "lldb/Target/StopInfo.h"21#include "lldb/Target/Target.h"22#include "lldb/Target/Thread.h"23#include "lldb/Target/ThreadPlanRunToAddress.h"24#include "lldb/Utility/LLDBLog.h"25#include "lldb/Utility/Log.h"26#include "lldb/Utility/Stream.h"2728using namespace lldb;29using namespace lldb_private;3031// ThreadPlanCallUserExpression: Plan to call a single function3233ThreadPlanCallUserExpression::ThreadPlanCallUserExpression(34Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args,35const EvaluateExpressionOptions &options,36lldb::UserExpressionSP &user_expression_sp)37: ThreadPlanCallFunction(thread, function, CompilerType(), args, options),38m_user_expression_sp(user_expression_sp) {39// User expressions are generally "User generated" so we should set them up40// to stop when done.41SetIsControllingPlan(true);42SetOkayToDiscard(false);43}4445ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() = default;4647void ThreadPlanCallUserExpression::GetDescription(48Stream *s, lldb::DescriptionLevel level) {49if (level == eDescriptionLevelBrief)50s->Printf("User Expression thread plan");51else52ThreadPlanCallFunction::GetDescription(s, level);53}5455void ThreadPlanCallUserExpression::DidPush() {56ThreadPlanCallFunction::DidPush();57if (m_user_expression_sp)58m_user_expression_sp->WillStartExecuting();59}6061void ThreadPlanCallUserExpression::DidPop() {62ThreadPlanCallFunction::DidPop();63if (m_user_expression_sp)64m_user_expression_sp.reset();65}6667bool ThreadPlanCallUserExpression::MischiefManaged() {68Log *log = GetLog(LLDBLog::Step);6970if (IsPlanComplete()) {71LLDB_LOGF(log, "ThreadPlanCallFunction(%p): Completed call function plan.",72static_cast<void *>(this));7374if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) {75lldb::addr_t function_stack_top;76lldb::addr_t function_stack_bottom;77lldb::addr_t function_stack_pointer = GetFunctionStackPointer();7879function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();80function_stack_top = function_stack_pointer;8182DiagnosticManager diagnostics;8384ExecutionContext exe_ctx(GetThread());8586m_user_expression_sp->FinalizeJITExecution(87diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom,88function_stack_top);89}9091ThreadPlan::MischiefManaged();92return true;93} else {94return false;95}96}9798StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() {99StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo();100101if (stop_info_sp) {102lldb::addr_t addr = GetStopAddress();103DynamicCheckerFunctions *checkers = m_process.GetDynamicCheckers();104StreamString s;105106if (checkers && checkers->DoCheckersExplainStop(addr, s))107stop_info_sp->SetDescription(s.GetData());108}109110return stop_info_sp;111}112113void ThreadPlanCallUserExpression::DoTakedown(bool success) {114ThreadPlanCallFunction::DoTakedown(success);115m_user_expression_sp->DidFinishExecuting();116}117118119