当前位置: 首页>>代码示例>>C++>>正文


C++ Unwind::GetFrameInfoAtIndex方法代码示例

本文整理汇总了C++中Unwind::GetFrameInfoAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ Unwind::GetFrameInfoAtIndex方法的具体用法?C++ Unwind::GetFrameInfoAtIndex怎么用?C++ Unwind::GetFrameInfoAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unwind的用法示例。


在下文中一共展示了Unwind::GetFrameInfoAtIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetFrameAtIndex

StackFrameSP StackFrameList::GetFrameAtIndex(uint32_t idx) {
  StackFrameSP frame_sp;
  std::lock_guard<std::recursive_mutex> guard(m_mutex);
  uint32_t original_idx = idx;

  uint32_t inlined_depth = GetCurrentInlinedDepth();
  if (inlined_depth != UINT32_MAX)
    idx += inlined_depth;

  if (idx < m_frames.size())
    frame_sp = m_frames[idx];

  if (frame_sp)
    return frame_sp;

  // GetFramesUpTo will fill m_frames with as many frames as you asked for,
  // if there are that many.  If there weren't then you asked for too many
  // frames.
  GetFramesUpTo(idx);
  if (idx < m_frames.size()) {
    if (m_show_inlined_frames) {
      // When inline frames are enabled we actually create all the frames in
      // GetFramesUpTo.
      frame_sp = m_frames[idx];
    } else {
      Unwind *unwinder = m_thread.GetUnwinder();
      if (unwinder) {
        addr_t pc, cfa;
        if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc)) {
          const bool cfa_is_valid = true;
          const bool stop_id_is_valid = false;
          const bool is_history_frame = false;
          frame_sp.reset(new StackFrame(
              m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid, pc, 0,
              stop_id_is_valid, is_history_frame, nullptr));

          Function *function =
              frame_sp->GetSymbolContext(eSymbolContextFunction).function;
          if (function) {
            // When we aren't showing inline functions we always use
            // the top most function block as the scope.
            frame_sp->SetSymbolContextScope(&function->GetBlock(false));
          } else {
            // Set the symbol scope from the symbol regardless if it is nullptr
            // or valid.
            frame_sp->SetSymbolContextScope(
                frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol);
          }
          SetFrameAtIndex(idx, frame_sp);
        }
      }
    }
  } else if (original_idx == 0) {
    // There should ALWAYS be a frame at index 0.  If something went wrong with
    // the CurrentInlinedDepth such that
    // there weren't as many frames as we thought taking that into account, then
    // reset the current inlined depth
    // and return the real zeroth frame.
    if (m_frames.empty()) {
      // Why do we have a thread with zero frames, that should not ever
      // happen...
      if (m_thread.IsValid())
        assert("A valid thread has no frames.");
    } else {
      ResetCurrentInlinedDepth();
      frame_sp = m_frames[original_idx];
    }
  }

  return frame_sp;
}
开发者ID:CodaFi,项目名称:swift-lldb,代码行数:71,代码来源:StackFrameList.cpp

示例2: GetFramesUpTo

void StackFrameList::GetFramesUpTo(uint32_t end_idx) {
  // this makes sure we do not fetch frames for an invalid thread
  if (!m_thread.IsValid())
    return;

  // We've already gotten more frames than asked for, or we've already finished
  // unwinding, return.
  if (m_frames.size() > end_idx || GetAllFramesFetched())
    return;

  Unwind *unwinder = m_thread.GetUnwinder();

  if (m_show_inlined_frames) {
#if defined(DEBUG_STACK_FRAMES)
    StreamFile s(stdout, false);
#endif
    // If we are hiding some frames from the outside world, we need to add those
    // onto the total count of
    // frames to fetch.  However, we don't need to do that if end_idx is 0 since
    // in that case we always
    // get the first concrete frame and all the inlined frames below it...  And
    // of course, if end_idx is
    // UINT32_MAX that means get all, so just do that...

    uint32_t inlined_depth = 0;
    if (end_idx > 0 && end_idx != UINT32_MAX) {
      inlined_depth = GetCurrentInlinedDepth();
      if (inlined_depth != UINT32_MAX) {
        if (end_idx > 0)
          end_idx += inlined_depth;
      }
    }

    StackFrameSP unwind_frame_sp;
    do {
      uint32_t idx = m_concrete_frames_fetched++;
      lldb::addr_t pc = LLDB_INVALID_ADDRESS;
      lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
      if (idx == 0) {
        // We might have already created frame zero, only create it
        // if we need to
        if (m_frames.empty()) {
          RegisterContextSP reg_ctx_sp(m_thread.GetRegisterContext());

          if (reg_ctx_sp) {
            const bool success =
                unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
            // There shouldn't be any way not to get the frame info for frame 0.
            // But if the unwinder can't make one, lets make one by hand with
            // the
            // SP as the CFA and see if that gets any further.
            if (!success) {
              cfa = reg_ctx_sp->GetSP();
              pc = reg_ctx_sp->GetPC();
            }

            unwind_frame_sp.reset(new StackFrame(m_thread.shared_from_this(),
                                                 m_frames.size(), idx,
                                                 reg_ctx_sp, cfa, pc, nullptr));
            m_frames.push_back(unwind_frame_sp);
          }
        } else {
          unwind_frame_sp = m_frames.front();
          cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
        }
      } else {
        const bool success =
            unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
        if (!success) {
          // We've gotten to the end of the stack.
          SetAllFramesFetched();
          break;
        }
        const bool cfa_is_valid = true;
        const bool stop_id_is_valid = false;
        const bool is_history_frame = false;
        unwind_frame_sp.reset(new StackFrame(
            m_thread.shared_from_this(), m_frames.size(), idx, cfa,
            cfa_is_valid, pc, 0, stop_id_is_valid, is_history_frame, nullptr));
        m_frames.push_back(unwind_frame_sp);
      }

      assert(unwind_frame_sp);
      SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext(
          eSymbolContextBlock | eSymbolContextFunction);
      Block *unwind_block = unwind_sc.block;
      if (unwind_block) {
        Address curr_frame_address(unwind_frame_sp->GetFrameCodeAddress());
        TargetSP target_sp = m_thread.CalculateTarget();
        // Be sure to adjust the frame address to match the address
        // that was used to lookup the symbol context above. If we are
        // in the first concrete frame, then we lookup using the current
        // address, else we decrement the address by one to get the correct
        // location.
        if (idx > 0) {
          if (curr_frame_address.GetOffset() == 0) {
            // If curr_frame_address points to the first address in a section
            // then after
            // adjustment it will point to an other section. In that case
            // resolve the
//.........这里部分代码省略.........
开发者ID:CodaFi,项目名称:swift-lldb,代码行数:101,代码来源:StackFrameList.cpp


注:本文中的Unwind::GetFrameInfoAtIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。