emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.29k stars 181 forks source link

Question: Configuring `launch.json` for Debugging MPI C++ Code with LLDB on Mac M1 #765

Open durwasa-chakraborty opened 9 months ago

durwasa-chakraborty commented 9 months ago

I seek guidance on configuring launch.json to debug a parallel C++ MPI program using LLDB on a Mac M1, which currently lacks gdb support. I have successfully debugged a basic C++ program with the following launch.json configuration:

{
    "configurations": [
        {
            "type": "lldb-vscode",
            "request": "launch",
            "name": "C++ LLDB in the parent folder",
            "program": "${workspaceFolder}/betweeness_centrality_serial",
            "cwd": "${workspaceFolder}",
            "args": []
        }
    ]
}

This setup works well for a single-threaded application, where I can run and debug the betweeness_centrality_serial binary using LLDB. [1]

Screenshot 2023-12-03 at 12 40 05 AM

However, I face challenges when attempting to debug a parallel version of the program, which requires specific MPI commands. Normally, I would run the parallel version using the command:

OMPI_CXX=g++ mpiexec -np 1 lldb ./betweeness_centrality_parallel small.graph

My current launch.json for the parallel version looks like this:

{
    "configurations": [{
        "type"  : "lldb-vscode",
        "request": "launch",
        "name": "Debug | C++ | Betweeness Centrality",
        "program": "${workspaceFolder}/betweeness_centrality_parallel",
        "cwd" :"${workspaceFolder}",
        "args": ['small.graph']
    }]
}

I need assistance in modifying this configuration to incorporate the MPI execution and environment setup (OMPI_CXX=g++ mpiexec -np 1) before the LLDB command.

Could you please guide me on adjusting the launch.json to accommodate these requirements for MPI debugging?

Thank you so much for your help.

yyoncho commented 9 months ago

OMPI_CXX=g++

This part can go as an env param, right?

mpiexec -np 1

What is this part supposed to do?

durwasa-chakraborty commented 9 months ago

OMPI_CXX=g++

This part can go as an env param, right?

I did not think of that! Thank you. I'll dig around to see how to add env parameter in the launch.json.

mpiexec -np 1

What is this part supposed to do?

The mpiexec command is used to execute the binary. Since the binary has been compiled with mpi++, using mpiexec is the required method to run it. The -np flag specifies the number of processes to initiate, which is set to 1 in this case. Debugging multiple processes can be tough -np 2 but theoretically np 1 should be same as debugging any C++ code.

yyoncho commented 9 months ago

To me it sounds like one way to debug it is to attach to the process, right? That would be the way to debug it even if you start the process via command like lldb?

durwasa-chakraborty commented 9 months ago

TL;DR

Could you assist me / point me to some examples which might help me in resolving the issue with the attach request in the LLDB setting?


Long answer I tried to attach the process and debug the code. However, I'm encountering issues when using the attach request. Below are the steps I've taken and the outcomes:

  1. Initial Setup:

    • Compiled the C++ code with g++ -g betweeness_centrality_serial.cpp -o betweeness_centrality_serial.
    • Launched LLDB with lldb betweeness_centrality_serial.
  2. LLDB Attach Attempt:

    • Used the following launch.json configuration with an attach request:
      {
       "configurations": [{
           "type": "lldb-vscode",
           "request": "attach",
           "name": "Debug | C++ | Betweenness Centrality Serial",
           "cwd": "${workspaceFolder}",
           "program": "${workspaceFolder}/betweeness_centrality_serial",
           "pid": "${command:PickProcess}"
       }]
      }
    • Selected the process from the list corresponding to the lldb <binary>
    • Result: The debug session exited with process status: 9.
  3. Changing Request to launch:

    • Modified the request to launch in launch.json.
    • Outcome: Debugger functioned correctly, allowing PID selection and showing expected behavior.
  4. Parallel Execution Issue:

    • Executed OMPI_CXX=g++ mpiexec -np 1 lldb ./bc_dslV2 small.graph.
    • Tried attaching the process with the same attach configuration for a parallel setup.
    • Result: Encountered the same error - "debug session exited with process status".

I suspect the issue lies with the attach request configuration itself. I've referred to LLDB-VSCode documentation and tried all the three techniques mentioned in the doc (pid, waitFor, application name) but couldn't pin point it whether it's a syntax issue or a problem with the process.