question

PavleStojanovic-2347 avatar image
0 Votes"
PavleStojanovic-2347 asked PavleStojanovic-2347 commented

How to get friend classes and functions using DIA SDK?

I added check for SymTagFriend inside loop for UDT children but it's never executed. Can someone tell me how I can get friend classes and functions?

 bool PDB::readFromFile(const QString& filePath)
 {
     HRESULT hr = CoInitialize(nullptr);
    
     hr = CoCreateInstance(__uuidof(DiaSource),
         nullptr,
         CLSCTX_INPROC_SERVER,
         __uuidof(IDiaDataSource),
         (void**)(&diaDataSource));
    
     if (FAILED(hr))
     {
         emit sendStatusMessage("Can't load msdia library!");
    
         return false;
     }
    
     QByteArray buffer2;
     buffer2.resize((filePath.length() + 1) * 2);
     buffer2.fill(0);
    
     wchar_t* filePath2 = (wchar_t*)buffer2.data();
     filePath.toWCharArray(filePath2);
    
     hr = diaDataSource->loadDataFromPdb(filePath2);
    
     if (FAILED(hr))
     {
         emit sendStatusMessage("Can't load data from PDB!");
    
         return false;
     }
    
     hr = diaDataSource->openSession(&diaSession);
    
     if (FAILED(hr))
     {
         emit sendStatusMessage("Can't open session!");
    
         return false;
     }
    
     hr = diaSession->get_globalScope(&global);
    
     if (FAILED(hr))
     {
         emit sendStatusMessage("Can't get global scope!");
    
         return false;
     }
        
     return true;
 }
    
 void PDB::loadPDBData()
 {
     IDiaSymbol* symbol;
        
     if (getSymbolByTypeName(SymTagUDT, "A", &symbol)
     {
         IDiaEnumSymbols* enumSymbols;
    
         if (symbol->findChildren(SymTagNull, nullptr, nsNone, &enumSymbols) == S_OK)
         {
             LONG count;
    
             if (enumSymbols->get_Count(&count) == S_OK)
             {
                 if (count)
                 {
                     IDiaSymbol* symbol2;
                     ULONG celt = 0;
    
                     while (SUCCEEDED(enumSymbols->Next(1, &symbol2, &celt)) && (celt == 1))
                     {
                         DWORD symTag;
                                    
                         symbol2->get_symTag(&symTag);
                                    
                         if (symTag == SymTagFriend)
                         {
                             Friend friend1 = getFriend(symbol2);
                         }
                                    
                         symbol2->Release();
                     }
                 }
             }
                        
             enumSymbols->Release();
         }        
     }
 }
    
 bool PDB::getSymbolByTypeName(enum SymTagEnum symTag, QString typeName, IDiaSymbol** symbol)
 {
     IDiaEnumSymbols* enumSymbols;
    
     if (global->findChildren(symTag, typeName.toStdWString().c_str(), nsNone, &enumSymbols) == S_OK)
     {
         if (enumSymbols->Item(0, symbol) != S_OK)
         {
             return false;
         }
    
         enumSymbols->Release();
    
         return true;
     }
    
     return false;
 }


Here is also example for which I am trying to get friend class

 class A
 {
 private:
     int a;
    
 public:
     A() { a = 0; }
     friend class B;
 };
    
 class B
 {
 private:
     int b;
    
 public:
     void showA(A& x)
     {
         std::cout << "A::a=" << x.a;
     }
 };



c++vs-debugging
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PavleStojanovic-2347 , welcome to Microsoft Q&A forum. If you try to use other elements will it correctly get the corresponding type of symbol, or executed this time?

0 Votes 0 ·

Hello @PavleStojanovic-2347 , have you also checked the @RLWA32-6355’s reply? Please feel free to contact us.

0 Votes 0 ·

Even the VS2019 DIA2Dump sample fails to produce any information regarding friend classes and SymTagFriend symbols.

The only place in the sample that referenced SymTagFriend was the PrintTypeInDetail function on line 1845 of PrintSymbol.cpp. I set a breakpoint in the function and then ran the sample with the -all parameter so that all debug information would be printed. The breakpoint was never hit.

0 Votes 0 ·

0 Answers