CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Using GDB to go through OpenFOAM source codes

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By aerosjc

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 13, 2018, 09:17
Default Using GDB to go through OpenFOAM source codes
  #1
Member
 
Jingchang.Shi
Join Date: Aug 2012
Location: Hang Zhou, China
Posts: 78
Rep Power: 14
aerosjc is on a distinguished road
Hi!

I'm a newbie using OpenFOAM-6. I'm trying to read the source codes by GDB. However, I cannot understand why gdb cannot step into the constructor of some classes like fvMesh. Also GDB reports something like

Code:
(gdb) p mesh
$1 = <incomplete type>
I first compiled an application: rhoSimpleFoam in Debug mode. Basically, I export the variable WM_COMPILE_OPTION from Opt to Debug, and then compile the application. I also tried compiling the whole bunch of OpenFOAM in the Debug mode. No effects on what I will describe below. The Debug mode of rhoSimpleFoam is 3.8MB while the Opt version is 889KB.

Then I use gdb to run rhoSimpleFoam by

Code:
gdb <ThePathToDebugMode>/rhoSimpleFoam
The rhoSimpleFoam.C is as follows,

Code:
#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;
}
What I want to know is how the fvMesh is initialized, which should be done in
Code:
#include "createMesh.H"
. The file createMesh.H is as follows,

Code:
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
    )
);
I set a breakpoint at
Code:
Foam::fvMesh mesh
in GDB and run to there. However, GDB cannot step into the constructor of that fvMesh. Instead GDB steps into
Code:
runTime.timeName()
. After that, GDB gets out of that file createMesh.H. The corresponding constructor of that fvMesh is as follows,

Code:
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 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);
     }
 }
Another problem I cannot understand is as follows. GDB is still in the file createMesh.H. GDB knows nothing about some variables, just like the following output.

Code:
(gdb) p runTime
$1 = <incomplete type>
(gdb) p runTime.timeName()
Couldn't find method Foam::Time::timeName
In fact, I use
Code:
info sources
in GDB to show the loaded symbols. For references for
Code:
info sources
, check this webpage. The symbols have already been loaded.

So it seems like GDB knows really a little about OpenFOAM. GDB cannot step into a function body in some OpenFOAM classes. GDB cannot find some methods in OpenFOAM either.

Anyone could help me understand what's going on? Thanks!

Jingchang
atulkjoy likes this.
aerosjc is offline   Reply With Quote

Old   December 24, 2018, 19:46
Default
  #2
Senior Member
 
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 18
wouter is on a distinguished road
did you google: debug openfoam ?
There are a lot of suggestions


Hope this helps
Wouter
wouter is offline   Reply With Quote

Reply

Tags
debug, gdb


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 22:53
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 17:02
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error FerdiFuchs OpenFOAM Community Contributions 27 April 16, 2014 16:14
centOS 5.6 : paraFoam not working yossi OpenFOAM Installation 2 October 9, 2013 02:41
pisoFoam compiling error with OF 1.7.1 on MAC OSX Greg Givogue OpenFOAM Programming & Development 3 March 4, 2011 18:18


All times are GMT -4. The time now is 16:00.