使用GDB浏览OpenFOAM源代码

时间:2018-12-13 13:27:17

标签: c++ debugging gdb openfoam

我是使用OpenFOAM-6的新手。我正在尝试通过GDB阅读源代码。但是,我不明白为什么GDB无法进入诸如fvMesh之类的某些类的构造函数中。 GDB也会报告

(gdb) p mesh
$1 = <incomplete type>

我首先在调试模式下编译了一个应用程序rhoSimpleFoam。基本上,我将变量WM_COMPILE_OPTION从Opt导出到Debug,然后编译应用程序。我还尝试了在调试模式下编译整个OpenFOAM。不会影响我在下面描述的内容。 rhoSimpleFoam的调试模式为3.8MB,而Opt版本为889KB。

然后我使用gdb运行rhoSimpleFoam

gdb <ThePathToDebugMode>/rhoSimpleFoam

rhoSimpleFoam.C如下,

#include "fvCFD.H"
#include "fluidThermo.H"
#include "turbulentFluidThermoModel.H"
#include "simpleControl.H"
#include "pressureControl.H"
#include "fvOptions.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "postProcess.H"

    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createControl.H"
    #include "createFields.H"
    #include "createFieldRefs.H"
    #include "initContinuityErrs.H"

    turbulence->validate();

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nStarting time loop\n" << endl;

    while (simple.loop(runTime))
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        // Pressure-velocity SIMPLE corrector
        #include "UEqn.H"
        #include "EEqn.H"

        if (simple.consistent())
        {
            #include "pcEqn.H"
        }
        else
        {
            #include "pEqn.H"
        }

        turbulence->correct();

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;

我想知道fvMesh是如何初始化的,应该在#include "createMesh.H"中完成。文件createMesh.H如下,

Foam::Info
    << "Create mesh for time = "
    << runTime.timeName() << Foam::nl << Foam::endl;

Foam::fvMesh mesh
(
    Foam::IOobject
    (
        Foam::fvMesh::defaultRegion,
        runTime.timeName(),
        runTime,
        Foam::IOobject::MUST_READ
    )
);

我在GDB中的Foam::fvMesh mesh处设置了一个断点,然后运行到那里。但是,GDB无法介入该fvMesh的构造函数。相反,GDB进入了runTime.timeName()。之后,GDB将从该文件createMesh.H中退出。该fvMesh的相应构造函数如下,

Foam::fvMesh::fvMesh(const IOobject& io)
:
    polyMesh(io),
    surfaceInterpolation(*this),
    fvSchemes(static_cast<const objectRegistry&>(*this)),
    fvSolution(static_cast<const objectRegistry&>(*this)),
    data(static_cast<const objectRegistry&>(*this)),
    boundary_(*this, boundaryMesh()),
    lduPtr_(nullptr),
    curTimeIndex_(time().timeIndex()),
    VPtr_(nullptr),
    V0Ptr_(nullptr),
    V00Ptr_(nullptr),
    SfPtr_(nullptr),
    magSfPtr_(nullptr),
    CPtr_(nullptr),
    CfPtr_(nullptr),
    phiPtr_(nullptr)
{
    if (debug)
    {
        InfoInFunction << "Constructing fvMesh from IOobject" << endl;
    }

    // Check the existence of the cell volumes and read if present
    // and set the storage of V00
    if (fileHandler().isFile(time().timePath()/"V0"))
    {
        V0Ptr_ = new DimensionedField<scalar, volMesh>
        (
            IOobject
            (
                "V0",
                time().timeName(),
                *this,
                IOobject::MUST_READ,
                IOobject::NO_WRITE,
                false
            ),
            *this
        );

        V00();
    }

    // Check the existence of the mesh fluxes, read if present and set the
    // mesh to be moving
    if (fileHandler().isFile(time().timePath()/"meshPhi"))
    {
        phiPtr_ = new surfaceScalarField
        (
            IOobject
            (
                "meshPhi",
                time().timeName(),
                *this,
                IOobject::MUST_READ,
                IOobject::NO_WRITE,
                false
            ),
            *this
        );

        // The mesh is now considered moving so the old-time cell volumes
        // will be required for the time derivatives so if they haven't been
        // read initialise to the current cell volumes
        if (!V0Ptr_)
        {
            V0Ptr_ = new DimensionedField<scalar, volMesh>
            (
                IOobject
                (
                    "V0",
                    time().timeName(),
                    *this,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE,
                    false
                ),
                V()
            );
        }

        moving(true);
    }
}

我无法理解的另一个问题如下。 GDB仍在文件createMesh.H中。 GDB对某些变量一无所知,就像下面的输出一样。

(gdb) p runTime
$1 = <incomplete type>
(gdb) p runTime.timeName()
Couldn't find method Foam::Time::timeName

实际上,我在GDB中使用info sources来显示已加载的符号。有关info sources的参考,请选中此webpage。符号已经加载。

因此,似乎GDB对OpenFOAM确实了解得很少。 GDB无法进入某些OpenFOAM类的功能主体。 GDB也无法在OpenFOAM中找到某些方法。

任何人都可以帮助我了解发生了什么事?谢谢!

景昌

0 个答案:

没有答案