vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Endless "parsing opened files" (1.3.0 regression)

Open sean-mcmanus opened this issue 5 years ago • 23 comments

I started to experience this issue about week ago (current version was 1.3.1 for this extension). After some time since vscode starts db icon shows parsing files, then load stops. However when I start editing c++ file (simple click into it is enough), it starts "parsing opened files" and it never ends.

Now I downgraded version to 1.2.2 and there is no issue with excessive load.

It might not be related to the original issue (whole project is much bigger)

Originally posted by @kiiv-cz in https://github.com/microsoft/vscode-cpptools/issues/5574#issuecomment-823245598

sean-mcmanus avatar Apr 20 '21 18:04 sean-mcmanus

@kiiv-cz Do you have any more repro info? If you set C_Cpp.loggingLevel to "Debug" do you see any logging messages?

What is the call stack of the thread that is doing work when you attach/break with a debugger (https://github.com/microsoft/vscode-cpptools/wiki/Attaching-debugger-to-cpptools-or-cpptools%E2%80%90srv)?

sean-mcmanus avatar Apr 20 '21 18:04 sean-mcmanus

It seems to be caused by one of the threads and ctrl+<right click> on some symbol in code. It's running for a long time (several minutes - but when I'm working, it'll look like it's non-stop) at 100% as opposed to 1.2.2 that just makes short spikes in usage:

Thread 14 (Thread 0x7f5c30e0c700 (LWP 34616)):
#0  0x00000000007ff7e5 in browse_engine::query_include_path_suggestions_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, bool, std::map<code_store::a_record_id<code_store::a_file_tag>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<code_store::a_record_id<code_store::a_file_tag> >, std::allocator<std::pair<code_store::a_record_id<code_store::a_file_tag> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >*) ()
#1  0x00000000007f20e9 in browse_engine::parse_file(unsigned long, char const*, code_store::a_record_id<code_store::a_file_tag> const&, std::unordered_set<code_store::a_record_id<code_store::a_file_tag>, std::hash<code_store::a_record_id<code_store::a_file_tag> >, std::equal_to<code_store::a_record_id<code_store::a_file_tag> >, std::allocator<code_store::a_record_id<code_store::a_file_tag> > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, parser&, std::function<void ()>, std::shared_ptr<include_paths>, bool) ()
#2  0x00000000007f6f41 in browse_engine::parse_file(unsigned long, char const*, bool, std::function<void ()>, std::shared_ptr<include_paths>, bool) ()
#3  0x00000000007642af in vscode::message_handler::parse_file(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::function<void ()>, std::shared_ptr<vscode::message_handler::optional_parse_file_args>) ()
#4  0x000000000077d12d in std::_Function_handler<void (), vscode::message_handler::main_loop()::$_10>::_M_invoke(std::_Any_data const&) ()
#5  0x0000000000f0abb0 in execute_native_thread_routine ()
#6  0x00007f5c37846609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#7  0x00007f5c3776d293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 14 (Thread 0x7f5c30e0c700 (LWP 34616)):
#0  __GI___libc_malloc (bytes=128) at malloc.c:2940
        ar_ptr = <optimized out>
        victim = <optimized out>
        hook = <optimized out>
        tbytes = <optimized out>
        tc_idx = <optimized out>
        __PRETTY_FUNCTION__ = "__libc_malloc"
