Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanCallUserExpression.cpp -------------------------*- C++-*-===// |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Target/ThreadPlanCallUserExpression.h" |
| 11 | |
Jim Ingham | 46d005d | 2014-04-02 22:53:21 +0000 | [diff] [blame] | 12 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/Breakpoint.h" |
| 14 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 15 | #include "lldb/Core/Address.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/DiagnosticManager.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 17 | #include "lldb/Expression/IRDynamicChecks.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 18 | #include "lldb/Expression/UserExpression.h" |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 19 | #include "lldb/Host/HostInfo.h" |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 20 | #include "lldb/Target/LanguageRuntime.h" |
| 21 | #include "lldb/Target/Process.h" |
| 22 | #include "lldb/Target/RegisterContext.h" |
| 23 | #include "lldb/Target/StopInfo.h" |
| 24 | #include "lldb/Target/Target.h" |
| 25 | #include "lldb/Target/Thread.h" |
| 26 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 27 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 28 | #include "lldb/Utility/Stream.h" |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | //---------------------------------------------------------------------- |
| 34 | // ThreadPlanCallUserExpression: Plan to call a single function |
| 35 | //---------------------------------------------------------------------- |
| 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | ThreadPlanCallUserExpression::ThreadPlanCallUserExpression( |
| 38 | Thread &thread, Address &function, llvm::ArrayRef<lldb::addr_t> args, |
| 39 | const EvaluateExpressionOptions &options, |
| 40 | lldb::UserExpressionSP &user_expression_sp) |
| 41 | : ThreadPlanCallFunction(thread, function, CompilerType(), args, options), |
| 42 | m_user_expression_sp(user_expression_sp) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 43 | // User expressions are generally "User generated" so we should set them up |
| 44 | // to stop when done. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | SetIsMasterPlan(true); |
| 46 | SetOkayToDiscard(false); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression() {} |
| 50 | |
| 51 | void ThreadPlanCallUserExpression::GetDescription( |
| 52 | Stream *s, lldb::DescriptionLevel level) { |
| 53 | if (level == eDescriptionLevelBrief) |
| 54 | s->Printf("User Expression thread plan"); |
| 55 | else |
| 56 | ThreadPlanCallFunction::GetDescription(s, level); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Lang Hames | 8b38565 | 2017-05-05 22:42:13 +0000 | [diff] [blame] | 59 | void ThreadPlanCallUserExpression::DidPush() { |
| 60 | ThreadPlanCallFunction::DidPush(); |
| 61 | if (m_user_expression_sp) |
| 62 | m_user_expression_sp->WillStartExecuting(); |
| 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | void ThreadPlanCallUserExpression::WillPop() { |
| 66 | ThreadPlanCallFunction::WillPop(); |
| 67 | if (m_user_expression_sp) |
| 68 | m_user_expression_sp.reset(); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | bool ThreadPlanCallUserExpression::MischiefManaged() { |
| 72 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | if (IsPlanComplete()) { |
| 75 | if (log) |
| 76 | log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", |
| 77 | static_cast<void *>(this)); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) { |
| 80 | lldb::addr_t function_stack_top; |
| 81 | lldb::addr_t function_stack_bottom; |
| 82 | lldb::addr_t function_stack_pointer = GetFunctionStackPointer(); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); |
| 85 | function_stack_top = function_stack_pointer; |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 86 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | DiagnosticManager diagnostics; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | ExecutionContext exe_ctx(GetThread()); |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 90 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | m_user_expression_sp->FinalizeJITExecution( |
| 92 | diagnostics, exe_ctx, m_result_var_sp, function_stack_bottom, |
| 93 | function_stack_top); |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 94 | } |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | ThreadPlan::MischiefManaged(); |
| 97 | return true; |
| 98 | } else { |
| 99 | return false; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | StopInfoSP ThreadPlanCallUserExpression::GetRealStopInfo() { |
| 104 | StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo(); |
| 105 | |
| 106 | if (stop_info_sp) { |
| 107 | lldb::addr_t addr = GetStopAddress(); |
| 108 | DynamicCheckerFunctions *checkers = |
| 109 | m_thread.GetProcess()->GetDynamicCheckers(); |
| 110 | StreamString s; |
| 111 | |
| 112 | if (checkers && checkers->DoCheckersExplainStop(addr, s)) |
| 113 | stop_info_sp->SetDescription(s.GetData()); |
| 114 | } |
| 115 | |
| 116 | return stop_info_sp; |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 117 | } |
Lang Hames | 8b38565 | 2017-05-05 22:42:13 +0000 | [diff] [blame] | 118 | |
| 119 | void ThreadPlanCallUserExpression::DoTakedown(bool success) { |
| 120 | ThreadPlanCallFunction::DoTakedown(success); |
| 121 | m_user_expression_sp->DidFinishExecuting(); |
| 122 | } |