My VS Code workspace turn "Operation not permitted" when use gdb

Viewed 154

I'm trying to debug a very simple C program main.c by gdb via Visual Studio Code(Microsoft C/C++ extension).

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc,char *argv[]) {
    int *ptr = malloc(sizeof(int));
    int x;
    printf("code addr: %p\n", &main);
    printf("heap addr: %p\n", ptr);
    printf("stack addr: %p\n", &x);
}

When I start debugging, my VS Code ask me for allow main access my folder

see picture here.

Then something stranger happened.

If I select Don't Allow, the debugger still seems to be working well.

But if I select OK, after main exit, my VS Code's workspace explorer and terminal can no longer open any file, like below:

$ ls
ls: .: Operation not permitted

Now creating a new tty in VS Code terminal will throw error

shell-init: error retrieving current directory: getcwd
job-working-directory: error retrieving current directory: getcwd: cannot access

Opening a recent file(such as main.c) by VS Code will throw Error: EPERM: operation not permitted

Below is some information generated by VS Code after setup debugger

# vscode launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: gcc build active file"
        }
    ]
}
# vscode tasks.json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

VS Code info

Version: 1.64.0
Commit: 5554b12acf27056905806867f251c859323ff7e9
Date: 2022-02-03T04:20:17.224Z (1 mo ago)
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin x64 21.2.0

Permissions

$ ls -la                      
total 128
drwxr-xr-x   7 ljf  staff    224 Mar 14 14:46 .
drwxr-xr-x  25 ljf  staff    800 Mar 14 14:15 ..
-rw-r--r--   1 ljf  staff     65 Mar 14 10:25 Makefile
-rw-r--r--   1 ljf  staff     57 Mar 14 10:26 README.md
-rwxr-xr-x   1 ljf  staff  49936 Mar 14 14:46 main
-rw-r--r--   1 ljf  staff    560 Mar 14 11:32 main.c
drwxr-xr-x   3 ljf  staff     96 Mar 14 14:46 main.dSYM
$ whoami 
ljf
$ tree main.dSYM
main.dSYM
└── Contents
    ├── Info.plist
    └── Resources
        └── DWARF
            └── main

sorry

My English is poor. Please excuse grammar or typing error. I'm trying my best to improve.

0 Answers
Related