Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanCallUserExpression.cpp ------------------------------*- C++ -*-===// |
| 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 |
| 17 | #include "lldb/lldb-private-log.h" |
| 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" |
| 23 | #include "lldb/Expression/ClangUserExpression.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame^] | 24 | #include "lldb/Expression/IRDynamicChecks.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 | |
| 41 | ThreadPlanCallUserExpression::ThreadPlanCallUserExpression (Thread &thread, |
| 42 | Address &function, |
Sean Callanan | a464f3d | 2013-11-08 01:14:26 +0000 | [diff] [blame] | 43 | llvm::ArrayRef<lldb::addr_t> args, |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 44 | const EvaluateExpressionOptions &options, |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 45 | ClangUserExpression::ClangUserExpressionSP &user_expression_sp) : |
Sean Callanan | a464f3d | 2013-11-08 01:14:26 +0000 | [diff] [blame] | 46 | ThreadPlanCallFunction (thread, function, ClangASTType(), args, options), |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 47 | m_user_expression_sp (user_expression_sp) |
| 48 | { |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 49 | // User expressions are generally "User generated" so we should set them up to stop when done. |
| 50 | SetIsMasterPlan (true); |
| 51 | SetOkayToDiscard(false); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | ThreadPlanCallUserExpression::~ThreadPlanCallUserExpression () |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | ThreadPlanCallUserExpression::GetDescription (Stream *s, lldb::DescriptionLevel level) |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 60 | { |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 61 | if (level == eDescriptionLevelBrief) |
| 62 | s->Printf("User Expression thread plan"); |
| 63 | else |
| 64 | ThreadPlanCallFunction::GetDescription (s, level); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | ThreadPlanCallUserExpression::WillPop () |
| 69 | { |
| 70 | ThreadPlanCallFunction::WillPop(); |
| 71 | if (m_user_expression_sp) |
| 72 | m_user_expression_sp.reset(); |
| 73 | } |
| 74 | |
| 75 | bool |
| 76 | ThreadPlanCallUserExpression::MischiefManaged () |
| 77 | { |
| 78 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 79 | |
| 80 | if (IsPlanComplete()) |
| 81 | { |
| 82 | if (log) |
| 83 | log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", |
| 84 | static_cast<void*>(this)); |
| 85 | |
| 86 | if (m_manage_materialization && PlanSucceeded() && m_user_expression_sp) |
| 87 | { |
| 88 | lldb::addr_t function_stack_top; |
| 89 | lldb::addr_t function_stack_bottom; |
| 90 | lldb::addr_t function_stack_pointer = GetFunctionStackPointer(); |
| 91 | |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 92 | function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 93 | function_stack_top = function_stack_pointer; |
| 94 | |
| 95 | StreamString error_stream; |
| 96 | |
| 97 | ExecutionContext exe_ctx(GetThread()); |
| 98 | |
| 99 | m_user_expression_sp->FinalizeJITExecution(error_stream, exe_ctx, m_result_var_sp, function_stack_bottom, function_stack_top); |
| 100 | } |
| 101 | |
| 102 | ThreadPlan::MischiefManaged (); |
| 103 | return true; |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | return false; |
| 108 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 109 | } |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 110 | |
| 111 | StopInfoSP |
| 112 | ThreadPlanCallUserExpression::GetRealStopInfo() |
| 113 | { |
| 114 | StopInfoSP stop_info_sp = ThreadPlanCallFunction::GetRealStopInfo(); |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 115 | |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 116 | if (stop_info_sp) |
| 117 | { |
| 118 | lldb::addr_t addr = GetStopAddress(); |
| 119 | DynamicCheckerFunctions *checkers = m_thread.GetProcess()->GetDynamicCheckers(); |
| 120 | StreamString s; |
| 121 | |
| 122 | if (checkers && checkers->DoCheckersExplainStop(addr, s)) |
| 123 | stop_info_sp->SetDescription(s.GetData()); |
| 124 | } |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 125 | |
| 126 | return stop_info_sp; |
| 127 | } |