Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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": [

    {
        "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?

Q2:How do I keep the focus on callstack belonging to that thread?

like image 605
vraa Avatar asked Dec 05 '25 03:12

vraa


1 Answers

I found only one option to do this. In the VS Code Debug Console, when you stop at a breakpoint, you need to run the command

-exec set scheduler-locking step

enter image description here

Unfortunately, I can't found how to setting up the scheduler-locking option before starting debugging. So, I asked about this here

like image 91
mr NAE Avatar answered Dec 08 '25 09:12

mr NAE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!