microsoft / vscode-cpptools

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

Go to definition failing when done twice on symbol defined locally #6280

Open renyhp opened 4 years ago

renyhp commented 4 years ago

Type: LanguageService

Describe the bug

Steps to reproduce

  1. Open a .cpp file
  2. Click on any symbol defined in the same opened file
  3. Go to definition (or Peek definition)
  4. This works (an editor, or the peek viewer, opens), and IntelliSense also works as expected (hovering shows definition, etc)
  5. Close the newly opened editor / peek viewer
  6. Click on any symbol (whatsoever) and go to definition
  7. No definition found for 'symbol'. Also, IntelliSense stops working (hovering does not highlight anything). This might be related to the fact that the
Logs (sorry for italian) ``` -------- Diagnostics - 8/10/2020, 20:49:13 Version: 1.0.1 Current Configuration: { "name": "Linux", "includePath": [ big list of paths ], "defines": [], "compilerPath": "compilerpath", "cStandard": "c11", "cppStandard": "c++14", "intelliSenseMode": "gcc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "path": [ big list of paths ] }, "compilerArgs": [] } Translation Unit Mappings: [ /path/to//myfile.cc. ]: /path/to//myfile.cc Translation Unit Configurations: [ /path/to//myfile.cc ]: not ready Process ID: 22754 Memory Usage: 3 MB Compiler Path: compiler path Includes: big list of paths Standard Version: c++14 IntelliSense Mode: gcc-x64 Other Flags: --g++ --gnu_version=80200 Total Memory Usage: 3 MB ------- Workspace parsing diagnostics ------- Number of folders and files enumerated: 21991 Number of files discovered (not excluded): 18112 # C++ log ciclo inattivo: rianalisi del documento attivo textDocument/hover: file:///path/to//myfile.cc (id: 26) textDocument/hover: file:///path/to//myfile.cc (id: 27) textDocument/hover: file:///path/to//myfile.cc (id: 28) Arresto del server IntelliSense: /path/to//myfile.cc terminazione del processo figlio: 22666 ancora attivo. Verrà terminato... Il processo non è stato ancora terminato. Verrà sospeso per 10 millisecondi prima di riprovare. Il processo non è stato ancora terminato. Verrà sospeso per 20 millisecondi prima di riprovare. Il processo non è stato ancora terminato. Verrà sospeso per 40 millisecondi prima di riprovare. Chiusura del canale di comunicazione. Il client IntelliSense non è disponibile. Verrà usato il parser di tag per passare alla definizione. Il client IntelliSense non è disponibile. Verrà usato il parser di tag per accedere alle informazioni rapide. utilizzo del parser di tag per accedere alle informazioni rapide ```

Additional context The file is quite big (~2000 lines), and the project is also big (as you can see from logs). It might be relevant that the project is accessed on an AFS mount.

sean-mcmanus commented 4 years ago

It sounds like cpptools-srv may be crashing. Do you see a "failed" message in the C/C++ logs?

If so, can you follow the steps at https://github.com/microsoft/vscode-cpptools/wiki/Attaching-debugger-to-cpptools-or-cpptools%E2%80%90srv to get a crash call stack?

renyhp commented 4 years ago

Actually, the C++ logs look like the IntelliSense server is shut down (Arresto del server IntelliSense), then it waits for the process to terminate (Il processo non è stato ancora terminato), then some communication channel gets closed (Chiusura del canale di comunicazione) and the IntelliSense client becomes unavailable (Il client IntelliSense non è disponibile). There is no sign of crashing.

Here is the full log after attaching to cpptools-srv and reproducing the bug:

=thread-group-added,id="i1"
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New LWP 24158]
[New LWP 24159]
[New LWP 24160]
[New LWP 24161]
[New LWP 24162]
[New LWP 24164]
0x00007f105b47c36c in ?? ()
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Switching to thread 7 (LWP 24164)](running)
=thread-selected,id="7"
[LWP 24164 exited]
[New LWP 24465]
[LWP 24465 exited]
[LWP 24161 exited]
[LWP 24160 exited]
[LWP 24159 exited]
[LWP 24158 exited]
[LWP 24157 exited]

Program terminated with signal SIGKILL, Killed.
The program no longer exists.
Debugger has disconnected from the program '/home/renyhp/.vscode/extensions/ms-vscode.cpptools-1.0.1/bin/cpptools'.

The debugger stops as soon as the editor opened by the first 'Go to Definition' is closed.

