diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 | 
| commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
| tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /lldb/source/Expression/LLVMUserExpression.cpp | |
| parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
Notes
Diffstat (limited to 'lldb/source/Expression/LLVMUserExpression.cpp')
| -rw-r--r-- | lldb/source/Expression/LLVMUserExpression.cpp | 298 | 
1 files changed, 148 insertions, 150 deletions
| diff --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp index 99e0c11df420..1fc878bbd616 100644 --- a/lldb/source/Expression/LLVMUserExpression.cpp +++ b/lldb/source/Expression/LLVMUserExpression.cpp @@ -35,20 +35,20 @@  using namespace lldb_private; +char LLVMUserExpression::ID; +  LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,                                         llvm::StringRef expr,                                         llvm::StringRef prefix,                                         lldb::LanguageType language,                                         ResultType desired_type, -                                       const EvaluateExpressionOptions &options, -                                       ExpressionKind kind) -    : UserExpression(exe_scope, expr, prefix, language, desired_type, options, -                     kind), +                                       const EvaluateExpressionOptions &options) +    : UserExpression(exe_scope, expr, prefix, language, desired_type, options),        m_stack_frame_bottom(LLDB_INVALID_ADDRESS),        m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false),        m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(), -      m_materializer_up(), m_jit_module_wp(), -      m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {} +      m_materializer_up(), m_jit_module_wp(), m_can_interpret(false), +      m_materialized_address(LLDB_INVALID_ADDRESS) {}  LLVMUserExpression::~LLVMUserExpression() {    if (m_target) { @@ -70,174 +70,172 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,    Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |                                                    LIBLLDB_LOG_STEP)); -  if (m_jit_start_addr != LLDB_INVALID_ADDRESS || m_can_interpret) { -    lldb::addr_t struct_address = LLDB_INVALID_ADDRESS; +  if (m_jit_start_addr == LLDB_INVALID_ADDRESS && !m_can_interpret) { +    diagnostic_manager.PutString( +        eDiagnosticSeverityError, +        "Expression can't be run, because there is no JIT compiled function"); +    return lldb::eExpressionSetupError; +  } -    if (!PrepareToExecuteJITExpression(diagnostic_manager, exe_ctx, -                                       struct_address)) { -      diagnostic_manager.Printf( +  lldb::addr_t struct_address = LLDB_INVALID_ADDRESS; + +  if (!PrepareToExecuteJITExpression(diagnostic_manager, exe_ctx, +                                     struct_address)) { +    diagnostic_manager.Printf( +        eDiagnosticSeverityError, +        "errored out in %s, couldn't PrepareToExecuteJITExpression", +        __FUNCTION__); +    return lldb::eExpressionSetupError; +  } + +  lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS; +  lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS; + +  if (m_can_interpret) { +    llvm::Module *module = m_execution_unit_sp->GetModule(); +    llvm::Function *function = m_execution_unit_sp->GetFunction(); + +    if (!module || !function) { +      diagnostic_manager.PutString(            eDiagnosticSeverityError, -          "errored out in %s, couldn't PrepareToExecuteJITExpression", -          __FUNCTION__); +          "supposed to interpret, but nothing is there");        return lldb::eExpressionSetupError;      } -    lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS; -    lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS; +    Status interpreter_error; -    if (m_can_interpret) { -      llvm::Module *module = m_execution_unit_sp->GetModule(); -      llvm::Function *function = m_execution_unit_sp->GetFunction(); +    std::vector<lldb::addr_t> args; -      if (!module || !function) { -        diagnostic_manager.PutString( -            eDiagnosticSeverityError, -            "supposed to interpret, but nothing is there"); -        return lldb::eExpressionSetupError; -      } +    if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { +      diagnostic_manager.Printf(eDiagnosticSeverityError, +                                "errored out in %s, couldn't AddArguments", +                                __FUNCTION__); +      return lldb::eExpressionSetupError; +    } -      Status interpreter_error; +    function_stack_bottom = m_stack_frame_bottom; +    function_stack_top = m_stack_frame_top; -      std::vector<lldb::addr_t> args; +    IRInterpreter::Interpret(*module, *function, args, *m_execution_unit_sp, +                             interpreter_error, function_stack_bottom, +                             function_stack_top, exe_ctx); -      if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { -        diagnostic_manager.Printf(eDiagnosticSeverityError, -                                  "errored out in %s, couldn't AddArguments", -                                  __FUNCTION__); -        return lldb::eExpressionSetupError; -      } +    if (!interpreter_error.Success()) { +      diagnostic_manager.Printf(eDiagnosticSeverityError, +                                "supposed to interpret, but failed: %s", +                                interpreter_error.AsCString()); +      return lldb::eExpressionDiscarded; +    } +  } else { +    if (!exe_ctx.HasThreadScope()) { +      diagnostic_manager.Printf(eDiagnosticSeverityError, +                                "%s called with no thread selected", +                                __FUNCTION__); +      return lldb::eExpressionSetupError; +    } -      function_stack_bottom = m_stack_frame_bottom; -      function_stack_top = m_stack_frame_top; +    Address wrapper_address(m_jit_start_addr); -      IRInterpreter::Interpret(*module, *function, args, *m_execution_unit_sp, -                               interpreter_error, function_stack_bottom, -                               function_stack_top, exe_ctx); +    std::vector<lldb::addr_t> args; -      if (!interpreter_error.Success()) { -        diagnostic_manager.Printf(eDiagnosticSeverityError, -                                  "supposed to interpret, but failed: %s", -                                  interpreter_error.AsCString()); -        return lldb::eExpressionDiscarded; -      } -    } else { -      if (!exe_ctx.HasThreadScope()) { -        diagnostic_manager.Printf(eDiagnosticSeverityError, -                                  "%s called with no thread selected", -                                  __FUNCTION__); -        return lldb::eExpressionSetupError; -      } +    if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { +      diagnostic_manager.Printf(eDiagnosticSeverityError, +                                "errored out in %s, couldn't AddArguments", +                                __FUNCTION__); +      return lldb::eExpressionSetupError; +    } -      Address wrapper_address(m_jit_start_addr); +    lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression( +        exe_ctx.GetThreadRef(), wrapper_address, args, options, +        shared_ptr_to_me)); -      std::vector<lldb::addr_t> args; +    StreamString ss; +    if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) { +      diagnostic_manager.PutString(eDiagnosticSeverityError, ss.GetString()); +      return lldb::eExpressionSetupError; +    } -      if (!AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) { -        diagnostic_manager.Printf(eDiagnosticSeverityError, -                                  "errored out in %s, couldn't AddArguments", -                                  __FUNCTION__); -        return lldb::eExpressionSetupError; -      } +    ThreadPlanCallUserExpression *user_expression_plan = +        static_cast<ThreadPlanCallUserExpression *>(call_plan_sp.get()); -      lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression( -          exe_ctx.GetThreadRef(), wrapper_address, args, options, -          shared_ptr_to_me)); +    lldb::addr_t function_stack_pointer = +        user_expression_plan->GetFunctionStackPointer(); -      StreamString ss; -      if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) { -        diagnostic_manager.PutString(eDiagnosticSeverityError, ss.GetString()); -        return lldb::eExpressionSetupError; -      } +    function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); +    function_stack_top = function_stack_pointer; + +    LLDB_LOGF(log, +              "-- [UserExpression::Execute] Execution of expression begins --"); + +    if (exe_ctx.GetProcessPtr()) +      exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); + +    lldb::ExpressionResults execution_result = +        exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx, call_plan_sp, options, +                                              diagnostic_manager); + +    if (exe_ctx.GetProcessPtr()) +      exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); -      ThreadPlanCallUserExpression *user_expression_plan = -          static_cast<ThreadPlanCallUserExpression *>(call_plan_sp.get()); - -      lldb::addr_t function_stack_pointer = -          user_expression_plan->GetFunctionStackPointer(); - -      function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize(); -      function_stack_top = function_stack_pointer; - -      LLDB_LOGF( -          log, -          "-- [UserExpression::Execute] Execution of expression begins --"); - -      if (exe_ctx.GetProcessPtr()) -        exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); - -      lldb::ExpressionResults execution_result = -          exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx, call_plan_sp, options, -                                                diagnostic_manager); - -      if (exe_ctx.GetProcessPtr()) -        exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); - -      LLDB_LOGF(log, "-- [UserExpression::Execute] Execution of expression " -                     "completed --"); - -      if (execution_result == lldb::eExpressionInterrupted || -          execution_result == lldb::eExpressionHitBreakpoint) { -        const char *error_desc = nullptr; - -        if (call_plan_sp) { -          lldb::StopInfoSP real_stop_info_sp = call_plan_sp->GetRealStopInfo(); -          if (real_stop_info_sp) -            error_desc = real_stop_info_sp->GetDescription(); -        } -        if (error_desc) -          diagnostic_manager.Printf(eDiagnosticSeverityError, -                                    "Execution was interrupted, reason: %s.", -                                    error_desc); -        else -          diagnostic_manager.PutString(eDiagnosticSeverityError, -                                       "Execution was interrupted."); - -        if ((execution_result == lldb::eExpressionInterrupted && -             options.DoesUnwindOnError()) || -            (execution_result == lldb::eExpressionHitBreakpoint && -             options.DoesIgnoreBreakpoints())) -          diagnostic_manager.AppendMessageToDiagnostic( -              "The process has been returned to the state before expression " -              "evaluation."); -        else { -          if (execution_result == lldb::eExpressionHitBreakpoint) -            user_expression_plan->TransferExpressionOwnership(); -          diagnostic_manager.AppendMessageToDiagnostic( -              "The process has been left at the point where it was " -              "interrupted, " -              "use \"thread return -x\" to return to the state before " -              "expression evaluation."); -        } - -        return execution_result; -      } else if (execution_result == lldb::eExpressionStoppedForDebug) { -        diagnostic_manager.PutString( -            eDiagnosticSeverityRemark, -            "Execution was halted at the first instruction of the expression " -            "function because \"debug\" was requested.\n" -            "Use \"thread return -x\" to return to the state before expression " +    LLDB_LOGF(log, "-- [UserExpression::Execute] Execution of expression " +                   "completed --"); + +    if (execution_result == lldb::eExpressionInterrupted || +        execution_result == lldb::eExpressionHitBreakpoint) { +      const char *error_desc = nullptr; + +      if (call_plan_sp) { +        lldb::StopInfoSP real_stop_info_sp = call_plan_sp->GetRealStopInfo(); +        if (real_stop_info_sp) +          error_desc = real_stop_info_sp->GetDescription(); +      } +      if (error_desc) +        diagnostic_manager.Printf(eDiagnosticSeverityError, +                                  "Execution was interrupted, reason: %s.", +                                  error_desc); +      else +        diagnostic_manager.PutString(eDiagnosticSeverityError, +                                     "Execution was interrupted."); + +      if ((execution_result == lldb::eExpressionInterrupted && +           options.DoesUnwindOnError()) || +          (execution_result == lldb::eExpressionHitBreakpoint && +           options.DoesIgnoreBreakpoints())) +        diagnostic_manager.AppendMessageToDiagnostic( +            "The process has been returned to the state before expression "              "evaluation."); -        return execution_result; -      } else if (execution_result != lldb::eExpressionCompleted) { -        diagnostic_manager.Printf( -            eDiagnosticSeverityError, -            "Couldn't execute function; result was %s", -            Process::ExecutionResultAsCString(execution_result)); -        return execution_result; +      else { +        if (execution_result == lldb::eExpressionHitBreakpoint) +          user_expression_plan->TransferExpressionOwnership(); +        diagnostic_manager.AppendMessageToDiagnostic( +            "The process has been left at the point where it was " +            "interrupted, " +            "use \"thread return -x\" to return to the state before " +            "expression evaluation.");        } -    } -    if (FinalizeJITExecution(diagnostic_manager, exe_ctx, result, -                             function_stack_bottom, function_stack_top)) { -      return lldb::eExpressionCompleted; -    } else { -      return lldb::eExpressionResultUnavailable; +      return execution_result; +    } else if (execution_result == lldb::eExpressionStoppedForDebug) { +      diagnostic_manager.PutString( +          eDiagnosticSeverityRemark, +          "Execution was halted at the first instruction of the expression " +          "function because \"debug\" was requested.\n" +          "Use \"thread return -x\" to return to the state before expression " +          "evaluation."); +      return execution_result; +    } else if (execution_result != lldb::eExpressionCompleted) { +      diagnostic_manager.Printf( +          eDiagnosticSeverityError, "Couldn't execute function; result was %s", +          Process::ExecutionResultAsCString(execution_result)); +      return execution_result;      } +  } + +  if (FinalizeJITExecution(diagnostic_manager, exe_ctx, result, +                           function_stack_bottom, function_stack_top)) { +    return lldb::eExpressionCompleted;    } else { -    diagnostic_manager.PutString( -        eDiagnosticSeverityError, -        "Expression can't be run, because there is no JIT compiled function"); -    return lldb::eExpressionSetupError; +    return lldb::eExpressionResultUnavailable;    }  } | 
