コード例 #1
0
ファイル: debuginfo.cpp プロジェクト: Ambrevar/fr_public
void DebugInfo::TokenizeCallback(void *user,sInt uncompSize,sF32 compSize)
{
  DebugInfo *info;
  DISymbol *sym;
  sU32 addr;
  sInt leftSize,availSize,len;
  ReorderItem *reord;
  
  info = (DebugInfo *) user;
  leftSize = uncompSize;

  while(leftSize)
  {
    // setup
    availSize = leftSize;
    addr = info->Address;

    // find out whether there is a remapping for the current address range
    if(info->Reorder)
    {
      if(!info->Reorder->Find(addr,&reord)) // no match
      {
        if(reord)
          len = sMin<sInt>(availSize,reord->NewVA - addr);
        else
          len = availSize;

        info->Address += len;
        leftSize -= len;
      }
      else
      {
        len = sMin<sInt>(availSize,reord->NewVA + reord->NewSize - addr);
        info->Address += len;
        leftSize -= len;

        // just a crude approximation here, gotta fix it somehow
        availSize = reord->OldSize * len / reord->NewSize;
        addr = reord->OldVA + (reord->OldSize * (addr - reord->NewVA) + reord->NewSize/2) / reord->NewSize;
      }
    }
    else
    {
      info->Address += availSize;
      leftSize -= availSize;
    }

    // try to find symbol for current address
    while(availSize)
    {
      if(!info->FindSymbol(addr,&sym)) // no match
      {
        if(sym) // skip to next symbol or everything if there's no next symbol
          len = sMin<sInt>(availSize,sym->VA - addr);
        else
          len = availSize;

        addr += len;
        availSize -= len;
      }
      else // match with symbol
      {
        len = sMin<sInt>(availSize,sym->VA + sym->Size - addr);
        addr += len;
        availSize -= len;

        sym->PackedSize += compSize * 0.125f * len / uncompSize;
      }
    }
  }
}