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