microsoft / microsoft/vscode-cpptools
Unable to debug C++ from a python script in container
Nobody has claimed this yet.
- 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:
- 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
-
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" ],
} -
Use the code myadd.cpp and myscript.py from: https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/
-
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",
}
]
}
]
} -
Set the appropriate breakpoints in myscript.py (line 5) and in myadd.cpp (line 12)
-
Start Debugging the python script
-
When stop, attach the C++ debugger
-
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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