How to get friend classes and functions using DIA SDK?

Pavle Stojanovic 1 Reputation point
2021-06-30T10:20:46.833+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,593 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
958 questions
{count} votes