#1  0x0000000000e8a345 in operator new(unsigned long) ()
--Type <RET> for more, q to quit, c to continue without paging--
No symbol table info available.
#2  0x0000000000640dcc in void std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>(__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
No symbol table info available.
#3  0x0000000000df5cca in msvc::path_utf8::split_path(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
No symbol table info available.
#4  0x0000000000df400a in msvc::path_utf8::path_utf8(std::basic_string_view<char, std::char_traits<char> >, bool) ()
No symbol table info available.
#5  0x0000000000df5593 in msvc::path_utf8::folder() const ()
No symbol table info available.
#6  0x00000000007ff53f in browse_engine::query_include_path_suggestions_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, bool, std::map<code_store::a_record_id<code_store::a_file_tag>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<code_store::a_record_id<code_store::a_file_tag> >, std::allocator<std::pair<code_store::a_record_id<code_store::a_file_tag> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >*) ()
No symbol table info available.
#7  0x00000000007f20e9 in browse_engine::parse_file(unsigned long, char const*, code_store::a_record_id<code_store::a_file_tag> const&, std::unordered_set<code_store::a_record_id<code_store::a_file_tag>, std::hash<code_store::a_record_id<code_store::a_file_tag> >, std::equal_to<code_store::a_record_id<code_store::a_file_tag> >, std::allocator<code_store::a_record_id<code_store::a_file_tag> > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, parser&, std::function<void ()>, std::shared_ptr<include_paths>, bool) ()
No symbol table info available.
#8  0x00000000007f6f41 in browse_engine::parse_file(unsigned long, char const*, bool, std::function<void ()>, std::shared_ptr<include_paths>, bool) ()
No symbol table info available.
#9  0x00000000007642af in vscode::message_handler::parse_file(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::function<void ()>, std::shared_ptr<vscode::message_handler::optional_parse_file_args>) ()
No symbol table info available.
#10 0x000000000077d12d in std::_Function_handler<void (), vscode::message_handler::main_loop()::$_10>::_M_invoke(std::_Any_data const&) ()
No symbol table info available.
#11 0x0000000000f0abb0 in execute_native_thread_routine ()
No symbol table info available.
#12 0x00007f5c37846609 in start_thread (arg=<optimized out>) at pthread_create.c:477
        ret = <optimized out>
        pd = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140033933756160, 6074051129793129596, 140033967324142, 140033967324143, 140033967324144, 140033933754304, -6128488064304993156, -6128499301874979716}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x0, 0x0}, data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
        not_first_call = 0
#13 0x00007f5c3776d293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
No locals.

kiiv-cz avatar Apr 20 '21 21:04 kiiv-cz

Yeah, that call stack matches the call stack another user reported at https://github.com/microsoft/vscode-cpptools/issues/7218 .

That code path appears to be for when recursive includes "**" is not used -- can you confirm that that is the case for you?

That code has checks that should be preventing infinite loops so I'm not sure what is going on yet or how to get a repro.

1.3.0 added some changes regarding symlinks and file iteration that could somehow be impacting this, but none of that code changed directly.

sean-mcmanus avatar Apr 20 '21 22:04 sean-mcmanus

It seems the recursive includes are used:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "clang-x64",
            "compileCommands": "${workspaceFolder}/cmake-build-debug/compile_commands.json"
        }
    ],
    "version": 4
}

From debug it looks like "Discovering files" is doing whole filesystem (ends around 1300000 files) and workspace has only around 85000 (and not everything is C/C++).

kiiv-cz avatar Apr 21 '21 06:04 kiiv-cz

It might be related to that mentioned "discovery files"

idle loop: reparsing the active document
Checking for syntax errors: file:///wa/wtf/5G/vcm-smfplc/policy/src/DecisionRegister.cpp
Queueing IntelliSense update for files in translation unit of: /wa/wtf/5G/vcm-smfplc/policy/src/DecisionRegister.cpp
Error squiggle count: 1
Error squiggle count: 8
Update IntelliSense time (sec): 18.861
  tag parsing file: /proc/pressure/memory
  tag parsing file: /proc/98/limits
  tag parsing file: /proc/98/task/98/limits
  tag parsing file: /proc/97/limits
  tag parsing file: /proc/97/task/97/limits
  tag parsing file: /proc/96/limits
...

It's parsing absolutely everything in /proc ending with stack, limits, memory

Edit for 1.2.2 after start:

  Processing folder (recursive): /usr/include/
  Processing folder (recursive): /usr/lib/llvm-10/lib/clang/10.0.0/include/
  Processing folder (recursive): /usr/local/include/
  Processing folder (recursive): /wa/wtf/5G/
Database safe to open
  Discovering files: 80921 file(s) processed

So it's doing related directories only, not a whole filesystem

kiiv-cz avatar Apr 21 '21 07:04 kiiv-cz

@kiiv-cz It seems like you may have a symlink to "/" or "/proc" or under "${workspaceFolder}". Can you add "/proc": true to your "C_Cpp.files.exclude" setting (or add other similar excludes if you see those, or add an exclude to symlink if you can locate that)? 1.3.0 fixed issues with our directory iteration code which may have previously been (unintentionally) blocking our ability to recurse into the symlink, i.e. the iteration behavior with a symlink seems "by design" so far, but I don't understand yet how you're hitting the "query_include_path_suggestions_impl" code after opening a file when you're using recursive includes so I'm investigating that still.

Also, after adding the C_Cpp.files.exclude it may get "stuck" removing hundreds of thousands of files from the database, so it may be quicker to do a Reset IntelliSense Database command afterwards.

