microsoft / microsoft/vscode-cpptools

Debug a Python C/C++ extension in VSCode on Windows

Aperta
#6,974 11 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

debugger help wanted question
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Type: Debugger

Describe the bug

  • OS and Version: Windows 10, 64-bit
  • VS Code Version: 1.53.2
  • C/C++ Extension Version: 1.2.0
  • Other extensions you installed (and if the issue persists after disabling them): Python
  • Vscode Github issue that redirects me here: issue
  • I wouild like to debug a Python C/C++ extension on Windows I have posted a question with full details in StackOverflow, but no suitable answer has been posted.
    In Linux, it seems to be possible (see Nadiah link). However, on Windows, after attaching a "(gdb) attach" to the active Python process, I cannot stop on any breakpoint of the C code.
    I can debug a standalone C/C++ application without problems.
    I am not sure if it is a bug or it is a feature that is not yet available in Windows. Any help is much appreciated.

To Reproduce
Please include a code sample and launch.json configuration.
Code to reproduce the behavior:

  1. Python Code
import os
import greet

pid = os.getpid()

test=2.2

greet.greet('World')

print("hi")
  1. C code
#include <Python.h>

static PyObject *
greet_name(PyObject *self, PyObject *args)
{
    const char *name;

    if (!PyArg_ParseTuple(args, "s", &name))
    {
        return NULL;
    }
    
    printf("Helllo %s!\n", name);

    Py_RETURN_NONE;
}

static PyMethodDef GreetMethods[] = {
    {"greet", greet_name, METH_VARARGS, "Greet an entity."},
    {NULL, NULL, 0, NULL}
};

static struct PyModuleDef greet =
{
    PyModuleDef_HEAD_INIT,
    "greet",     /* name of module */
    "",          /* module documentation, may be NULL */
    -1,          /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
    GreetMethods
};

PyMODINIT_FUNC PyInit_greet(void)
{
    return PyModule_Create(&greet);
}

I compile the C code with GCC 8.1 by running

python setup.py install

  1. Setup file
import os

from setuptools import setup, Extension

os.environ["CC"] = "g++-8.1.0"

_DEBUG = True
_DEBUG_LEVEL = 0
# extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args = ["-Wall", "-Wextra"]
if _DEBUG:
    extra_compile_args += ["-g3", "-O0", "-DDEBUG=%s" % _DEBUG_LEVEL, "-UNDEBUG"]
else:
    extra_compile_args += ["-DNDEBUG", "-O3"]

setup(
    name='greet',
    version='1.0',
    description='Python Package with Hello World C Extension',
    ext_modules=[
        Extension(
            'greet',
            sources=['greetmodule.c'],
            py_limited_api=True,
            extra_compile_args=extra_compile_args)
    ],
)

I even specify O0 option to have all debug symbols.

  1. Launch JSON file
"configurations": [
    {
        "name": "(gdb) Attach",
        "type": "cppdbg",
        "request": "attach",
        "program": "venv/Scripts/python",
        "processId": "${command:pickProcess}",
        "MIMode": "gdb",
        // "miDebuggerPath": "/path/to/gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    },
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    }
]

Steps that I follow:

  1. Add a breakpoint in the python file, run the launch configuration “Python: Current File” and wait until the breakpoint is reached.
  2. Run the “(gdb) Attach” launch configuration, select the python interpreter whose path contains “/.vscode/”. In this case, in Windows, I am not getting prompted to enter my user password as it happens in Linux.
  3. Set breakpoints in the C++ Files
  4. The python debugger is currently stopped at a break point. Switch back from the debugger “(gdb) Attach” to the other debugger “Python: Current File” and press F5 (Continue).
    In this last step, vscode should automatically jump between the two debuggers between python and c++ code, but I cannot achieve this behavior.

I am able to debug Python and C programs alone, but not together.

Additional context
If applicable, please include logging by adding "logging": { "engineLogging": true, "trace": true, "traceResponse": true } in your launch.json
Add any other context about the problem here including log or error messages in your Debug Console or Output windows.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema con greetmodule.c, setup.py e le due configurazioni di avvio: “Python: Current File” e “(gdb) Attach”. Leggi la sequenza dei breakpoint riportata e confronta il comportamento delle sessioni di debugging Python e C/C++ su Windows. L’attività è completata quando il workflow documentato di debugging misto Python/C può arrestarsi sul breakpoint C e riprendere tra entrambi i debugger, oppure quando la limitazione supportata è chiaramente identificata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, cpp, python, vscode
Ambito
desktop, devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.