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