Vscode-cpptools: [GDB] follow-fork-mode child

Created on 21 Feb 2017  Â·  10Comments  Â·  Source: microsoft/vscode-cpptools

GDB has a command called set follow-fork-mode child that instructs GDB to follow the forked process. I couldn't find a way to do this with this plugin.

I tried adding various permutations of "-exec set follow-fork-mode child" to the setup commands in the launch.json, but wasn't able to get it to work.

Is it possible to set this up from launch.json?

bug debugger question

Most helpful comment

@ApoorvaJ We use gdb's MI command structure. This is the block you need to add to your launch.json section:

            "setupCommands": [
                {"text": "-gdb-set follow-fork-mode child"}
            ]

Note: There is a bug in the current release version that crashes and makes it so that this doesn't work. I have fixed it (and referenced the Pull Request) and it will be in our 0.10.2 release.

All 10 comments

@ApoorvaJ Do you have a simple code example I can try out for this?

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    pid_t pid = fork();
    if (pid != 0) {
        printf("Main process\n");
    } else {
        printf("Forked process\n");
    }

    return 0;
}

Compile using the gcc -g fork.c option on command line on Linux to enable debug symbols. Open in gdb using gdb ./a.out Set breakpoints on both printfs. Try running. You'll only ever hit the main process breakpoint.

To hit the other one, type in set follow-fork-mode child into gdb, and then run again. You'll now only hit the forked process breakpoint.

I'd like to control this behaviour in the launch.json file while debugging via VS Code.

@ApoorvaJ Thanks. I'll take a look and let you know.

@ApoorvaJ We use gdb's MI command structure. This is the block you need to add to your launch.json section:

            "setupCommands": [
                {"text": "-gdb-set follow-fork-mode child"}
            ]

Note: There is a bug in the current release version that crashes and makes it so that this doesn't work. I have fixed it (and referenced the Pull Request) and it will be in our 0.10.2 release.

@ApoorvaJ 0.10.2 is live. Closing this issue because it is resolved.

can't switch to child process in VS code version 1.34.0

Also, can't switch to child process in VS code version 1.35.0

Version 1.37.1 I'm unable to even start the process. I get a write EPIPE error. I have ensured that I'm in fact loading the correct child source code. It runs fine in stand-alone node.

@curtiskeisler yours sounds like a different issue . Please file a new issue with logging information.

This is the block you need to add to your launch.json section:

            "setupCommands": [
                {"text": "-gdb-set follow-fork-mode child"}
            ]

Is this in the docs?

Was this page helpful?
0 / 5 - 0 ratings