clang-tidy + VSCode: how to see command line? - c++

Is there a way to see the actual commmand line that VSCode is issuing to clang-tidy?
I am trying to figure out why clang-tidy is giving clang-diagnostic-error messages about being unable to find certain header files, though I have configured workspace settings file settings.json to with "C_Cpp.default.includePath" to include the necessary folders, and have configured settings.json to contain "C_Cpp.codeAnalysis.clangTidy.args" entries such as "-Imy_path/to/the/files".
The build (clang and/or gcc and/or aarch64-linux-g++) all build fine with no errors. I am using the cmake extension in VSCode to generate the makefile (Ninja) and run the build.
I can't find the reason why the #include files are not being found by clang-tidy, so it seems that checking the actual command line being issued by VSCode would be a starting point for debugging this.
Thanks in advance for any help debugging this configuration issue.

Related

GDB set breakpoints with absolute paths

I'm trying to debug an application compiled with Ninja.
I have my source code /usr/local/...project-src/
I have my build output located at /usr/local/...project-src/out/Debug/build
The compiled output includes debug information
file out/Debug/build includes:
ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
I'm able to add breakpoints when using relative paths:
cd /usr/local/...project-src
gdb
file out/Debug/build
b x/y.cc:34
# success
Breakpoint 1 at <mem-loc>: file ../../x/y.cc, line 34.
But when I use absolute paths, it fails
cd /usr/local/...project-src
gdb
file out/Debug/build
b /usr/local/...project-src/x/y.cc
# failure
No source file named /usr/local/...project/x/y.cc.
info source prints No current source file.
dir prints Source directories searched: /usr/local/...project-src/out/Debug:$cdir:$cwd
I've also tried:
b ../../x/y.cc, I tried this since that's what the successful command outputs. Surprisingly, it didn't work which is really confusing me.
running gdb from the root directory and other directories.
doing cd to various directories after starting gdb
messing around with set substitute-path and adding directories using dir
I'm hoping the solution is simple, since breakpoints, and variable values, and everything else works, just not with absolute paths.
Also worth noting, once I've successfully added a breakpoint to a file (using the relative path), the other paths also work (both the absolute path and the ../../x/y.cc path).
Lastly, as to why I want absolute paths to work, I'm using CLion's remote-gdb configuration to connect to a gdbserver, and CLion is using absolute paths for whatever reason. Perhaps there is a way to configure CLion to just use the x/y.cc instead? I'm running the gdbserver with gdbserver :2000 out/Debug/build and configured CLion's target remote, symbol file, and sysroot. I've also tried setting the path mappings in CLion.
Edit, testing on a dummy HelloWorld project using g++ -g instead of ninja to build, I'm able to add breakpoints using absolute paths e.g. b /usr/local/...untitled/main.cpp:4. So it seems to be, for some reason, gdb supports full paths for the HelloWorld project built with g++, but not for the real project built with Ninja.
tldr, resolved using gdb --readnow.
Per the comment suggestion I began digging into my build config. 2 things I noticed:
1) The issue disappeared if I built with less debug details. But then I wouldn't be able to inspect expressions & variables. So I thought the issue may somehow related to gdb not having enough memory or cache to load all the debug info. This sounds reasonable since the project source code contains 100,000's of files.
2) As I mentioned earlier, I could add breakpoints using absolute paths after I had added a breakpoint using a relative path to the same file.
I learnt of the info, info set, and info sources commands. Although the outputs were the same between the light-weight debug build and the full debug built (step 1), I noticed that the output of info sources changed in step 2. Before I had added the breakpoint using a relative path, `info sources would list all source files under 'Source files for which symbols will be read in on demand'. But after adding a relative breakpoint, a few of the files (I think the files on the current frame) would be added to the loaded source files.
So I went looking for a way to tell gdb to load all the source files and discovered the gdb --readnow flag (or file <built-file> -readnow with 1 dash -) and though it prints a bunch of warning messages, it seems to resolve my issue.
That being said, I never discovered how to configure CLion to use the readnow flag. The newest EAP (2019.3) release supposedly supports configuring .gdbinit files individual per project, though I haven't tried this. I also don't know if readnow can be configured in a .gdbinit file since it's not a setting. I kind of circumvented the entire configuring CLion issue when I figured how to correctly configure custom build targets and applications in CLion during this investigation.
Edit,
Yet another workaround. If I cd into /usr/local/...project-src/out/Debug which contains the build file (as opposed to /usr/local/...project-src/), then absolute paths work even without readnow.

I'm getting the error "Please install clang or check configuration"

I'm on Ubuntu 17.10. I installed VSC and so far happier than when I was on Eclipse, but have hit a snag.
I'm trying to include a .h file, but getting an error WiFi.h not found. I've got the "includePath" set to include this file location, but still getting that error, along with the "Please install clang...". Well, I had already installed it (C/C++ Clang Command Adapter 0.2.2, and Clang-Format 1.6.1" via the extensions 'install'. I checked and I have a directory ""clang-format.executable": "~/.vscode/extensions/ms-vscode.cpptools-0.16.1/LLVM/bin/clang-format" on my system. So, the research I had done indicated I should either change the PATH, which I did, but that didn't solve it. I also edited the 'user settings', and set: ""clang-format.executable": "~/.vscode/extensions/ms-vscode.cpptools-0.16.1/LLVM/bin/clang-format", but I'm still getting the problem.
I don't understand why VSC isn't finding the include!
Any help would be appreciated. I've restarted VSC to make sure that wasn't an issue, and also did a 'app-clean', but still the error.
[edit-add]: the include is outside of the project I'm working on, but so are some of the other include .h files, so I don't think this makes any difference....
Thanks!

Getting vscode c++ plugin to locate protocol buffer headers

I am using bazel to build a c++ application that includes protocol buffers. This means that bazel runs the protocol buffer compiler as part of the build process, and squirrels the generated files away somewhere within the bazel output directory. VSCode is then unable to resolve these #include directives since they are not on any include path that vscode knows about.
But I'd rather not hardcode some frequently-changing bazel output directory in my vscode config. Does anyone have any suggested strategy for resolving this?
You can hardcode <bazel_workspace_path>\bazel-genfiles or <bazel_workspace_path>\bazel-bin as include directories.
bazel-bin and bazel-genfiles are junctions (~= directory symlinks) that point to the corresponding output directories. (They are called convenience symlinks. See the --symlink_prefix flag for more info.)

What causes the Eclipse CDT Unresolved inclusion: <iostream>

Just installed the latest Eclipse IDE and am following the included C++ User Guide right from 'Before you begin' section.
The simple application was successfully completed but once I got to the makefile project and the C++ file tutorials, I got the "Unresolved inclusion: <iostream>" error and a bunch of others related to "cout, cin, endl" because of it.
I followed the tutorials exactly as instructed and am not sure why this occurred. I have since corrected it by following this answer, but now want to know why this happens, especially since I am following the official tutorial and do I have to add the C++ include path for every project on Eclipse?
Related Question
That first error in the screenshot linked in the comments provides a clue to the problem.
If you go to the preference page mentioned in the error's "Location", you'll see that there is a field called "Command to get compiler specs" with the contents something like:
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
This is a command that Eclipse tries to run to get your compiler to output its built-in include paths and other similar information.
The fact that you're getting the error Program "-E" not found in PATH suggests that the variables ${COMMAND} and ${FLAGS} are evaluating to empty strings, so that the first actual token in the command (which the shell then tries to interpret as the program name) is -E.
I'm not sure why those variables are evaluating to empty, but you should be able to work around the issue by replacing ${COMMAND} with g++ (presumably g++ is in your PATH).
I've searched for a few hours and tried a lot solutions.
Envirment: windows, Eclipse IDE for C/C++ Developers
Version: Kepler Service Release 2
CDT: 8.3.0
Following steps works for me:
make sure the envirement is clear. => I suggest delete the eclipse and unzip it again from your orginal download. Remove all variable relatated to eclipse and MinGW you set to PATH of envirment variables.
make sure the workspace is clear. => Delete .metadata folder in your workspace folder.
use valid MinGW. => the one using download tool is slow and I'm not sure which one to select. I suggest download MinGWStudio which contains an unzip MinGW from http://vaultec.mbnet.fi/mingwstudio.php This is a IDE tool like eclipse contains a downloaded unzip MinGW. Make sure you download the one plus MinGW compiler which is about 20M. You can use this studio if you want or copy the MinGW folder to C:/ if you still prefer eclipse. Copy /MinGW inside /MinGWStudio to C:/.
close your eclipse and reopen it, create a new project, you should able to see MinGW section for new project option, and it will auto map g++, gcc and include files under C:/MinGW folder. Just make sure you copy MinGW folder from MinGWStudio to the root of C:/.
You will able to see your include after these steps. Build your project, everything should goes well even there may some warning hint.
Hope it helps.

How to resolve the Issue ID "toomanyconfigs" and "missingInclude:" in Cppcheck

I am working in an MFC application (around 2000 files) with Visual Studio 2008. I run Cppcheck for this application, but I found these two issues.
Issue toomanyconfigs: (Information -- The checking of the file will be interrupted because there are too many #ifdef configurations. Checking of all #ifdef configurations can be forced by --force command line option or from GUI preferences. However that may increase the checking time.)
Issue missingInclude: (Information -- Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project's include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find, use --check-config.)
My Cppcheck argument list is
cppcheck --quiet --verbose --check-config --force --enable=all --suppress=missingIncludeSystem --template=vs --std=c++11 $(ItemPath)
How can I resolve these issues?
I am a Cppcheck developer.
It is weird that you get the toomanyconfigs when you used --force. If you can create a file that reproduce the problem, please report it in our issue tracker. You can probably remove all code in the file and just keep the preprocessor directives.
You can specify include paths with -I.
Cppcheck-1.76 (next version) will be able to import Visual Studio 2010 and later solution files so you get includepaths automatically. Maybe that will be interesting to test.