bool UnwindCurrent::UnwindFromContext(size_t num_ignore_frames, bool resolve) {
  // The cursor structure is pretty large, do not put it on the stack.
  unw_cursor_t* cursor = new unw_cursor_t;
  int ret = unw_init_local(cursor, &context_);
  if (ret < 0) {
    BACK_LOGW("unw_init_local failed %d", ret);
    delete cursor;
    return false;
  }

  std::vector<backtrace_frame_data_t>* frames = GetFrames();
  frames->reserve(MAX_BACKTRACE_FRAMES);
  size_t num_frames = 0;
  do {
    unw_word_t pc;
    ret = unw_get_reg(cursor, UNW_REG_IP, &pc);
    if (ret < 0) {
      BACK_LOGW("Failed to read IP %d", ret);
      break;
    }
    unw_word_t sp;
    ret = unw_get_reg(cursor, UNW_REG_SP, &sp);
    if (ret < 0) {
      BACK_LOGW("Failed to read SP %d", ret);
      break;
    }

    if (num_ignore_frames == 0) {
      frames->resize(num_frames+1);
      backtrace_frame_data_t* frame = &frames->at(num_frames);
      frame->num = num_frames;
      frame->pc = static_cast<uintptr_t>(pc);
      frame->sp = static_cast<uintptr_t>(sp);
      frame->stack_size = 0;

      if (num_frames > 0) {
        // Set the stack size for the previous frame.
        backtrace_frame_data_t* prev = &frames->at(num_frames-1);
        prev->stack_size = frame->sp - prev->sp;
      }

      if (resolve) {
        frame->func_name = GetFunctionName(frame->pc, &frame->func_offset);
        frame->map = FindMap(frame->pc);
      } else {
        frame->map = NULL;
        frame->func_offset = 0;
      }
      num_frames++;
    } else {
      num_ignore_frames--;
    }
    ret = unw_step (cursor);
  } while (ret > 0 && num_frames < MAX_BACKTRACE_FRAMES);

  delete cursor;
  return true;
}
Example #2
0
HRESULT Cluster::unListGetMessageIDs(UINT*& omListId, UINT& nMsgCount)
{
    list<FRAME_STRUCT> ouFrameList;
    GetFrames(ouFrameList);

    omListId = new UINT[ouFrameList.size()];
    nMsgCount = ouFrameList.size();
    list<FRAME_STRUCT>::iterator itrBegin = ouFrameList.begin();
    int unMsgIndex = 0;
    while ( ouFrameList.end() != itrBegin )
    {
        omListId[unMsgIndex] = itrBegin->m_nSlotId;
        unMsgIndex++;
        itrBegin++;
    }
    return S_OK;
}
Example #3
0
bool BattleAnimation::IsDone() const {
	return GetFrame() >= GetFrames();
}
Example #4
0
bool UnwindPtrace::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) {
  if (ucontext) {
    BACK_LOGW("Unwinding from a specified context not supported yet.");
    return false;
  }

  addr_space_ = unw_create_addr_space(&_UPT_accessors, 0);
  if (!addr_space_) {
    BACK_LOGW("unw_create_addr_space failed.");
    return false;
  }

  UnwindMap* map = static_cast<UnwindMap*>(GetMap());
  if (NULL == map) {
    BACK_LOGW("GetMap before unwinding failed.");
    return false;
  }
  unw_map_set(addr_space_, map->GetMapCursor());

  upt_info_ = reinterpret_cast<struct UPT_info*>(_UPT_create(Tid()));
  if (!upt_info_) {
    BACK_LOGW("Failed to create upt info.");
    return false;
  }

  unw_cursor_t cursor;
  if(num_ignore_frames==0xdeaddead)
  	{
  		cursor.opaque[0]=0xdeaddead; //add for tell libunwind to unwind for kernel unwind userspace backtrace,lhd
  		BACK_LOGW(" K2U_bt call into UnwindPtrace::Unwind.");
		num_ignore_frames=0;
  	}
  int ret = unw_init_remote(&cursor, addr_space_, upt_info_);
  if (ret < 0) {
    BACK_LOGW("unw_init_remote failed %d", ret);
    return false;
  }

  std::vector<backtrace_frame_data_t>* frames = GetFrames();
  frames->reserve(MAX_BACKTRACE_FRAMES);
  size_t num_frames = 0;
  do {
    unw_word_t pc;
    ret = unw_get_reg(&cursor, UNW_REG_IP, &pc);
    if (ret < 0) {
      BACK_LOGW("Failed to read IP %d", ret);
      break;
    }
    unw_word_t sp;
    ret = unw_get_reg(&cursor, UNW_REG_SP, &sp);
    if (ret < 0) {
      BACK_LOGW("Failed to read SP %d", ret);
      break;
    }

    if (num_ignore_frames == 0) {
      frames->resize(num_frames+1);
      backtrace_frame_data_t* frame = &frames->at(num_frames);
      frame->num = num_frames;
      frame->pc = static_cast<uintptr_t>(pc);
      frame->sp = static_cast<uintptr_t>(sp);
      frame->stack_size = 0;

      if (num_frames > 0) {
        backtrace_frame_data_t* prev = &frames->at(num_frames-1);
        prev->stack_size = frame->sp - prev->sp;
      }

      frame->func_name = GetFunctionName(frame->pc, &frame->func_offset);

      frame->map = FindMap(frame->pc);

      num_frames++;
    } else {
      num_ignore_frames--;
    }
    ret = unw_step (&cursor);
  } while (ret > 0 && num_frames < MAX_BACKTRACE_FRAMES);

  return true;
}
Example #5
0
void Game::OnMain()
{
    SetPlanSize(cxSize2F(2048, 1536));
//
    const cxStr *data = nullptr;
    {
        cxStr *code = cxStr::UTF8("8347834");
        IndexType message = IndexType_init_zero;
        message.tid = 200;
        message.code = CX_STR_PB_ENCODE(code);
        data = cxStr::PBEncode(IndexType_fields, &message);
        cxUtil::Instance()->WriteDocument("test.dat", data, true);
    }
    {
        cxStr *code = cxStr::Create();
        IndexType m2 = IndexType_init_zero;
        m2.code = CX_STR_PB_DECODE(code);
        cxBool ok = data->PBDecode(IndexType_fields, &m2);
        CX_LOGGER("%d",ok);
    }
    
//    LoadTexture("grid.png","grid");
//
//    cxSprite *sp = cxSprite::Create();
//    sp->SetSize(cxSize2F(64));
//    sp->SetTexture("grid");
//    Window()->Append(sp);
//    
//    cxMoveTo::Create(cxPoint2F(0, 512), 6)->AttachTo(sp)->onExit+=cxAction::Remove;
//    
//    {
//        cxSprite *sp2 = cxSprite::Create();
//        sp2->SetSize(cxSize2F(64));
//        sp2->SetTexture("grid");
//        sp2->SetColor(cxColor4F::RED);
//        Window()->Append(sp2);
//        
//        cxFollow::Create(sp, 50)->AttachTo(sp2);
//    }
    
//    Controller *cv = Controller::Create(6, 6);
//    cv->SetResizeFlags(cxView::ResizeBottom);
//    Window()->Append(cv);
//
//    return;
    //加载纹理
    LoadTexture("jl.lqt");
    //加载帧序列
    LoadFrames("frames.csv");
    //加载动作组
    LoadActions("actions.csv");
    //获取法师帧序列
    const cxFrames *fs = GetFrames("Mage");
    //获取法师的动作列表
    const cxActionGroup *ag = GetActions("Mage");
    //获得move动作
    
    //创建动画
    {
        //获得动作组
        const cxActionAttr *move = ag->Action("attack");
        //创建动画
        cxAnimate *animate = fs->Animate();
        animate->onFrame+=[](cxAnimate *pav,cxInt frame){
            CX_LOGGER("%d %d",frame,pav->IsKeyFrame());
        };
        animate->SetAction(move, 1);
        animate->SetSpeed(1.0f);
        //创建载体
        cxAtlas *atlas = cxAtlas::Create();
        atlas->SetFlipX(true);
        atlas->SetSize(cxSize2F(200, 200));
        atlas->Append(animate);//加入动画
        //载体加入绘制
        Window()->Append(atlas);
    }
    
    {
        const cxActionAttr *move = ag->Action("move");
        cxAnimate *animate = fs->Animate();
        animate->onFrame+=[](cxAnimate *pav,cxInt frame){
            CX_LOGGER("%d %d",frame,pav->IsKeyFrame());
        };
        animate->SetAction(move, 1);
        animate->SetSpeed(1.0f);
        //
        cxAtlas *atlas = cxAtlas::Create();
        atlas->SetFlipX(true);
        atlas->SetSize(cxSize2F(200, 200));
        atlas->SetPosition(cxPoint2F(0, 300));
        animate->AttachTo(atlas);
        Window()->Append(atlas);
    }
}
Example #6
0
bool CVobFile::Open(CString fn, CAtlList<CString>& vobs, ULONG nProgNum /*= 1*/, bool bAuthenticate /*= true*/)
{
    if (!m_ifoFile.Open(fn, CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone)) {
        return false;
    }

    char hdr[IFO_HEADER_SIZE + 1];
    m_ifoFile.Read(hdr, IFO_HEADER_SIZE);
    hdr[IFO_HEADER_SIZE] = '\0';
    if (strcmp(hdr, VTS_HEADER)) {
        return false;
    }

    // Audio streams ...
    m_ifoFile.Seek(0x202, CFile::begin);
    BYTE buffer[SUBTITLE_BLOCK_SIZE];
    m_ifoFile.Read(buffer, AUDIO_BLOCK_SIZE);
    CGolombBuffer gb(buffer, AUDIO_BLOCK_SIZE);
    int stream_count = gb.ReadShort();
    for (int i = 0; i < std::min(stream_count, 8); i++) {
        BYTE Coding_mode = (BYTE)gb.BitRead(3);
        gb.BitRead(5);// skip
        int ToAdd = 0;
        switch (Coding_mode) {
            case 0:
                ToAdd = 0x80;
                break;
            case 4:
                ToAdd = 0xA0;
                break;
            case 6:
                ToAdd = 0x88;
                break;
            default:
                break;
        }
        gb.ReadByte();// skip
        char lang[2];
        gb.ReadBuffer((BYTE*)lang, 2);
        gb.ReadDword();// skip
        if (ToAdd) {
            m_pStream_Lang[ToAdd + i] = ISO6391ToLanguage(lang);
        }
    }

    // Subtitle streams ...
    m_ifoFile.Seek(0x254, CFile::begin);
    m_ifoFile.Read(buffer, SUBTITLE_BLOCK_SIZE);
    CGolombBuffer gb_s(buffer, SUBTITLE_BLOCK_SIZE);
    stream_count = gb_s.ReadShort();
    for (int i = 0; i < std::min(stream_count, 32); i++) {
        gb_s.ReadShort();
        char lang[2];
        gb_s.ReadBuffer((BYTE*)lang, 2);
        gb_s.ReadShort();
        m_pStream_Lang[0x20 + i] = ISO6391ToLanguage(lang);
    }

    // Chapters ...
    m_ifoFile.Seek(0xCC, CFile::begin); //Get VTS_PGCI address
    DWORD pcgITPosition = ReadDword() * 2048;
    m_ifoFile.Seek(pcgITPosition, CFile::begin);
    WORD nProgCount = (WORD)ReadShort();
    if (nProgNum > nProgCount) {
        return false;
    }
    m_ifoFile.Seek(pcgITPosition + 8 * nProgNum + 4, CFile::begin);
    DWORD chainOffset = ReadDword();
    m_ifoFile.Seek(pcgITPosition + chainOffset + 2, CFile::begin);
    BYTE programChainPrograms = ReadByte();
    m_iChaptersCount = programChainPrograms;
    m_ifoFile.Seek(pcgITPosition + chainOffset + 230, CFile::begin);
    int programMapOffset = ReadShort();
    m_ifoFile.Seek(pcgITPosition + chainOffset + 0xE8, CFile::begin);
    int cellTableOffset = ReadShort();
    REFERENCE_TIME rtDuration = 0;
    m_pChapters[0] = 0;
    for (BYTE currentProgram = 0; currentProgram < programChainPrograms; currentProgram++) {
        m_ifoFile.Seek(pcgITPosition + chainOffset + programMapOffset + currentProgram, CFile::begin);
        byte entryCell = ReadByte();
        byte exitCell = entryCell;
        if (currentProgram < (programChainPrograms - 1)) {
            m_ifoFile.Seek(pcgITPosition + chainOffset + programMapOffset + (currentProgram + 1), CFile::begin);
            exitCell = ReadByte() - 1;
        }

        REFERENCE_TIME rtTotalTime = 0;
        for (int currentCell = entryCell; currentCell <= exitCell; currentCell++) {
            int cellStart = cellTableOffset + ((currentCell - 1) * 0x18);
            m_ifoFile.Seek(pcgITPosition + chainOffset + cellStart, CFile::begin);
            BYTE bytes[4];
            ReadBuffer(bytes, 4);
            int cellType = bytes[0] >> 6;
            if (cellType == 0x00 || cellType == 0x01) {
                m_ifoFile.Seek(pcgITPosition + chainOffset + cellStart + 4, CFile::begin);
                ReadBuffer(bytes, 4);
                short frames = GetFrames(bytes[3]);
                int fpsMask = bytes[3] >> 6;
                double fps = fpsMask == 0x01 ? 25 : fpsMask == 0x03 ? (30 / 1.001) : 0;
                CString tmp;
                int hours = bytes[0];
                tmp.Format(_T("%x"), hours);
                _stscanf_s(tmp, _T("%d"), &hours);
                int minutes = bytes[1];
                tmp.Format(_T("%x"), minutes);
                _stscanf_s(tmp, _T("%d"), &minutes);
                int seconds = bytes[2];
                tmp.Format(_T("%x"), seconds);
                _stscanf_s(tmp, _T("%d"), &seconds);
                int mmseconds = 0;
                if (fps != 0) {
                    mmseconds = (int)(1000 * frames / fps);
                }

                REFERENCE_TIME rtCurrentTime = 10000i64 * (((hours * 60 + minutes) * 60 + seconds) * 1000 + mmseconds);
                rtTotalTime += rtCurrentTime;
            }
        }
        rtDuration += rtTotalTime;
        m_pChapters[currentProgram + 1] = rtDuration;
    }
Example #7
0
/*******************************************************************************
  Function Name    :  bWriteDBHeader
  Input(s)         :    -
  Output           :  TRUE/FALSE
  Functionality    :  Creates a "Unions.h" file and adds union defintions
                      to it.
  Member of        :  CMsgSignal
  Friend of        :      -

  Author(s)        :  Amarnath Shastry
  Date Created     :  15.02.2002
  Modifications    :  Amitesh Bharti, 12.03.2003
                      changes made to create unions.h structures as per
                      CRH0002
  Modifications    :  Raja N 12.02.2004
                      Modified to include Sign check for signals and moved
                      some hardcoded strings to Hashdefines.h
  Modifications    :  Raja N 18.05.2004
                      Added two more members in the union to give word and long
                      access of the data array
  Modifications    :  Raja N 18.05.2004
                      Added two more members in the union to give word and long
                      access of the data array
  Modifications    :  Anish 21.12.2006
                      Added code to have header name as header file name in
                      ifndef condition at the begining of *_UNIONS.h file
*******************************************************************************/
CString Cluster::bWriteDBHeader(CString omStrActiveDataBase, ETYPE_BUS eBus)
{
    BOOL bRetVal                = TRUE;
    CString omStrPath           = EMPTY_STRING;
    //Add header for ifndef condition
    CString omStrHeaderString   = EMPTY_STRING;
    CString omStrHeaderFileName = defHEADER_FILE_NAME;
    char  acErrorMsg[defSIZE_OF_ERROR_BUFFER];
    CFileException   omException  ;
    CStdioFile omHeaderFile;
    omStrHeaderFileName = omStrActiveDataBase.Left(
                              omStrActiveDataBase.ReverseFind('.') );
    omStrHeaderString = omStrHeaderFileName;
    omStrHeaderFileName += defHEADER_FILE_NAME;
    TRY
    {
        // Open HeaderFile
        bRetVal = omHeaderFile.Open( omStrHeaderFileName,
        CFile::modeCreate|CFile::modeWrite|CFile::typeText,&omException);
        if (bRetVal == FALSE)
        {
            // Get the exception error message
            omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
            // union.h file  open error notification
            // AfxMessageBox and MessageBox does not work here. So the API
            // call for MessageBox is used.
            if (m_bAutoServerMode == FALSE)
            {
                ::MessageBox(NULL,acErrorMsg,("BUSMASTER") ,MB_ICONERROR|MB_OK);
            }
        }
        else
        {
            int nIndex = omStrHeaderString.ReverseFind(defCHAR_PATH_SEPRATER);
            int nLength = omStrHeaderString.GetLength();
            omStrHeaderString = omStrHeaderString.Right(nLength - nIndex -1);
            omStrHeaderString.MakeUpper();
            CString omStrTemp;
            omStrTemp.Format(H_FILE_HEADER_START,omStrHeaderString,omStrHeaderString);

            // Add Header "Help information"
            omHeaderFile.WriteString(defHELP_INFO_IN_UNIONS);

            // Add Header "ifndef..."
            omHeaderFile.WriteString(omStrTemp);

            // Add Pragma Pack
            omStrTemp.Format(H_FILE_HEADER_PRAGMA_PACK,omStrHeaderString,omStrHeaderString);
            omHeaderFile.WriteString(omStrTemp);

            CString omStrDLC = STR_EMPTY;
            UINT aunSigStartBit[defMAX_SIGNALS] ;
            UINT aunLength[defMAX_SIGNALS] ;
            CStringArray omStrArraySigName;
            omStrArraySigName.RemoveAll();
            BOOL bReturn = FALSE;
            UINT unSigCount = 0;
            CString omStrcommandLine = STR_EMPTY;
            CString omStrSigName = STR_EMPTY;
            CString omStrdelimiter = STR_EMPTY;

            list<FRAME_STRUCT> ouFrameList;
            GetFrames(ouFrameList );
            for ( list<FRAME_STRUCT>::iterator unMsgIndex = ouFrameList.begin();
            unMsgIndex != ouFrameList.end();
            unMsgIndex++)
            {
                // Get all signal names.
                // signal name will be the variable name
                // of the union of length specified in DB
                unSigCount = 0;
                list<SIGNAL_STRUCT> sigList;
                unMsgIndex->GetSignalList(sigList);
                //sSIGNALS* pSg = m_psMessages[unMsgIndex].m_psSignals;
                list<SIGNAL_STRUCT>::iterator itrSig = sigList.begin();
                while(itrSig != sigList.end())
                {
                    //UINT nSize = omStrArraySigName.GetSize();
                    /*aunSigStartBit[unSigCount] =
                    (itrSig->m_unStartByte - 1 ) * defBITS_IN_BYTE;*/
                    aunSigStartBit[unSigCount] = itrSig->m_unStartbit;
                    unSigCount++;
                    //pSg = pSg->m_psNextSignalList;
                    itrSig++;
                }
                // Check if there is no signal add one signal declaration
                // with no name occuppying whole message length.
                if(sigList.size() > 0 )
                {
                    bReturn =
                        bSortSignalStartBitAscend(aunSigStartBit,
                                                  sigList.size());
                    if(bReturn == TRUE )
                    {
                        switch (eBus)
                        {
                            case LIN: // TODO: LIN
                            {
                                bReturn = bFormSigNameAndLength(aunLength,
                                                                aunSigStartBit,
                                                                omStrArraySigName,
                                                                unMsgIndex);
                            }
                            break;
                            default: //This is a general routine which contructs
                                //structure based on message length and its signal length
                            {
                                /* bReturn = bFormSigNameAndLengthJ1939(aunSigStartBit,
                                                                      omStrArraySigName,
                                                                      unMsgIndex);*/
                            }
                            break;
                        }
                    }
                }
                else
                {
                    CString omFormatString;
                    // If message length is more then four byte
                    // define two signal with no name.
                    UINT unTempLen = unMsgIndex->m_nLength;
                    while (unTempLen > defUINT_SIZE)
                    {
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defUNSIGNED_INT,
                                              STR_EMPTY,
                                              defUINT_LENGTH);
                        omStrArraySigName.Add(omFormatString);
                        unSigCount++;
                        unTempLen -= defUINT_SIZE;
                    }
                    UINT unLength = unMsgIndex->m_nLength
                                    * defBITS_IN_BYTE
                                    - ( unSigCount * defUINT_LENGTH );
                    omFormatString.Format(defUNION_FORMAT_STRING,
                                          defUNSIGNED_INTEGER,
                                          STR_EMPTY,
                                          unLength);
                    omStrArraySigName.Add(omFormatString);

                    unSigCount = 0;
                    bReturn = TRUE;
                }
                //                INT nIndex = 0;
                if(bReturn == TRUE )
                {
                    bInsertBusSpecStructures(omHeaderFile,
                                             omStrcommandLine,
                                             omStrArraySigName,
                                             unMsgIndex, LIN);
                }
            }

            // add "#endif.."
            //omHeaderFile.WriteString(H_FILE_HEADER_END);

            omStrPath = omStrHeaderFileName;
            // Close opened file
            omHeaderFile.Close();
        }
    }
    CATCH_ALL(pomE)
    {
        if(pomE != NULL )
        {
            pomE->GetErrorMessage(acErrorMsg ,sizeof(acErrorMsg) );
            bRetVal = FALSE;
            pomE->Delete();
            // union.h file  open error notification
            if (m_bAutoServerMode == FALSE)
            {
                ::MessageBox(NULL,acErrorMsg,("BUSMASTER") ,MB_ICONERROR|MB_OK);
            }
        }
        // Close opened file
        omHeaderFile.Close();
    }
    END_CATCH_ALL

    return omStrPath;
}