sean-mcmanus avatar Apr 21 '21 18:04 sean-mcmanus

@kiiv-cz I think I'm reproing the bug -- after opening the .cpp file that has #include <limit> it seems to get stuck when it shouldn't (even with the C_Cpp.files.exclude set).

sean-mcmanus avatar Apr 21 '21 18:04 sean-mcmanus

@kiiv-cz Oops, no, I was mistaken. I had my files.exclude set to false on accident. Setting them to true fixed the issue.

sean-mcmanus avatar Apr 21 '21 18:04 sean-mcmanus

Doesn't look like there is any symlink to / or /proc. However there are 711 out of 721 links broken. Is there any possibility that broken links becomes something like / ?

kiiv-cz avatar Apr 21 '21 18:04 kiiv-cz

I'll check...

sean-mcmanus avatar Apr 21 '21 19:04 sean-mcmanus

Just started 1.3.1:

  Folder: / will be indexed
Populate include completion cache.
Discovering files...
  Processing folder (recursive): /
Replaced placeholder file record

as opposed to previously mentioned startup from 1.2.2

Attempting to get defaults from C++ compiler in "compilerPath" property: '/usr/bin/clang'
  Folder: /usr/include/ will be indexed
  Folder: /usr/lib/llvm-10/lib/clang/10.0.0/include/ will be indexed
  Folder: /usr/local/include/ will be indexed
  Folder: /wa/wtf/5G/ will be indexed
Populate include completion cache.
Discovering files...
  Processing folder (recursive): /usr/include/
  Processing folder (recursive): /usr/lib/llvm-10/lib/clang/10.0.0/include/
  Processing folder (recursive): /usr/local/include/
  Processing folder (recursive): /wa/wtf/5G/
  Discovering files: 81850 file(s) processed

kiiv-cz avatar Apr 21 '21 19:04 kiiv-cz

And is this working:

            "includePath": [
                "${workspaceFolder}/**"
            ],

I can imagine it becomes /** if ${workspaceFolder} will be empty. Any change in that?

kiiv-cz avatar Apr 21 '21 19:04 kiiv-cz

How is ${workspaceFolder} empty?

sean-mcmanus avatar Apr 21 '21 19:04 sean-mcmanus

No it doesn't seems like it's empty, even with includePath "/wa/wtf/5G/**" it's doing this:

  Folder: / will be indexed
Populate include completion cache.
Discovering files...
  Processing folder (recursive): /

It just seems to be ignored... The older version used more specific include directories than /

kiiv-cz avatar Apr 21 '21 19:04 kiiv-cz

What do you see when your includePath is empty? Do you have a browse.path set? Otherwise, maybe "/" is coming from querying your compiler?

sean-mcmanus avatar Apr 21 '21 19:04 sean-mcmanus

So empty includePath is different (there are now excludes + /proc exclude):

  Folder: / will be indexed
cpptools/didChangeSettings
Populate include completion cache.
IntelliSense Engine = Default.
Enhanced Colorization is enabled.
Error squiggles are enabled if all header dependencies are resolved.
Autocomplete is enabled.
File exclude: **/.vscode
File exclude: /proc
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: **/*.code-search

And "C_Cpp.default.browse.path": ["/wa/wtf/5G"] didn't make any change (it wasn't configured before) - still Folder: / will be indexed

However older version also keeps /wa/wtf/5G/ - no change if I change includePath nor browse.path

kiiv-cz avatar Apr 21 '21 19:04 kiiv-cz

Just tried to open directory with something much smaller (simple benchmark) and no / indexing.. I give up, I just keep older version as I just don't know from where it's getting that /

kiiv-cz avatar Apr 21 '21 20:04 kiiv-cz

Yes, that is very strange. We don't know where / is coming from either, assuming /wa/wtf/5G isn't a symlink to /.

sean-mcmanus avatar Apr 21 '21 20:04 sean-mcmanus

If you have configurationProvider or compileCommands set then the / could be coming from that.

sean-mcmanus avatar Apr 21 '21 20:04 sean-mcmanus

@Colengms noticed you have compileCommands set -- we believe the "/" is getting picked up from that (removing that would confirm)...possibly a bug where we're interpreting some argument as a reference to / -- are you able to provide your compile_commands.json and/or determine which command is causing the issue?

sean-mcmanus avatar Apr 21 '21 20:04 sean-mcmanus