我的 VS Code 工作区变成“不允许操作”当使用gdb时
我正在尝试通过 Visual Studio Code(Microsoft C/C++ 扩展
)通过 gdb 调试一个非常简单的 C 程序 main.c
。
#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);
}
当我开始调试时,我的 VS Code 要求我允许 main
访问我的文件夹
然后奇怪的事情发生了。
如果我选择不允许
,调试器似乎仍然运行良好。
但是,如果我选择OK
,在main
退出后,我的VS Code的工作区资源管理器和终端将无法再打开任何文件,如下所示:
$ ls
ls: .: Operation not permitted
现在在VS Code终端中创建一个新的tty将抛出错误
shell-init: error retrieving current directory: getcwd
job-working-directory: error retrieving current directory: getcwd: cannot access
通过 VS Code 打开最近的文件(例如 main.c)将抛出错误:EPERM:不允许操作
以下是 VS Code 在设置调试器后生成的一些信息
# 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
权限
$ 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
抱歉
我的英语很差。请原谅语法或打字错误。我正在尽力改进。
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论