microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Add permission check to database path instead of failing silently #12542

Open zcjie1 opened 2 months ago

zcjie1 commented 2 months ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

In WSL2, I compiled the Linux source code (version 5.15) and generated the compile_commands.json file using the script provided with the Linux source code.

Next, I added the path to the compile_commands.json file in the c_cpp_properties.json configuration and it was a long time wait.

when I attempted to navigate to the definitions of functions or variables, I encountered issues where the IDE indicated that these symbols were undefined.

I tested several versions of the extension, including those from the 1.21.x, 1.20.x, 1.19.x, 1.18.x, and 1.17.x series, but not every single version within each series. The ability to navigate to the definition of functions or variables worked as expected in version 1.17.5.

ps: when in VMware VM Ubuntu22.04 with remote ssh in Windows 11, the navigate ability works as expected in version 1.21.4.

Configuration and Logs

c_cpp_properties.json:
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "cStandard": "gnu11",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "${default}",
            "compileCommands": "compile_commands.json",
            "compilerPath": "",
            "dotConfig": "",
            "compilerArgs": []
        }
    ],
    "version": 4
}

item in compile_commands.json:
{
  "command": "gcc -Wp,-MMD,block/.bdev.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/11/include -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough=5 -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-stack-clash-protection -g -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-alloc-size-larger-than -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned    -DKBUILD_MODFILE='\"block/bdev\"' -DKBUILD_BASENAME='\"bdev\"' -DKBUILD_MODNAME='\"bdev\"' -D__KBUILD_MODNAME=kmod_bdev -c -o block/bdev.o block/bdev.c",
  "directory": "/home/zcj/linux",
  "file": "/home/zcj/linux/block/bdev.c"
},

Other Extensions

No response

Additional context

No response

sean-mcmanus commented 2 months ago

All definitions aren't found? Is the Outline view always empty for active files?

With C_Cpp.loggingLevel set to "Debug" do you ever see any "tag parsing" messages (or error messages), such as after making an edit?

When you run C/C++: Log Diagnostics from the command palette, what does it show after the Browse Paths from compile_commands.json, from workspace folder: logging and what paths in that list do not work with go to definition?

zcjie1 commented 2 months ago

@sean-mcmanus

In version 1.21.6

  1. The Outline view is always empty and show "loading document symbols for "xxx.c"..."

  2. There is no "tag parsing" message in debug log when edit the file, but in the next image when hover on " Rescan workspace":

Snipaste_2024-08-06_08-22-56

Snipaste_2024-08-06_08-25-51

In version 1.17.5

The Outline view is normal

Colengms commented 2 months ago

Hi @zcjie1 . Could you enable the setting "C_Cpp.loggingLevel": "Debug" and provide the log output from the C/C++ output channel, from startup until the repro? I suspect the issue may be that the compiler command line isn't being correctly interpreted. The log output may help clarify that. It would also be useful to know whether that log output stalls (or logs only 'received' messages and doesn't 'invoke' them). If so, the last 'invoked' message logged may provide us some clues. Or is it continuing to actively output to the log the whole time?

Also, do you know if you have any symbolic links under your workspace folder? We have a known issue where a symbolic link that creates a circular reference could cause hang on startup. (This should be addressed in our next release, 1.22.0)

zcjie1 commented 2 months ago

@Colengms .

  1. The complete debug information: debug.log

  2. There are exactly some symbolic link files under the workspace folder, but I don't think they cause circular references:

