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