Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 1 | //===-- LLVMUserExpression.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 | // C Includes |
| 11 | // C++ Includes |
| 12 | |
| 13 | // Project includes |
| 14 | #include "lldb/Expression/LLVMUserExpression.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Module.h" |
| 16 | #include "lldb/Core/StreamFile.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ValueObjectConstResult.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 18 | #include "lldb/Expression/DiagnosticManager.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 19 | #include "lldb/Expression/ExpressionSourceCode.h" |
| 20 | #include "lldb/Expression/IRExecutionUnit.h" |
| 21 | #include "lldb/Expression/IRInterpreter.h" |
| 22 | #include "lldb/Expression/Materializer.h" |
| 23 | #include "lldb/Host/HostInfo.h" |
| 24 | #include "lldb/Symbol/Block.h" |
| 25 | #include "lldb/Symbol/ClangASTContext.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 26 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/Function.h" |
| 28 | #include "lldb/Symbol/ObjectFile.h" |
| 29 | #include "lldb/Symbol/SymbolVendor.h" |
| 30 | #include "lldb/Symbol/Type.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/VariableList.h" |
| 32 | #include "lldb/Target/ExecutionContext.h" |
| 33 | #include "lldb/Target/Process.h" |
| 34 | #include "lldb/Target/StackFrame.h" |
| 35 | #include "lldb/Target/Target.h" |
| 36 | #include "lldb/Target/ThreadPlan.h" |
| 37 | #include "lldb/Target/ThreadPlanCallUserExpression.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 38 | #include "lldb/Utility/ConstString.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 39 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 40 | #include "lldb/Utility/StreamString.h" |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 41 | |
| 42 | using namespace lldb_private; |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope, |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 45 | llvm::StringRef expr, |
| 46 | llvm::StringRef prefix, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | lldb::LanguageType language, |
| 48 | ResultType desired_type, |
Jim Ingham | 19a63fc | 2015-11-03 02:11:24 +0000 | [diff] [blame] | 49 | const EvaluateExpressionOptions &options) |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 50 | : UserExpression(exe_scope, expr, prefix, language, desired_type, options), |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 51 | m_stack_frame_bottom(LLDB_INVALID_ADDRESS), |
Bruce Mitchener | ef4536c | 2017-03-23 09:52:26 +0000 | [diff] [blame] | 52 | m_stack_frame_top(LLDB_INVALID_ADDRESS), |
Jason Molenda | ab2dae0 | 2017-03-21 02:59:15 +0000 | [diff] [blame] | 53 | m_allow_cxx(false), |
| 54 | m_allow_objc(false), |
Bruce Mitchener | ef4536c | 2017-03-23 09:52:26 +0000 | [diff] [blame] | 55 | m_transformed_text(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | m_execution_unit_sp(), m_materializer_ap(), m_jit_module_wp(), |
| 57 | m_enforce_valid_object(true), m_in_cplusplus_method(false), |
| 58 | m_in_objectivec_method(false), m_in_static_method(false), |
| 59 | m_needs_object_ptr(false), m_target(NULL), m_can_interpret(false), |
| 60 | m_materialized_address(LLDB_INVALID_ADDRESS) {} |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | LLVMUserExpression::~LLVMUserExpression() { |
| 63 | if (m_target) { |
| 64 | lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock()); |
| 65 | if (jit_module_sp) |
| 66 | m_target->GetImages().Remove(jit_module_sp); |
| 67 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | lldb::ExpressionResults |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, |
| 72 | ExecutionContext &exe_ctx, |
| 73 | const EvaluateExpressionOptions &options, |
| 74 | lldb::UserExpressionSP &shared_ptr_to_me, |
| 75 | lldb::ExpressionVariableSP &result) { |
| 76 | // The expression log is quite verbose, and if you're just tracking the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 77 | // execution of the expression, it's quite convenient to have these logs come |
| 78 | // out with the STEP log as well. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | |
| 80 | LIBLLDB_LOG_STEP)); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret) { |
| 83 | lldb::addr_t struct_address = LLDB_INVALID_ADDRESS; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | if (!PrepareToExecuteJITExpression(diagnostic_manager, exe_ctx, |
| 86 | struct_address)) { |
| 87 | diagnostic_manager.Printf( |
| 88 | eDiagnosticSeverityError, |
| 89 | "errored out in %s, couldn't PrepareToExecuteJITExpression", |
| 90 | __FUNCTION__); |
| 91 | return lldb::eExpressionSetupError; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 92 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | |
| 94 | lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS; |
| 95 | lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS; |
| 96 | |
| 97 | if (m_can_interpret) { |
| 98 | llvm::Module *module = m_execution_unit_sp->GetModule(); |
| 99 | llvm::Function *function = m_execution_unit_sp->GetFunction(); |
| 100 | |
| 101 | if (!module || !function) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 102 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | eDiagnosticSeverityError, |
| 104 | "supposed to interpret, but nothing is there"); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 105 | return lldb::eExpressionSetupError; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 107 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 108 | Status interpreter_error; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | std::vector<lldb::addr_t> args; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 113 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | "errored out in %s, couldn't AddArguments", |
| 115 | __FUNCTION__); |
| 116 | return lldb::eExpressionSetupError; |
| 117 | } |
| 118 | |
| 119 | function_stack_bottom = m_stack_frame_bottom; |
| 120 | function_stack_top = m_stack_frame_top; |
| 121 | |
| 122 | IRInterpreter::Interpret(*module, *function, args, |
| 123 | *m_execution_unit_sp.get(), interpreter_error, |
| 124 | function_stack_bottom, function_stack_top, |
| 125 | exe_ctx); |
| 126 | |
| 127 | if (!interpreter_error.Success()) { |
| 128 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 129 | "supposed to interpret, but failed: %s", |
| 130 | interpreter_error.AsCString()); |
| 131 | return lldb::eExpressionDiscarded; |
| 132 | } |
| 133 | } else { |
| 134 | if (!exe_ctx.HasThreadScope()) { |
| 135 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 136 | "%s called with no thread selected", |
| 137 | __FUNCTION__); |
| 138 | return lldb::eExpressionSetupError; |
| 139 | } |
| 140 | |
| 141 | Address wrapper_address(m_jit_start_addr); |
| 142 | |
| 143 | std::vector<lldb::addr_t> args; |
| 144 | |
| 145 | if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { |
| 146 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 147 | "errored out in %s, couldn't AddArguments", |
| 148 | __FUNCTION__); |
| 149 | return lldb::eExpressionSetupError; |
| 150 | } |
| 151 | |
| 152 | lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression( |
| 153 | exe_ctx.GetThreadRef(), wrapper_address, args, options, |
| 154 | shared_ptr_to_me)); |
| 155 | |
| 156 | StreamString ss; |
| 157 | if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) { |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 158 | diagnostic_manager.PutString(eDiagnosticSeverityError, ss.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 159 | return lldb::eExpressionSetupError; |
| 160 | } |
| 161 | |
| 162 | ThreadPlanCallUserExpression *user_expression_plan = |
| 163 | static_cast<ThreadPlanCallUserExpression *>(call_plan_sp.get()); |
| 164 | |
| 165 | lldb::addr_t function_stack_pointer = |
| 166 | user_expression_plan->GetFunctionStackPointer(); |
| 167 | |
| 168 | function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); |
| 169 | function_stack_top = function_stack_pointer; |
| 170 | |
| 171 | if (log) |
| 172 | log->Printf( |
| 173 | "-- [UserExpression::Execute] Execution of expression begins --"); |
| 174 | |
| 175 | if (exe_ctx.GetProcessPtr()) |
| 176 | exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); |
| 177 | |
| 178 | lldb::ExpressionResults execution_result = |
| 179 | exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx, call_plan_sp, options, |
| 180 | diagnostic_manager); |
| 181 | |
| 182 | if (exe_ctx.GetProcessPtr()) |
| 183 | exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); |
| 184 | |
| 185 | if (log) |
| 186 | log->Printf("-- [UserExpression::Execute] Execution of expression " |
| 187 | "completed --"); |
| 188 | |
| 189 | if (execution_result == lldb::eExpressionInterrupted || |
| 190 | execution_result == lldb::eExpressionHitBreakpoint) { |
| 191 | const char *error_desc = NULL; |
| 192 | |
| 193 | if (call_plan_sp) { |
| 194 | lldb::StopInfoSP real_stop_info_sp = call_plan_sp->GetRealStopInfo(); |
| 195 | if (real_stop_info_sp) |
| 196 | error_desc = real_stop_info_sp->GetDescription(); |
| 197 | } |
| 198 | if (error_desc) |
| 199 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 200 | "Execution was interrupted, reason: %s.", |
| 201 | error_desc); |
| 202 | else |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 203 | diagnostic_manager.PutString(eDiagnosticSeverityError, |
| 204 | "Execution was interrupted."); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | |
| 206 | if ((execution_result == lldb::eExpressionInterrupted && |
| 207 | options.DoesUnwindOnError()) || |
| 208 | (execution_result == lldb::eExpressionHitBreakpoint && |
| 209 | options.DoesIgnoreBreakpoints())) |
| 210 | diagnostic_manager.AppendMessageToDiagnostic( |
| 211 | "The process has been returned to the state before expression " |
| 212 | "evaluation."); |
| 213 | else { |
| 214 | if (execution_result == lldb::eExpressionHitBreakpoint) |
| 215 | user_expression_plan->TransferExpressionOwnership(); |
| 216 | diagnostic_manager.AppendMessageToDiagnostic( |
| 217 | "The process has been left at the point where it was " |
| 218 | "interrupted, " |
| 219 | "use \"thread return -x\" to return to the state before " |
| 220 | "expression evaluation."); |
| 221 | } |
| 222 | |
| 223 | return execution_result; |
| 224 | } else if (execution_result == lldb::eExpressionStoppedForDebug) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 225 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | eDiagnosticSeverityRemark, |
| 227 | "Execution was halted at the first instruction of the expression " |
| 228 | "function because \"debug\" was requested.\n" |
| 229 | "Use \"thread return -x\" to return to the state before expression " |
| 230 | "evaluation."); |
| 231 | return execution_result; |
| 232 | } else if (execution_result != lldb::eExpressionCompleted) { |
| 233 | diagnostic_manager.Printf( |
| 234 | eDiagnosticSeverityError, |
| 235 | "Couldn't execute function; result was %s", |
| 236 | Process::ExecutionResultAsCString(execution_result)); |
| 237 | return execution_result; |
| 238 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | if (FinalizeJITExecution(diagnostic_manager, exe_ctx, result, |
| 242 | function_stack_bottom, function_stack_top)) { |
| 243 | return lldb::eExpressionCompleted; |
| 244 | } else { |
| 245 | return lldb::eExpressionResultUnavailable; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 246 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | } else { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 248 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 249 | eDiagnosticSeverityError, |
| 250 | "Expression can't be run, because there is no JIT compiled function"); |
| 251 | return lldb::eExpressionSetupError; |
| 252 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | bool LLVMUserExpression::FinalizeJITExecution( |
| 256 | DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 257 | lldb::ExpressionVariableSP &result, lldb::addr_t function_stack_bottom, |
| 258 | lldb::addr_t function_stack_top) { |
| 259 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 260 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | if (log) |
| 262 | log->Printf("-- [UserExpression::FinalizeJITExecution] Dematerializing " |
| 263 | "after execution --"); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 264 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | if (!m_dematerializer_sp) { |
| 266 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 267 | "Couldn't apply expression side effects : no " |
| 268 | "dematerializer is present"); |
| 269 | return false; |
| 270 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 271 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 272 | Status dematerialize_error; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | m_dematerializer_sp->Dematerialize(dematerialize_error, function_stack_bottom, |
| 275 | function_stack_top); |
Jim Ingham | 2c38141 | 2015-11-04 20:32:27 +0000 | [diff] [blame] | 276 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 277 | if (!dematerialize_error.Success()) { |
| 278 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 279 | "Couldn't apply expression side effects : %s", |
| 280 | dematerialize_error.AsCString("unknown error")); |
| 281 | return false; |
| 282 | } |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 283 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 | result = |
| 285 | GetResultAfterDematerialization(exe_ctx.GetBestExecutionContextScope()); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 286 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 287 | if (result) |
| 288 | result->TransferAddress(); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | m_dematerializer_sp.reset(); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 291 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | return true; |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 295 | bool LLVMUserExpression::PrepareToExecuteJITExpression( |
| 296 | DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, |
| 297 | lldb::addr_t &struct_address) { |
| 298 | lldb::TargetSP target; |
| 299 | lldb::ProcessSP process; |
| 300 | lldb::StackFrameSP frame; |
| 301 | |
| 302 | if (!LockAndCheckContext(exe_ctx, target, process, frame)) { |
Zachary Turner | e2411fa | 2016-11-12 19:12:56 +0000 | [diff] [blame] | 303 | diagnostic_manager.PutString( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 304 | eDiagnosticSeverityError, |
| 305 | "The context has changed before we could JIT the expression!"); |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret) { |
| 310 | if (m_materialized_address == LLDB_INVALID_ADDRESS) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 311 | Status alloc_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 312 | |
| 313 | IRMemoryMap::AllocationPolicy policy = |
| 314 | m_can_interpret ? IRMemoryMap::eAllocationPolicyHostOnly |
| 315 | : IRMemoryMap::eAllocationPolicyMirror; |
| 316 | |
| 317 | const bool zero_memory = false; |
| 318 | |
| 319 | m_materialized_address = m_execution_unit_sp->Malloc( |
| 320 | m_materializer_ap->GetStructByteSize(), |
| 321 | m_materializer_ap->GetStructAlignment(), |
| 322 | lldb::ePermissionsReadable | lldb::ePermissionsWritable, policy, |
| 323 | zero_memory, alloc_error); |
| 324 | |
| 325 | if (!alloc_error.Success()) { |
| 326 | diagnostic_manager.Printf( |
| 327 | eDiagnosticSeverityError, |
| 328 | "Couldn't allocate space for materialized struct: %s", |
| 329 | alloc_error.AsCString()); |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | struct_address = m_materialized_address; |
| 335 | |
| 336 | if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 337 | Status alloc_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | |
| 339 | const size_t stack_frame_size = 512 * 1024; |
| 340 | |
| 341 | const bool zero_memory = false; |
| 342 | |
| 343 | m_stack_frame_bottom = m_execution_unit_sp->Malloc( |
| 344 | stack_frame_size, 8, |
| 345 | lldb::ePermissionsReadable | lldb::ePermissionsWritable, |
| 346 | IRMemoryMap::eAllocationPolicyHostOnly, zero_memory, alloc_error); |
| 347 | |
| 348 | m_stack_frame_top = m_stack_frame_bottom + stack_frame_size; |
| 349 | |
| 350 | if (!alloc_error.Success()) { |
| 351 | diagnostic_manager.Printf( |
| 352 | eDiagnosticSeverityError, |
| 353 | "Couldn't allocate space for the stack frame: %s", |
| 354 | alloc_error.AsCString()); |
| 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 359 | Status materialize_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 360 | |
| 361 | m_dematerializer_sp = m_materializer_ap->Materialize( |
| 362 | frame, *m_execution_unit_sp, struct_address, materialize_error); |
| 363 | |
| 364 | if (!materialize_error.Success()) { |
| 365 | diagnostic_manager.Printf(eDiagnosticSeverityError, |
| 366 | "Couldn't materialize: %s", |
| 367 | materialize_error.AsCString()); |
| 368 | return false; |
| 369 | } |
| 370 | } |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | lldb::ModuleSP LLVMUserExpression::GetJITModule() { |
| 375 | if (m_execution_unit_sp) |
| 376 | return m_execution_unit_sp->GetJITModule(); |
| 377 | return lldb::ModuleSP(); |
Ryan Brown | 998c8a1c1 | 2015-11-02 19:30:40 +0000 | [diff] [blame] | 378 | } |