find linux -type l linux/tools/testing/selftests/powerpc/vphn/vphn.c linux/tools/testing/selftests/powerpc/vphn/asm/lppaca.h linux/tools/testing/selftests/powerpc/stringloops/memcmp_64.S linux/tools/testing/selftests/powerpc/stringloops/memcmp_32.S linux/tools/testing/selftests/powerpc/stringloops/strlen_32.S linux/tools/testing/selftests/powerpc/primitives/word-at-a-time.h linux/tools/testing/selftests/powerpc/primitives/asm/feature-fixups.h linux/tools/testing/selftests/powerpc/primitives/asm/asm-const.h linux/tools/testing/selftests/powerpc/primitives/asm/ppc_asm.h linux/tools/testing/selftests/powerpc/primitives/asm/asm-compat.h linux/tools/testing/selftests/powerpc/primitives/asm/extable.h linux/tools/testing/selftests/powerpc/nx-gzip/include/vas-api.h linux/tools/testing/selftests/powerpc/copyloops/memcpy_64.S linux/tools/testing/selftests/powerpc/copyloops/copyuser_power7.S linux/tools/testing/selftests/powerpc/copyloops/copy_mc_64.S linux/tools/testing/selftests/powerpc/copyloops/memcpy_power7.S linux/tools/testing/selftests/powerpc/copyloops/copyuser_64.S linux/arch/x86_64/boot/bzImage linux/arch/arm/boot/dts/sun8i-a23-ippo-q8h-v1.2.dts linux/arch/arm/boot/dts/sun8i-a33-ippo-q8h-v1.2.dts linux/arch/arm/boot/dts/sun8i-a23-ippo-q8h-v5.dts linux/arch/arm/boot/dts/sun8i-a33-et-q8-v1.6.dts linux/arch/arm64/boot/dts/arm/vexpress-v2m-rs1.dtsi linux/include/dt-bindings/input/linux-event-codes.h linux/include/dt-bindings/clock/qcom,dispcc-sm8150.h linux/Documentation/Changes linux/scripts/dummy-tools/objcopy linux/scripts/dummy-tools/nm linux/scripts/dtc/include-prefixes/arc linux/scripts/dtc/include-prefixes/mips linux/scripts/dtc/include-prefixes/powerpc linux/scripts/dtc/include-prefixes/openrisc linux/scripts/dtc/include-prefixes/nios2 linux/scripts/dtc/include-prefixes/sh linux/scripts/dtc/include-prefixes/microblaze linux/scripts/dtc/include-prefixes/arm linux/scripts/dtc/include-prefixes/dt-bindings linux/scripts/dtc/include-prefixes/h8300 linux/scripts/dtc/include-prefixes/arm64 linux/scripts/dtc/include-prefixes/xtensa

Colengms commented 2 months ago

Hi @zcjie1 . I see a bunch of the following in your log:

Unable to access browse database

I've actually not seen this before. Usually an issue accessing the browse database is reported as an error opening it. Perhaps the database exists but cannot be written to, or is in a path you no longer have permission to?

Could you try setting an explicit path for a browse database to a known-good location using the C_Cpp.default.browse.databaseFilename setting or in c_cpp_properties.json using the browse.databaseFilename field?

zcjie1 commented 2 months ago

@Colengms

When I set C_Cpp.default.browse.databaseFilename to customized path, it works.

I find the default databaseFile in the Windows system because of WSL2 environment: image

I have sufficient permissions to access the databaseFile, but why Unable to access browse database ?

By the way, it woreks in version 1.17.5 without changing the default databaseFile.

Colengms commented 2 months ago

Hi @zcjie1 . Just to confirm, did you have to go all the way back to 1.17.5 to resolve the issue? (There are some pre-release versions after 1.17.5, but since we don't currently have a pre-release out, the marketplace UI might not be making old pre-releases available to install. They can be found in the Releases section here in our repo.)

Colengms commented 2 months ago

Also, I'm not sure that's the path used for projects opened in your Linux remote. That looks like the path used for project opened locally on Windows.

There was a change in 1.18.0:

Switch to using XDG_CACHE_HOME on Linux for the default database path. https://github.com/microsoft/vscode-cpptools/issues/10191

Is it possible the issue has something to do with the value of that var, or the permission of the path it refers to?

https://github.com/microsoft/vscode-cpptools/blob/0ffdc003fac22feb054aac5ceb6d2ce3907d0b0d/Extension/src/common.ts#L1337-L1343

zcjie1 commented 2 months ago

@Colengms .

I recursively change the owner of ~/.cache/vscode-cpptools(originally root) , and it works.

I'm not sure if I mistakenly used the root user to install VS Code on WSL2, or if there's an issue with the initialization code of the extension?

Colengms commented 2 months ago

Hi @zcjie1 . The account used to create the directory should have been the account the directory is under. The C/C++ Extension doesn't directly deal with file system account permissions. It assumes the permissions provided by VS Code should be sufficient and consistent. It's possible there was an issue with VS Code in which the wrong account permissions were used, or perhaps permissions on the folder or database were changed for some other reason.

We can use this issue to track adding checking of the permissions of the database path and existing database file.