microsoft / microsoft/vscode-cpptools

Unable to debug C++ from a python script in container

Open
#8,222 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugger help wanted
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Hello,
I am trying to debug a C++ code from a python script in a dev container, but the breakpoints at my .cpp do not have any effect.
Thank you very much in advance.

Steps to reproduce:

  1. Use the following as Dockerfile:

FROM python:3.8-slim

RUN apt-get update &&
apt-get install -y binutils cmake
gcc g++ libtool make
vim curl net-tools unzip procps gdb

  1. Use the following as devcontainer.json:
    {
    "name": "Existing Dockerfile",
    "context": "..",
    "dockerFile": "../Dockerfile",
    "extensions": ["ms-python.python", "ms-vscode.cpptools"],
    "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
    }

  2. Use the code myadd.cpp and myscript.py from: https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/

  3. Use the following as launch.json:
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal"
    },
    {
    "name": "(gdb) Attach",
    "type": "cppdbg",
    "request": "attach",
    "program": "/usr/local/bin/python",
    "processId": "${command:pickProcess}",
    "MIMode": "gdb",
    "setupCommands": [
    {
    "description": "Enable pretty-printing for gdb",
    "text": "-enable-pretty-printing",
    }
    ]
    }
    ]
    }

  4. Set the appropriate breakpoints in myscript.py (line 5) and in myadd.cpp (line 12)

  5. Start Debugging the python script

  6. When stop, attach the C++ debugger

  7. Continue execution of python script

At this point, a cpptools terminal is created but gdb does not stop in the .cpp code, and the program executes until the end.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the mixed Python/C++ session using the Dockerfile, devcontainer.json, and launch.json shown in the issue, then inspect the cpptools terminal and GDB attach behavior. Compare breakpoint handling in myscript.py and myadd.cpp; done means the C++ breakpoint is reached after attaching and continuing the Python process.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, docker, python, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.