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