piyushkarki / tandem

A HPC DG method for 2D and 3D SEAS problems
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Internal: Trying to set up debugging for Tandem/PETSc repo #2

Open piyushkarki opened 1 day ago

piyushkarki commented 1 day ago

It might be useful for someone trying to do this in the future or even to me in case of academic amnesia.

Caveat: I use VScode as my IDE so this is only for the particular setup. You could of course adopt this for your usage with modifications.

So what you need is, inside the .vscode folder, you need launh and tasks json file. Currently they look like this:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Tandem",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/pkarki/tandem_project/build-2d-p6/app/static", // Running something static and 2d is cheap
            "args": [
                "/home/pkarki/tandem_project/tandem/examples/elasticity/2d/circular_hole.toml",
            ],
            "cwd": "/home/pkarki/tandem_project/build-2d-p6/app",
            "stopAtEntry": false,
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build tandem" 
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build tandem",
            "type": "shell",
            "command": "bash",
            "args": [
                "-c",
                "mkdir -p build-2d-p6 && cd build-2d-p6 && cmake /home/pkarki/tandem_project/tandem -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_PREFIX_PATH=/home/pkarki/bin -DCMAKE_BUILD_TYPE=Debug -DDOMAIN_DIMENSION=2 -DPOLYNOMIAL_DEGREE=6 && cd app && make -j 20"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "/home/pkarki/tandem_project" // Should be the working directory but shouldn't matter if you're using absolute paths everywhere
            },
            "problemMatcher": ["$gcc"]
        }
    ]
}

Main thing to remember is to have a debug compiler flag which is -g but since we aren't directly compiling source files but rather from cmake, we need to specify this with -DCMAKE_BUILD_TYPE=Debug.

With this, you can step into the code and debug for the cpp files.