Visual Studio Code, когда аргументы командной строки добавляются в launch.json точки останова не получают - PullRequest
0 голосов
/ 22 декабря 2018

*** ПОСМОТРЕТЬ ДНО ДЛЯ РЕДАКТИРОВАНИЯ *

Я пытаюсь отладить программу на C в VS Code, но точка останова не задана.У меня была похожая проблема в другой программе, которую я отлаживал на прошлой неделе, и я переместил код в другой файл, открыл файл в VS Code, и точки останова работали нормально.Поэтому я думаю, что это ошибка с моей стороны, но я не могу понять, что это такое.Большинство вещей, которые я читаю при переполнении стека, это люди, которые забывают добавить -g при компиляции.Вот несколько ресурсов, на которые я смотрел:

https://code.visualstudio.com/docs/languages/cpp

https://github.com/Microsoft/vscode-cpptools/issues/1685

teeCommand.c

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>
#include <fcntl.h>

#define BUF_SIZE 1024
#define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)


int main(int argc, char *argv[])
{
int fileLength;
int inputFd, outputFd;
char* buffer;
ssize_t numRead;
char buf[BUF_SIZE];

if(argc < 5){
    printf("not enough arguments given");
}

inputFd = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if(inputFd == -1){
    handle_error("opening input file");
}

outputFd = open(argv[4], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if(outputFd == -1){
    handle_error("opening file output file");
}

while((numRead = read(inputFd, buf, BUF_SIZE)) > 0){
    if(write(outputFd, buf, numRead) != numRead){
        handle_error("could not write the whole buffer");
    }
}
if(numRead == -1){
    exit(1);
}

if(close(inputFd) == -1){
    exit(1);
}
if(close(outputFd) == -1){
    exit(1);
}

exit(EXIT_SUCCESS);
}

задачи.json

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "echo",
        "type": "shell",
        "command": "gcc -g teeCommand.c -o teeCommand",
        "group":{
            "kind": "build",
            "isDefault": true
        }
    }
]
}

launch.json

{
// 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": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/teeCommand",
        "args": ["file.txt", "|", "tee", "file2.txt"],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
]
}

Мой вывод:

& "warning: GDB: не удалось установить управляющий терминал: операция не разрешена\ n " недостаточно аргументов с учетом [1] + Готово / usr / bin / gdb --interpreter = mi --tty = $ {DbgTerm} 0 / tmp / Microsoft-MIEngine-Out-nwqez75o.cn0Нажмите любую клавишу, чтобы продолжить ...

, поэтому я вижу, что он ударяет по моему коду (жирным шрифтом), но не по точкам разрыва, которые я установил в VS Code вверху главного()

РЕДАКТИРОВАТЬ: я вижу, что проблема в моем launch.json, когда есть аргументы, добавленные к свойству args, код не останавливается в точках останова.Когда я убираю аргументы, код останавливается в точках останова

1 Ответ

0 голосов
/ 22 декабря 2018

настоятельно рекомендуем:

gdb teecommand
br main
r "file.txt", "|", "tee", "file2.txt"

, который работает так, как вы ожидаете, поэтому проблема в скрипте .json

...