Ejemplo n.º 1
0
// Format stack as GDBMI
static StackFrames getStackTrace(CIDebugControl *debugControl,
                                 CIDebugSymbols *debugSymbols,
                                 unsigned maxFrames,
                                 bool *incomplete,
                                 std::string *errorMessage)
{

    if (maxFrames) {
        *incomplete = false;
    } else {
        *incomplete = true;
        return StackFrames();
    }
    // Ask for one more frame to find out whether it is a complete listing.
    const unsigned askedFrames = maxFrames + 1;
    DEBUG_STACK_FRAME *frames = new DEBUG_STACK_FRAME[askedFrames];
    ULONG frameCount = 0;
    const HRESULT hr = debugControl->GetStackTrace(0, 0, 0, frames, askedFrames, &frameCount);
    if (FAILED(hr)) {
        delete [] frames;
        *errorMessage = msgDebugEngineComFailed("GetStackTrace", hr);
        return StackFrames();
    }
    if (askedFrames == frameCount) {
        --frameCount;
        *incomplete = true;
    }
    StackFrames rc(frameCount, StackFrame());
    for (ULONG f = 0; f < frameCount; ++f)
        getFrame(debugSymbols, frames[f], &(rc[f]));
    delete [] frames;
    return rc;
}
Ejemplo n.º 2
0
void JSVM::pushFrame(JSFunction *func, JSValue *argsBegin) {
    m_frames.push_back(StackFrame(func, argsBegin));
    m_frames.back().oldStackSize = (int)m_values.size();
    if (func != NULL) {
        m_values.resize((argsBegin - &m_values[0]) + func->meta->getLocalSpace());
    }
}
Ejemplo n.º 3
0
void VM::Initialize(std::unordered_map<int, VMFunction> code)
{
  m_functions = code;
  m_running = true;
  m_frames.clear();
  m_frame_pointer = 0;

  m_frames.push_back(StackFrame(MAIN_FUNCTION_ID));
}
 //-----------------------------------------------------------------
 bool StackMemoryManager::allocateMoreMemory()
 {
     if ( mActiveFrame == MAX_NUM_OF_FRAMES-1 )
         return false;
     size_t sizeOfNewBlob = mFrames[ mActiveFrame ].mMaxMemoryBlob * SIZE_OF_NEW_FRAME_FACTOR;
     char* newMem = new char[sizeOfNewBlob];
     if (!newMem)
         return false;
     mFrames[ ++mActiveFrame ] = StackFrame(sizeOfNewBlob, newMem);
     return true;
 }
Ejemplo n.º 5
0
void StyleScopeResolver::setupStack(const ContainerNode* parent)
{
    // The scoping element stack shouldn't be used if <style scoped> isn't used anywhere.
    ASSERT(!m_authorStyles.isEmpty());

    m_stack.shrink(0);
    int authorStyleBoundsIndex = 0;
    for (const ContainerNode* scope = parent; scope; scope = scope->parentOrHostNode()) {
        RuleSet* ruleSet = ruleSetFor(scope);
        if (ruleSet)
            m_stack.append(StackFrame(scope, authorStyleBoundsIndex, ruleSet));
        if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles())
            --authorStyleBoundsIndex;
    }

    m_stack.reverse();
    m_stackParent = parent;
    m_stackParentBoundsIndex = 0;
}
Ejemplo n.º 6
0
// Format stack as GDBMI
static StackFrames getStackTrace(CIDebugControl *debugControl,
                                 CIDebugSymbols *debugSymbols,
                                 unsigned maxFrames,
                                 std::string *errorMessage)
{

    if (!maxFrames)
        return StackFrames();
    DEBUG_STACK_FRAME *frames = new DEBUG_STACK_FRAME[maxFrames];
    ULONG frameCount = 0;
    const HRESULT hr = debugControl->GetStackTrace(0, 0, 0, frames, maxFrames, &frameCount);
    if (FAILED(hr)) {
        delete [] frames;
        *errorMessage = msgDebugEngineComFailed("GetStackTrace", hr);
    }
    StackFrames rc(frameCount, StackFrame());
    for (ULONG f = 0; f < frameCount; f++)
        getFrame(debugSymbols, frames[f], &(rc[f]));
    delete [] frames;
    return rc;
}
Ejemplo n.º 7
0
void StyleScopeResolver::push(const ContainerNode* scope, const ContainerNode* scopeParent)
{
    // Shortcut: Don't bother with the scoping element stack if <style scoped> isn't used anywhere.
    if (m_authorStyles.isEmpty()) {
        ASSERT(!m_stackParent);
        ASSERT(m_stack.isEmpty());
        return;
    }

    // In some wacky cases during style resolve we may get invoked for random elements.
    // Recreate the whole scoping element stack in such cases.
    if (!stackIsConsistent(scopeParent)) {
        setupStack(scope);
        return;
    }

    if (scope->isShadowRoot() && !toShadowRoot(scope)->applyAuthorStyles())
        ++m_stackParentBoundsIndex;
    // Otherwise just push the parent onto the stack.
    RuleSet* ruleSet = ruleSetFor(scope);
    if (ruleSet)
        m_stack.append(StackFrame(scope, m_stackParentBoundsIndex, ruleSet));
    m_stackParent = scope;
}
	//--------------------------------------------------------------------
	StackMemoryManager::StackMemoryManager(size_t stackSize)
		: mActiveFrame(0)
    {
        mFrames = new StackFrame[ MAX_NUM_OF_FRAMES ];
		mFrames[ mActiveFrame ] = StackFrame(stackSize, new char[stackSize]);
	}
