15ffd83dbSDimitry Andric //===-- LLVMUserExpression.cpp --------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric #include "lldb/Expression/LLVMUserExpression.h" 110b57cec5SDimitry Andric #include "lldb/Core/Module.h" 120b57cec5SDimitry Andric #include "lldb/Core/ValueObjectConstResult.h" 130b57cec5SDimitry Andric #include "lldb/Expression/DiagnosticManager.h" 149dba64beSDimitry Andric #include "lldb/Expression/ExpressionVariable.h" 150b57cec5SDimitry Andric #include "lldb/Expression/IRExecutionUnit.h" 160b57cec5SDimitry Andric #include "lldb/Expression/IRInterpreter.h" 170b57cec5SDimitry Andric #include "lldb/Expression/Materializer.h" 180b57cec5SDimitry Andric #include "lldb/Host/HostInfo.h" 190b57cec5SDimitry Andric #include "lldb/Symbol/Block.h" 200b57cec5SDimitry Andric #include "lldb/Symbol/Function.h" 210b57cec5SDimitry Andric #include "lldb/Symbol/ObjectFile.h" 220b57cec5SDimitry Andric #include "lldb/Symbol/SymbolVendor.h" 230b57cec5SDimitry Andric #include "lldb/Symbol/Type.h" 240b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h" 2506c3fb27SDimitry Andric #include "lldb/Target/ABI.h" 260b57cec5SDimitry Andric #include "lldb/Target/ExecutionContext.h" 270b57cec5SDimitry Andric #include "lldb/Target/Process.h" 280b57cec5SDimitry Andric #include "lldb/Target/StackFrame.h" 290b57cec5SDimitry Andric #include "lldb/Target/Target.h" 300b57cec5SDimitry Andric #include "lldb/Target/ThreadPlan.h" 310b57cec5SDimitry Andric #include "lldb/Target/ThreadPlanCallUserExpression.h" 320b57cec5SDimitry Andric #include "lldb/Utility/ConstString.h" 3381ad6265SDimitry Andric #include "lldb/Utility/LLDBLog.h" 340b57cec5SDimitry Andric #include "lldb/Utility/Log.h" 350b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h" 360b57cec5SDimitry Andric 3706c3fb27SDimitry Andric using namespace lldb; 380b57cec5SDimitry Andric using namespace lldb_private; 390b57cec5SDimitry Andric 40480093f4SDimitry Andric char LLVMUserExpression::ID; 41480093f4SDimitry Andric 420b57cec5SDimitry Andric LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope, 430b57cec5SDimitry Andric llvm::StringRef expr, 440b57cec5SDimitry Andric llvm::StringRef prefix, 45*0fca6ea1SDimitry Andric SourceLanguage language, 460b57cec5SDimitry Andric ResultType desired_type, 47480093f4SDimitry Andric const EvaluateExpressionOptions &options) 48480093f4SDimitry Andric : UserExpression(exe_scope, expr, prefix, language, desired_type, options), 490b57cec5SDimitry Andric m_stack_frame_bottom(LLDB_INVALID_ADDRESS), 500b57cec5SDimitry Andric m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false), 510b57cec5SDimitry Andric m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(), 52bdd1243dSDimitry Andric m_materializer_up(), m_jit_module_wp(), m_target(nullptr), 53bdd1243dSDimitry Andric m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {} 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric LLVMUserExpression::~LLVMUserExpression() { 560b57cec5SDimitry Andric if (m_target) { 570b57cec5SDimitry Andric lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock()); 580b57cec5SDimitry Andric if (jit_module_sp) 590b57cec5SDimitry Andric m_target->GetImages().Remove(jit_module_sp); 600b57cec5SDimitry Andric } 610b57cec5SDimitry Andric } 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric lldb::ExpressionResults 640b57cec5SDimitry Andric LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, 650b57cec5SDimitry Andric ExecutionContext &exe_ctx, 660b57cec5SDimitry Andric const EvaluateExpressionOptions &options, 670b57cec5SDimitry Andric lldb::UserExpressionSP &shared_ptr_to_me, 680b57cec5SDimitry Andric lldb::ExpressionVariableSP &result) { 690b57cec5SDimitry Andric // The expression log is quite verbose, and if you're just tracking the 700b57cec5SDimitry Andric // execution of the expression, it's quite convenient to have these logs come 710b57cec5SDimitry Andric // out with the STEP log as well. 7281ad6265SDimitry Andric Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); 730b57cec5SDimitry Andric 74480093f4SDimitry Andric if (m_jit_start_addr == LLDB_INVALID_ADDRESS && !m_can_interpret) { 75480093f4SDimitry Andric diagnostic_manager.PutString( 76*0fca6ea1SDimitry Andric lldb::eSeverityError, 77480093f4SDimitry Andric "Expression can't be run, because there is no JIT compiled function"); 78480093f4SDimitry Andric return lldb::eExpressionSetupError; 79480093f4SDimitry Andric } 80480093f4SDimitry Andric 810b57cec5SDimitry Andric lldb::addr_t struct_address = LLDB_INVALID_ADDRESS; 820b57cec5SDimitry Andric 830b57cec5SDimitry Andric if (!PrepareToExecuteJITExpression(diagnostic_manager, exe_ctx, 840b57cec5SDimitry Andric struct_address)) { 850b57cec5SDimitry Andric diagnostic_manager.Printf( 86*0fca6ea1SDimitry Andric lldb::eSeverityError, 870b57cec5SDimitry Andric "errored out in %s, couldn't PrepareToExecuteJITExpression", 880b57cec5SDimitry Andric __FUNCTION__); 890b57cec5SDimitry Andric return lldb::eExpressionSetupError; 900b57cec5SDimitry Andric } 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS; 930b57cec5SDimitry Andric lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric if (m_can_interpret) { 960b57cec5SDimitry Andric llvm::Module *module = m_execution_unit_sp->GetModule(); 970b57cec5SDimitry Andric llvm::Function *function = m_execution_unit_sp->GetFunction(); 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric if (!module || !function) { 1000b57cec5SDimitry Andric diagnostic_manager.PutString( 101*0fca6ea1SDimitry Andric lldb::eSeverityError, "supposed to interpret, but nothing is there"); 1020b57cec5SDimitry Andric return lldb::eExpressionSetupError; 1030b57cec5SDimitry Andric } 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric Status interpreter_error; 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric std::vector<lldb::addr_t> args; 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { 110*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 1110b57cec5SDimitry Andric "errored out in %s, couldn't AddArguments", 1120b57cec5SDimitry Andric __FUNCTION__); 1130b57cec5SDimitry Andric return lldb::eExpressionSetupError; 1140b57cec5SDimitry Andric } 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric function_stack_bottom = m_stack_frame_bottom; 1170b57cec5SDimitry Andric function_stack_top = m_stack_frame_top; 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andric IRInterpreter::Interpret(*module, *function, args, *m_execution_unit_sp, 1200b57cec5SDimitry Andric interpreter_error, function_stack_bottom, 1215f757f3fSDimitry Andric function_stack_top, exe_ctx, options.GetTimeout()); 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric if (!interpreter_error.Success()) { 124*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 1250b57cec5SDimitry Andric "supposed to interpret, but failed: %s", 1260b57cec5SDimitry Andric interpreter_error.AsCString()); 1270b57cec5SDimitry Andric return lldb::eExpressionDiscarded; 1280b57cec5SDimitry Andric } 1290b57cec5SDimitry Andric } else { 1300b57cec5SDimitry Andric if (!exe_ctx.HasThreadScope()) { 131*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 1320b57cec5SDimitry Andric "%s called with no thread selected", 1330b57cec5SDimitry Andric __FUNCTION__); 1340b57cec5SDimitry Andric return lldb::eExpressionSetupError; 1350b57cec5SDimitry Andric } 1360b57cec5SDimitry Andric 1375ffd83dbSDimitry Andric // Store away the thread ID for error reporting, in case it exits 1385ffd83dbSDimitry Andric // during execution: 1395ffd83dbSDimitry Andric lldb::tid_t expr_thread_id = exe_ctx.GetThreadRef().GetID(); 1405ffd83dbSDimitry Andric 1410b57cec5SDimitry Andric Address wrapper_address(m_jit_start_addr); 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric std::vector<lldb::addr_t> args; 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andric if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { 146*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 1470b57cec5SDimitry Andric "errored out in %s, couldn't AddArguments", 1480b57cec5SDimitry Andric __FUNCTION__); 1490b57cec5SDimitry Andric return lldb::eExpressionSetupError; 1500b57cec5SDimitry Andric } 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression( 1530b57cec5SDimitry Andric exe_ctx.GetThreadRef(), wrapper_address, args, options, 1540b57cec5SDimitry Andric shared_ptr_to_me)); 1550b57cec5SDimitry Andric 1560b57cec5SDimitry Andric StreamString ss; 1570b57cec5SDimitry Andric if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) { 158*0fca6ea1SDimitry Andric diagnostic_manager.PutString(lldb::eSeverityError, ss.GetString()); 1590b57cec5SDimitry Andric return lldb::eExpressionSetupError; 1600b57cec5SDimitry Andric } 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andric ThreadPlanCallUserExpression *user_expression_plan = 1630b57cec5SDimitry Andric static_cast<ThreadPlanCallUserExpression *>(call_plan_sp.get()); 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric lldb::addr_t function_stack_pointer = 1660b57cec5SDimitry Andric user_expression_plan->GetFunctionStackPointer(); 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andric function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); 1690b57cec5SDimitry Andric function_stack_top = function_stack_pointer; 1700b57cec5SDimitry Andric 171480093f4SDimitry Andric LLDB_LOGF(log, 1720b57cec5SDimitry Andric "-- [UserExpression::Execute] Execution of expression begins --"); 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric if (exe_ctx.GetProcessPtr()) 1750b57cec5SDimitry Andric exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric lldb::ExpressionResults execution_result = 1780b57cec5SDimitry Andric exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx, call_plan_sp, options, 1790b57cec5SDimitry Andric diagnostic_manager); 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric if (exe_ctx.GetProcessPtr()) 1820b57cec5SDimitry Andric exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); 1830b57cec5SDimitry Andric 1849dba64beSDimitry Andric LLDB_LOGF(log, "-- [UserExpression::Execute] Execution of expression " 1850b57cec5SDimitry Andric "completed --"); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric if (execution_result == lldb::eExpressionInterrupted || 1880b57cec5SDimitry Andric execution_result == lldb::eExpressionHitBreakpoint) { 1890b57cec5SDimitry Andric const char *error_desc = nullptr; 1900b57cec5SDimitry Andric 191fe6060f1SDimitry Andric if (user_expression_plan) { 192fe6060f1SDimitry Andric if (auto real_stop_info_sp = user_expression_plan->GetRealStopInfo()) 1930b57cec5SDimitry Andric error_desc = real_stop_info_sp->GetDescription(); 1940b57cec5SDimitry Andric } 1950b57cec5SDimitry Andric if (error_desc) 196*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 1970b57cec5SDimitry Andric "Execution was interrupted, reason: %s.", 1980b57cec5SDimitry Andric error_desc); 1990b57cec5SDimitry Andric else 200*0fca6ea1SDimitry Andric diagnostic_manager.PutString(lldb::eSeverityError, 2010b57cec5SDimitry Andric "Execution was interrupted."); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric if ((execution_result == lldb::eExpressionInterrupted && 2040b57cec5SDimitry Andric options.DoesUnwindOnError()) || 2050b57cec5SDimitry Andric (execution_result == lldb::eExpressionHitBreakpoint && 2060b57cec5SDimitry Andric options.DoesIgnoreBreakpoints())) 2070b57cec5SDimitry Andric diagnostic_manager.AppendMessageToDiagnostic( 2080b57cec5SDimitry Andric "The process has been returned to the state before expression " 2090b57cec5SDimitry Andric "evaluation."); 2100b57cec5SDimitry Andric else { 2110b57cec5SDimitry Andric if (execution_result == lldb::eExpressionHitBreakpoint) 2120b57cec5SDimitry Andric user_expression_plan->TransferExpressionOwnership(); 2130b57cec5SDimitry Andric diagnostic_manager.AppendMessageToDiagnostic( 2140b57cec5SDimitry Andric "The process has been left at the point where it was " 2150b57cec5SDimitry Andric "interrupted, " 2160b57cec5SDimitry Andric "use \"thread return -x\" to return to the state before " 2170b57cec5SDimitry Andric "expression evaluation."); 2180b57cec5SDimitry Andric } 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andric return execution_result; 2210b57cec5SDimitry Andric } else if (execution_result == lldb::eExpressionStoppedForDebug) { 2220b57cec5SDimitry Andric diagnostic_manager.PutString( 223*0fca6ea1SDimitry Andric lldb::eSeverityInfo, 2240b57cec5SDimitry Andric "Execution was halted at the first instruction of the expression " 2250b57cec5SDimitry Andric "function because \"debug\" was requested.\n" 2260b57cec5SDimitry Andric "Use \"thread return -x\" to return to the state before expression " 2270b57cec5SDimitry Andric "evaluation."); 2280b57cec5SDimitry Andric return execution_result; 2295ffd83dbSDimitry Andric } else if (execution_result == lldb::eExpressionThreadVanished) { 2305ffd83dbSDimitry Andric diagnostic_manager.Printf( 231*0fca6ea1SDimitry Andric lldb::eSeverityError, 2325ffd83dbSDimitry Andric "Couldn't complete execution; the thread " 2335ffd83dbSDimitry Andric "on which the expression was being run: 0x%" PRIx64 2345ffd83dbSDimitry Andric " exited during its execution.", 2355ffd83dbSDimitry Andric expr_thread_id); 2365ffd83dbSDimitry Andric return execution_result; 2370b57cec5SDimitry Andric } else if (execution_result != lldb::eExpressionCompleted) { 2380b57cec5SDimitry Andric diagnostic_manager.Printf( 239*0fca6ea1SDimitry Andric lldb::eSeverityError, "Couldn't execute function; result was %s", 2400b57cec5SDimitry Andric Process::ExecutionResultAsCString(execution_result)); 2410b57cec5SDimitry Andric return execution_result; 2420b57cec5SDimitry Andric } 2430b57cec5SDimitry Andric } 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andric if (FinalizeJITExecution(diagnostic_manager, exe_ctx, result, 2460b57cec5SDimitry Andric function_stack_bottom, function_stack_top)) { 2470b57cec5SDimitry Andric return lldb::eExpressionCompleted; 2480b57cec5SDimitry Andric } else { 2490b57cec5SDimitry Andric return lldb::eExpressionResultUnavailable; 2500b57cec5SDimitry Andric } 2510b57cec5SDimitry Andric } 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric bool LLVMUserExpression::FinalizeJITExecution( 2540b57cec5SDimitry Andric DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, 2550b57cec5SDimitry Andric lldb::ExpressionVariableSP &result, lldb::addr_t function_stack_bottom, 2560b57cec5SDimitry Andric lldb::addr_t function_stack_top) { 25781ad6265SDimitry Andric Log *log = GetLog(LLDBLog::Expressions); 2580b57cec5SDimitry Andric 2599dba64beSDimitry Andric LLDB_LOGF(log, "-- [UserExpression::FinalizeJITExecution] Dematerializing " 2600b57cec5SDimitry Andric "after execution --"); 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric if (!m_dematerializer_sp) { 263*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 2640b57cec5SDimitry Andric "Couldn't apply expression side effects : no " 2650b57cec5SDimitry Andric "dematerializer is present"); 2660b57cec5SDimitry Andric return false; 2670b57cec5SDimitry Andric } 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andric Status dematerialize_error; 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andric m_dematerializer_sp->Dematerialize(dematerialize_error, function_stack_bottom, 2720b57cec5SDimitry Andric function_stack_top); 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric if (!dematerialize_error.Success()) { 275*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 2760b57cec5SDimitry Andric "Couldn't apply expression side effects : %s", 2770b57cec5SDimitry Andric dematerialize_error.AsCString("unknown error")); 2780b57cec5SDimitry Andric return false; 2790b57cec5SDimitry Andric } 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric result = 2820b57cec5SDimitry Andric GetResultAfterDematerialization(exe_ctx.GetBestExecutionContextScope()); 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andric if (result) 2850b57cec5SDimitry Andric result->TransferAddress(); 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andric m_dematerializer_sp.reset(); 2880b57cec5SDimitry Andric 2890b57cec5SDimitry Andric return true; 2900b57cec5SDimitry Andric } 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andric bool LLVMUserExpression::PrepareToExecuteJITExpression( 2930b57cec5SDimitry Andric DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, 2940b57cec5SDimitry Andric lldb::addr_t &struct_address) { 2950b57cec5SDimitry Andric lldb::TargetSP target; 2960b57cec5SDimitry Andric lldb::ProcessSP process; 2970b57cec5SDimitry Andric lldb::StackFrameSP frame; 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andric if (!LockAndCheckContext(exe_ctx, target, process, frame)) { 3000b57cec5SDimitry Andric diagnostic_manager.PutString( 301*0fca6ea1SDimitry Andric lldb::eSeverityError, 3020b57cec5SDimitry Andric "The context has changed before we could JIT the expression!"); 3030b57cec5SDimitry Andric return false; 3040b57cec5SDimitry Andric } 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andric if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret) { 3070b57cec5SDimitry Andric if (m_materialized_address == LLDB_INVALID_ADDRESS) { 3080b57cec5SDimitry Andric Status alloc_error; 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andric IRMemoryMap::AllocationPolicy policy = 3110b57cec5SDimitry Andric m_can_interpret ? IRMemoryMap::eAllocationPolicyHostOnly 3120b57cec5SDimitry Andric : IRMemoryMap::eAllocationPolicyMirror; 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andric const bool zero_memory = false; 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric m_materialized_address = m_execution_unit_sp->Malloc( 3170b57cec5SDimitry Andric m_materializer_up->GetStructByteSize(), 3180b57cec5SDimitry Andric m_materializer_up->GetStructAlignment(), 3190b57cec5SDimitry Andric lldb::ePermissionsReadable | lldb::ePermissionsWritable, policy, 3200b57cec5SDimitry Andric zero_memory, alloc_error); 3210b57cec5SDimitry Andric 3220b57cec5SDimitry Andric if (!alloc_error.Success()) { 3230b57cec5SDimitry Andric diagnostic_manager.Printf( 324*0fca6ea1SDimitry Andric lldb::eSeverityError, 3250b57cec5SDimitry Andric "Couldn't allocate space for materialized struct: %s", 3260b57cec5SDimitry Andric alloc_error.AsCString()); 3270b57cec5SDimitry Andric return false; 3280b57cec5SDimitry Andric } 3290b57cec5SDimitry Andric } 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric struct_address = m_materialized_address; 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andric if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) { 3340b57cec5SDimitry Andric Status alloc_error; 3350b57cec5SDimitry Andric 33606c3fb27SDimitry Andric size_t stack_frame_size = target->GetExprAllocSize(); 33706c3fb27SDimitry Andric if (stack_frame_size == 0) { 33806c3fb27SDimitry Andric ABISP abi_sp; 33906c3fb27SDimitry Andric if (process && (abi_sp = process->GetABI())) 34006c3fb27SDimitry Andric stack_frame_size = abi_sp->GetStackFrameSize(); 34106c3fb27SDimitry Andric else 34206c3fb27SDimitry Andric stack_frame_size = 512 * 1024; 34306c3fb27SDimitry Andric } 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric const bool zero_memory = false; 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric m_stack_frame_bottom = m_execution_unit_sp->Malloc( 3480b57cec5SDimitry Andric stack_frame_size, 8, 3490b57cec5SDimitry Andric lldb::ePermissionsReadable | lldb::ePermissionsWritable, 3500b57cec5SDimitry Andric IRMemoryMap::eAllocationPolicyHostOnly, zero_memory, alloc_error); 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andric m_stack_frame_top = m_stack_frame_bottom + stack_frame_size; 3530b57cec5SDimitry Andric 3540b57cec5SDimitry Andric if (!alloc_error.Success()) { 3550b57cec5SDimitry Andric diagnostic_manager.Printf( 356*0fca6ea1SDimitry Andric lldb::eSeverityError, 3570b57cec5SDimitry Andric "Couldn't allocate space for the stack frame: %s", 3580b57cec5SDimitry Andric alloc_error.AsCString()); 3590b57cec5SDimitry Andric return false; 3600b57cec5SDimitry Andric } 3610b57cec5SDimitry Andric } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric Status materialize_error; 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric m_dematerializer_sp = m_materializer_up->Materialize( 3660b57cec5SDimitry Andric frame, *m_execution_unit_sp, struct_address, materialize_error); 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric if (!materialize_error.Success()) { 369*0fca6ea1SDimitry Andric diagnostic_manager.Printf(lldb::eSeverityError, 3700b57cec5SDimitry Andric "Couldn't materialize: %s", 3710b57cec5SDimitry Andric materialize_error.AsCString()); 3720b57cec5SDimitry Andric return false; 3730b57cec5SDimitry Andric } 3740b57cec5SDimitry Andric } 3750b57cec5SDimitry Andric return true; 3760b57cec5SDimitry Andric } 3770b57cec5SDimitry Andric 378