Example #1
0
    static IDiaEnumSegments* GetEnumSegments(IDiaSession *pSession)
    {
        IDiaEnumSegments* pUnknown  = NULL;
        IDiaEnumTables* pEnumTables = NULL;
        IDiaTable*      pTable      = NULL;
        ULONG           celt        = 0;

        if ( pSession->getEnumTables(&pEnumTables) != S_OK )
            return nullptr;

        while (pEnumTables->Next(1, &pTable, &celt) == S_OK && celt == 1)
        {
            // There is only one table that matches the given iid
            HRESULT hr = pTable->QueryInterface(__uuidof(IDiaEnumSegments), (void**)&pUnknown);
            pTable->Release();
            if (hr == S_OK)
                break;
        }
        pEnumTables->Release();
        return pUnknown;
    }
Example #2
0
I* GetEnumTable(IDiaSession *pSession)
{
    I*              pUnknown    = NULL;
    REFIID          iid         = __uuidof(I);
    IDiaEnumTables* pEnumTables = NULL;
    IDiaTable*      pTable      = NULL;
    ULONG           celt        = 0;

    if (pSession->getEnumTables(&pEnumTables) != S_OK)
    {
        // wprintf(L"ERROR - GetTable() getEnumTables\n");
        return NULL;
    }
    while (pEnumTables->Next(1, &pTable, &celt) == S_OK && celt == 1)
    {
        // There is only one table that matches the given iid
        HRESULT hr = pTable->QueryInterface(iid, (void**)&pUnknown);
        pTable->Release();
        if (hr == S_OK)
            break;
    }
    pEnumTables->Release();
    return pUnknown;
}
Example #3
0
void PDBFileReader::ReadEverything(DebugInfo &to)
{
    ULONG celt;

    Contribs = 0;
    nContribs = 0;

    DanglingLengthStart = 0;

    // read section table
    IDiaEnumTables *enumTables;
    if(Session->getEnumTables(&enumTables) == S_OK)
    {
        VARIANT vIndex;
        vIndex.vt = VT_BSTR;
        vIndex.bstrVal = SysAllocString(L"Sections");

        IDiaTable *secTable;
        if(enumTables->Item(vIndex,&secTable) == S_OK)
        {
            LONG count;

            secTable->get_Count(&count);
            Contribs = new SectionContrib[count];
            nContribs = 0;

            IDiaSectionContrib *item;
            while(SUCCEEDED(secTable->Next(1,(IUnknown **)&item,&celt)) && celt == 1)
            {
                SectionContrib &contrib = Contribs[nContribs++];

                item->get_addressOffset(&contrib.Offset);
                item->get_addressSection(&contrib.Section);
                item->get_length(&contrib.Length);
                item->get_compilandId(&contrib.Compiland);
                item->get_execute(&contrib.CodeFlag);

                item->Release();
            }

            secTable->Release();
        }

        SysFreeString(vIndex.bstrVal);
        enumTables->Release();
    }

    // enumerate symbols by (virtual) address
    IDiaEnumSymbolsByAddr *enumByAddr;
    if(SUCCEEDED(Session->getSymbolsByAddr(&enumByAddr)))
    {
        IDiaSymbol *symbol;
        // get first symbol to get first RVA (argh)
        if(SUCCEEDED(enumByAddr->symbolByAddr(1,0,&symbol)))
        {
            DWORD rva;
            if(symbol->get_relativeVirtualAddress(&rva) == S_OK)
            {
                symbol->Release();

                // now, enumerate by rva.
                if(SUCCEEDED(enumByAddr->symbolByRVA(rva,&symbol)))
                {
                    do
                    {
                        ProcessSymbol(symbol,to);
                        symbol->Release();

                        if(FAILED(enumByAddr->Next(1,&symbol,&celt)))
                            break;
                    }
                    while(celt == 1);
                }
            }
            else
                symbol->Release();
        }

        enumByAddr->Release();
    }

    // clean up
    delete[] Contribs;
}
Example #4
0
void PDBFileReader::ReadEverything(DebugInfo &to)
{
  ULONG celt;
  
  Contribs = 0;
  nContribs = 0;
  
  // read section table
  IDiaEnumTables *enumTables;
  if(Session->getEnumTables(&enumTables) == S_OK)
  {
    VARIANT vIndex;
    vIndex.vt = VT_BSTR;
    vIndex.bstrVal = SysAllocString(L"Sections");

    IDiaTable *secTable;
    if(enumTables->Item(vIndex,&secTable) == S_OK)
    {
      LONG count;

      secTable->get_Count(&count);
      Contribs = new SectionContrib[count];
      nContribs = 0;

      IDiaSectionContrib *item;
      while(SUCCEEDED(secTable->Next(1,(IUnknown **)&item,&celt)) && celt == 1)
      {
        SectionContrib &contrib = Contribs[nContribs++];

        item->get_addressOffset(&contrib.Offset);
        item->get_addressSection(&contrib.Section);
        item->get_length(&contrib.Length);
        item->get_compilandId(&contrib.Compiland);

				BOOL code=FALSE,initData=FALSE,uninitData=FALSE;
				item->get_code(&code);
				item->get_initializedData(&initData);
				item->get_uninitializedData(&uninitData);

				if(code && !initData && !uninitData)
					contrib.Type = DIC_CODE;
				else if(!code && initData && !uninitData)
					contrib.Type = DIC_DATA;
				else if(!code && !initData && uninitData)
					contrib.Type = DIC_BSS;
				else
					contrib.Type = DIC_UNKNOWN;

				BSTR objFileName = 0;
				
				IDiaSymbol *compiland = 0;
				item->get_compiland(&compiland);
				if(compiland)
				{
					compiland->get_name(&objFileName);
					compiland->Release();
				}

				sChar *objFileStr = BStrToString(objFileName,"<noobjfile>");
				contrib.ObjFile = to.GetFileByName(objFileStr);

				delete[] objFileStr;
				if(objFileName)
					SysFreeString(objFileName);

        item->Release();
      }

      secTable->Release();
    }

    SysFreeString(vIndex.bstrVal);
    enumTables->Release();
  }

  // enumerate symbols by (virtual) address
  IDiaEnumSymbolsByAddr *enumByAddr;
  if(SUCCEEDED(Session->getSymbolsByAddr(&enumByAddr)))
  {
    IDiaSymbol *symbol;
    // get first symbol to get first RVA (argh)
    if(SUCCEEDED(enumByAddr->symbolByAddr(1,0,&symbol)))
    {
      DWORD rva;
      if(symbol->get_relativeVirtualAddress(&rva) == S_OK)
      {
        symbol->Release();

        // now, enumerate by rva.
        if(SUCCEEDED(enumByAddr->symbolByRVA(rva,&symbol)))
        {
          do
          {
            ProcessSymbol(symbol,to);
            symbol->Release();

            if(FAILED(enumByAddr->Next(1,&symbol,&celt)))
              break;
          }
          while(celt == 1);
        }
      }
      else
        symbol->Release();
    }

    enumByAddr->Release();
  }

  // clean up
  delete[] Contribs;
}