Configure debug setting for PETSc in VScode

401 views Asked by At

This will be a long shot, but I would like to know if anyone in the community has the .json setting for running PETSc in VScode (for debbuging).

Best Regards

2

There are 2 answers

1
AudioBubble On

For the time being I am using example 19 from /petsc/src/snes/tutorials as a case.

I made a makefile with:

 touch makefile

Inside I placed:

include ${PETSC_DIR}/lib/petsc/conf/variables
include ${PETSC_DIR}/lib/petsc/conf/rules

example19: example19.o chkopts
    -${CLINKER} -o example19 example19.o ${PETSC_LIB}
        ${RM} example19.o

in the .json files of vscode

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "run petsc makefile",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

And in tasks.json

{
    "tasks": [
        {
            "type": "shell",
            "label": "run petsc makefile",
            "command": "make",
            "args": [
                "${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}",
                "env": {"PETSC_DEB":  "/home/pc/petsc"}
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
        }
    ],
    "version": "2.0.0"
}

This creates the executable and runs the script. But I cannot attach the debugger.

Would appreciate some help.

Best Regards

0
brad.a On

This is how you can start a PETSc program, pause it for the debugger, and attach the VS Code debugger.

launch.json

    "version": "0.2.0",
    "configurations": [
            "name": "Attach to process",
            "type": "cppdbg",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "program": "/dev/null",
            "linux": {
                "MIMode": "gdb"
            },
            "osx": {
                "MIMode": "lldb"
            }
        }
    ]
}

Start the program and have it sleep for 20 seconds so you can attach the debugger:

myprogram -stop_for_debugger -pause_debugger=20

The -stop_for_debugger option will cause the program to print the process id to stdout.

  1. In the left sidebar, select "Run and Debug".
  2. At the top of the panel, select Attach to process.
  3. Select the process for myprogram that matches the process id printed to stdout when you started the program.

VS Code cppdbg requires a "program", but the value does not matter as long as it exists on the filesystem.