sean-mcmanus commented 4 years ago

The logging shows you're attached to cpptools instead of cpptools-srv. Are you saying cpptools-srv also doesn't crash?

I don't fully understand your repro steps. I don't understand why in step 4 you're saying a windows opens if you're doing a Go to Def on a symbol thats defined in the original .cpp file. I don't know what file is being used in step 6.

renyhp commented 4 years ago

Ok, so this is strange. I was reproducing the bug while fiddling a bit with VS Code and suddenly I can't reproduce the bug anymore... but I'm quite sure I haven't changed any settings.

I will answer your questions anyway. Yes, the logging does show I'm attached to cpptools: I was sure I attached to cpptools-srv but it seems like I was wrong. I was sure I knew why in step 4 a windows opens, because I liked that I could return to where I was by closing the window. I searched in the settings for something that makes a window open when clicking on Go to Definition but I actually found nothing. Now that I can't reproduce the bug, in fact, the window does not open anymore. (Which is slightly bad for my workflow as I really can't see how to get back to the caller of the definition.) I would assume that the window opening is part of the bug. In step 6 I'm still using the same file. There is just one file in all the repro steps, but two windows open showing the same file.

Something else I just noticed: variables are now properly colored blue; before, they were black.

I will comment on this issue again if and when I encounter this bug again.

renyhp commented 4 years ago

Well, that was fast :) but I think I get it now.

I was accessing the project through a symlink to the containing folder: the files are in /afs/real/path/, but I opened the folder through the symlink /home/renyhp/symlink/ (which, by the way, correctly uses an absolute path). When I Go to Definition, the two open windows show the two different paths: the caller shows ~/symlink, and the newly opened window shows /afs/real/path/. If, instead, I open VS Code in /afs/real/path/, the file is the same, no window is opened, and the bug does not present itself anymore.

I also understand why I had attached to cpptools: I had selected cpptools-srv in the dropdown menu but I had forgot to change configurations.program in launch.json to point to cpptools-srv. Here is the debugger log when reproducing the bug:

=thread-group-added,id="i1"
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New LWP 31484]
[New LWP 31485]
[New LWP 31486]
[New LWP 31487]
[New LWP 31488]
[New LWP 31491]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
__libc_read (nbytes=4, buf=0x7ffd2da8a614, fd=5) at ../sysdeps/unix/sysv/linux/read.c:26
Loaded '/lib/x86_64-linux-gnu/libm.so.6'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libpthread.so.0'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libdl.so.2'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/librt.so.1'. Symbols loaded.
Loaded '/lib/x86_64-linux-gnu/libgcc_s.so.1'. Symbols loaded.
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Switching to thread 7 (Thread 0x7f554d9c8700 (LWP 31491))](running)
=thread-selected,id="7"
[Thread 0x7f554d9c8700 (LWP 31491) exited]
[New Thread 0x7f554d9c8700 (LWP 31696)]
[Thread 0x7f554e1c9700 (LWP 31488) exited]
[Thread 0x7f554e9ca700 (LWP 31487) exited]
[Thread 0x7f554f1cb700 (LWP 31486) exited]
[Thread 0x7f554f9cc700 (LWP 31485) exited]
[Thread 0x7f55501cd700 (LWP 31484) exited]
[Thread 0x7f55501ce740 (LWP 31483) exited]

Program terminated with signal SIGKILL, Killed.
The program no longer exists.
Debugger has disconnected from the program '/home/renyhp/.vscode/extensions/ms-vscode.cpptools-1.0.1/bin/cpptools-srv'.
rhish9h commented 3 years ago

I have a similar issue for C code. Peek definition stopped working on the second attempt. Should I add the issue's details here or create a new issue?

sean-mcmanus commented 3 years ago

@rhish9h Can you file a new issue? Unless you're reproing the exact same issue with a crash of cpptools-srv and can provide a crash call stack.

rhish9h commented 3 years ago

@rhish9h Can you file a new issue? Unless you're reproing the exact same issue with a crash of cpptools-srv and can provide a crash call stack.

Hey, I'm pretty much a newbie with this and not sure what cpptools-srv is exactly. But I followed the above solution to open the project with the actual path instead of the symlink, and it works fine now.

So the issue (peek definition not working) existed when I opened the project with symlink, works well when project is opened with real path.

sean-mcmanus commented 3 years ago

@rhish9h cpptools-srv is the IntelliSense process. It sounds like you're hitting the same issue.