15
votes

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?

1

1 Answers

0
votes

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.

Not sure about Q2, but this should give you what you need to continue. I'd think the callstack of the current thread is shown, but I'm not sure.