相关疑难解决方法(0)

在 Windows 上的 VSCode 中调试 Python C/C++ 扩展

问题总结

我正在为 Python 开发一个自 C 扩展,以提高特定代码段的性能。我想调试这个扩展,但到目前为止我还没有成功。我遵循了几个链接,例如来自 Nadiah来自 Bark,但我总是遇到同样的问题:我无法在 C 代码的任何断点处停止。

我尝试过的方法

这个想法是将 Python 作为主进程运行,并将编译后的 C 代码附加到这个主进程。下面我留下一个最小的可重复示例

蟒蛇文件

import os
import greet

pid = os.getpid()

test=2.2

greet.greet('World')

print("hi")
Run Code Online (Sandbox Code Playgroud)

如您所见,我什至在附加C代码时检索进程ID,以便在vscode中选择此ID,如下所示:

代码

#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 …
Run Code Online (Sandbox Code Playgroud)

c c++ python debugging visual-studio-code

12
推荐指数
1
解决办法
813
查看次数

标签 统计

c ×1

c++ ×1

debugging ×1

python ×1

visual-studio-code ×1