简体   繁体   English

使用 vscode 在调试多线程 C 程序时单步切换线程

[英]Step-over switches thread while debugging multi-threaded C program with vscode

Stepping multi-threaded C program with VSCode's debugger switches thread on every step.使用 VSCode 的调试器单步执行多线程 C 程序会在每一步切换线程。

The thread where debugger jumps runs code like this:调试器跳转的线程运行如下代码:

do {
    rc = nanosleep(&rqtp, &rem);
    rqtp = rem;
} while (rc < 0 && errno == EINTR);

My debugger configuration is as follows: "version": "0.2.0", "configurations": [我的调试器配置如下:“版本”:“0.2.0”,“配置”:[

    {
        "name": "solid Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/program",
        "args": ["-a","-b"],
        "stopAtEntry": true,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    }

Q1:How do I get debugger to stick with the thread which ran into breakpoint? Q1:如何让调试器坚持运行到断点的线程?

Q2:How do I keep the focus on callstack belonging to that thread? Q2:如何将焦点放在属于该线程的调用堆栈上?

Answer to Q1: According to this SO thread , adding set scheduler-locking on to the gdb will let you stay in the same thread when you single-step.对 Q1 的回答:根据这个 SO thread ,将set scheduler-locking on添加到 gdb 将使您在单步执行时保持在同一线程中。

Not sure about Q2, but this should give you what you need to continue.不确定 Q2,但这应该为您提供继续所需的信息。 I'd think the callstack of the current thread is shown, but I'm not sure.我认为显示了当前线程的调用堆栈,但我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM