microsoft / microsoft/vscode-cpptools

Debugger: error when debug code in "-gdb-set follow-fork-mode child" with popen

Aperta
#8,109 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

debugger more info needed
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

Bug type: Debugger

Describe the bug

  • OS and Version: Debian 9.13
  • VS Code Version: 1.60.0
  • C/C++ Extension Version: v1.6.0
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is.

Try to debug forked process by using this command:

                {
                    "description": "The new process is debugged after a fork. The parent process runs unimpeded.",
                    "text": "-gdb-set follow-fork-mode child",
                    "ignoreFailures": true
                }

However, the program being debugged has popen() that creates several threads, which crashes the debug process.

I guess vscode might "set follow-fork-mode child" right before calling fork() and immediately unset it after fork().

To Reproduce
Please include a code sample and launch.json configuration.
Steps to reproduce the behavior:

  1. Touch main.c
  2. Write the code in the file:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    printf("start popen\n");
    popen("echo hello", "r");
    printf("start fork\n");

    int pid = fork();

    if (pid== 0)
        printf("Hello from Child!\n");
  
    // parent process because return value non-zero.
    else
        printf("Hello from Parent!\n");

    return 0;
}

  1. Generate default launch.json and task.json
  2. Modify launch.json as:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc-6 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "The new process is debugged after a fork. The parent process runs unimpeded.",
                    "text": "-gdb-set follow-fork-mode child",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc-6 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
  1. Set some breakpoints from the start of main and debug step-by-step.
  2. Keep next-ing until debug process dies unnaturally.

Additional context
If applicable, please include logging by adding "logging": { "engineLogging": true, "trace": true, "traceResponse": true } in your launch.json
Add any other context about the problem here including log or error messages in your Debug Console or Output windows.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il riproduttore main.c e i setupCommands di launch.json usando -gdb-set follow-fork-mode child, quindi abilita engineLogging, trace e traceResponse. Analizza il comportamento del debugger intorno a popen(), fork() e al processo figlio; il lavoro è completato quando il debug del processo figlio non causa più la terminazione imprevista del processo di debug.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, typescript
Ambito
devtools, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.