StackTrace::StackTrace(void *their_context) {
  PCONTEXT context = reinterpret_cast<PCONTEXT>(their_context);
  CONTEXT current_context;
  if (their_context == NULL) {
    RtlCaptureContext(&current_context);
    context = &current_context;
  }

  HANDLE process = GetCurrentProcess();
  DbgHelp dbghelp(process);
  if (!dbghelp.is_loaded()) {
    goto fail;
  }

  STACKFRAME64 stack_frame;
  ZeroMemory(&stack_frame, sizeof(stack_frame));

  // http://stackoverflow.com/a/136942/249230
  stack_frame.AddrPC.Offset = context->Eip;
  stack_frame.AddrReturn.Offset = context->Eip;
  stack_frame.AddrPC.Mode = AddrModeFlat;
  stack_frame.AddrFrame.Offset = context->Ebp;
  stack_frame.AddrFrame.Mode = AddrModeFlat;
  stack_frame.AddrStack.Offset = context->Esp;
  stack_frame.AddrStack.Mode = AddrModeFlat;

  if (!dbghelp.HaveStackWalk64()) {
    goto fail;
  }

  SYMBOL_INFO *symbol = NULL;

  if (dbghelp.is_initialized()) {
    symbol = reinterpret_cast<SYMBOL_INFO*>(std::calloc(sizeof(*symbol) + kMaxSymbolNameLength, 1));
    symbol->SizeOfStruct = sizeof(*symbol);
    symbol->MaxNameLen = kMaxSymbolNameLength;

    if (dbghelp.HaveSymGetOptions() && dbghelp.HaveSymSetOptions()) {
      DWORD options = dbghelp.SymGetOptions();
      options |= SYMOPT_FAIL_CRITICAL_ERRORS;
      dbghelp.SymSetOptions(options);
    }
  }

  while (true) {
    DWORD64 address = stack_frame.AddrReturn.Offset;
    if (address <= 0) {
      break;
    }

    bool have_symbols = true;
    if (dbghelp.HaveSymGetModuleInfo64()) {
      IMAGEHLP_MODULE64 module;
      ZeroMemory(&module, sizeof(IMAGEHLP_MODULE64));
      module.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
      if (dbghelp.SymGetModuleInfo64(process, address, &module)) {
        if (!module.GlobalSymbols) {
          have_symbols = false;
        }
      }
    }

    const char *name = "";
    if (have_symbols) {
      if (dbghelp.is_initialized() && dbghelp.HaveSymFromAddr() && symbol != NULL) {
        if (dbghelp.SymFromAddr(process, address, NULL, symbol)) {
          name = symbol->Name;
        }
      }
    }

    frames_.push_back(StackFrame(reinterpret_cast<void*>(address), name));

    BOOL result = dbghelp.StackWalk64(IMAGE_FILE_MACHINE_I386, process, GetCurrentThread(), &stack_frame,
                                      (PVOID)context, NULL, NULL, NULL, NULL);
    if (!result) {
      break;
    }
  }

  if (symbol != NULL) {
    std::free(symbol);
  }

  return;

fail:
  frames_ = StackTraceGeneric(
    reinterpret_cast<void*>(context->Ebp),
    reinterpret_cast<void*>(context->Eip)).GetFrames();
}