harikrishnan94 / cxx-compiler-explorer Goto Github PK
View Code? Open in Web Editor NEWVSCode extension that provides godbolt.org features inside vscode using compile commands
License: MIT License
VSCode extension that provides godbolt.org features inside vscode using compile commands
License: MIT License
Hi, I wanted to use your extension with C (not C++). I wrote a C hello world and saved it and when I run "C++ Compiler Explorer: Disassemble file" it says
Failed to show assembly: Error: ENOENT: no such file or directory, open '/Users/myuser/hello/compile_commands.json'
I ran the "C/C++: Edit Configurations (JSON)" editor command and I'm able to run and debug the code with F5 (with clang), so I would expect the extension to work as well, without extra configuration. I don't know what compile_commands.json is and it would save a lot of time if I didn't have to figure that out, since VS Code evidently already has enough information to compile my code.
In fact, ideally even generating .vscode/c_cpp_properties.json, etc. and even saving a C file at all shouldn't be necessary. I sometimes want to quickly write some simple C code to compare the generated instructions, just like with Compiler Explorer, I open it (i.e. install it in my browser) and it compiles int square(int num) { return num * num; }
, I don't have to configure stuff.
That functionality of jumping to the corresponding assembly and vice-versa is lost as soon as you switch to another .cpp file.
Going back to the original one does not bring it back.
See referenced commit.
First I tried more sophisticated splitting in CompileCommand.process() with /[^"\s]*("(\\"|[^"])+")?/g
but in the end it's just not feasible. Just let the shell do its job.
The merge to integrate cmake tools at
Is a really cool addition that I (as a CMake user) desperately want.
however, it doesn't work.
The reason it doesn't work is because
tries to load the empty file, but fails when the file isn't there. This SHOULD trigger an exception which is caught by the except block, initializing the map with an empty map in the exception handler case...but for some reason its not. The exception passes through to the VsCode editor. Probably, ENOENT exceptions inside await blocks aren't caught by exception handlers? Or something? It seems unclear.
This issue means I can't use the CMake support.
It seems that currently the directory
property of the compilation database isn't considered when compiling the source file. At least I cannot find any place in the extensions code where it is used (please correct me if I'm wrong). The problem is, that my compilation database consists of relative include paths and assumes the command is executed in the specified working directory, as it should be. Therefore the compiler isn't able to find the header files.
Currently the extension can only find files in the internal database structure if the workspace path exactly matches the path as specified in the compilation database.
Expectation: It should also try to resolve paths relative to the working directory as specified in the compilation database.
Issue Type: Bug
I'm trying to use this with an out-of-tree build over RemoteSSH extension. I'm getting errors about not being able to find the files in "compile_commands.json". For example:
file:///home/anatoly/playground/memfd_fallocate/sparsetest.c is not found in compile_commands.json
Presumably this happens either because the extension is either not trying to get canonical path to files in the .json files, or because it doesn't understand how to work over RemoteSSH. Either way, not working...
Extension version: 0.2.0
VS Code version: Code - Insiders 1.39.0-insider (695ee74864ef93d10f5de0861cb66af190e76211, 2019-10-02T08:56:48.092Z)
OS version: Windows_NT x64 10.0.17763
Remote OS version: Linux x64 4.15.0-65-generic
the output from the extension is: g++: error: : No such file or directory. Feel free to ask for anything.
Suppose using the following compile command:
[
{
"directory": "/Users/hero/cpp_test/build",
"command": "/usr/bin/c++ -DSOME_VAR=\\\"\\\" -std=gnu++17 -o CMakeFiles/cpp_test.dir/main.cpp.o -c /Users/hero/cpp_test/main.cpp",
"file": "/Users/hero/cpp_test/main.cpp"
}
]
The intention is to pass the double quotes to SOME_VAR
. The current parser implementation does not recognize this pattern which causes the actual compile command to fail because the parser yields just two arguments.
cxx-compiler-explorer/src/compdb.ts
Line 321 in 08ecdb9
Because the last quoteChar
is not a double quote the whole remaining string is handled as one argument.
I will prepare a PR. But maybe there is already an argument parsing library available?
See referenced commit.
See referenced commit.
Maybe the input box could be populated with a configurable string by default.
Excellent improvements to the readability of the assembly file!
I had to change the code back to this arg format to make this version work on MacOS with clang.
getDisassembleCommand(outFile) {
// remove -o part
let fixedCmd = this._command.replace(/[\s]-o\s[^"\s]+/, '');
// now add necessary options to generate clean assembly
// return fixedCmd + ' -g1 -S -masm=intel -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-dwarf2-cfi-asm -o "' + outFile + '"';
let args = [
this.command,
"-g1",
"-S",
"-masm=intel",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-fno-dwarf2-cfi-asm",
"-o",
outFile
].concat(this.args);
return this.getCommand(args);
}
I tried your extension on a simple PlatformIO example project (using a compile_commands.json generated from pio run --verbose
).
The 'Disassemble with extra args' command is called cause it opens the input prompt. But after that nothing happens and there is no entry in the Developer Tools Console either.
I receive the following error when I try to run it:
Failed to show assembly: Unable to resolve filesystem provider with relative file path 'f:\project\build/compile_commands.json'
the variable compilerexplorer.compilationDirectory
is set to ${workspaceFolder}/build
Compilation fails on ARM based systems, not to mention that some people don't like the Intel syntax.
Currently I am facing the following issue. If my compile_commands.json
contains a compiler invocation like /usr/bin/c++
then this causes the extension to hang. There is no progress, it simply displays Compilation in progress
. It turns out the issue cannot be observed anymore when we add c++
to the following replace
statements. Actually it should use the system default c++filt
.
cxx-compiler-explorer/src/compdb.ts
Line 278 in 08ecdb9
I have also tried it with an older version (0.7.0), but the issue is the same. Of course this can easily be fixed, but I guess it would be better to make it more robust. Tell me what you think about this and I will try to prepare a PR. ๐
If the property command
is not set in the compilation database, the extension throws Command undefined ...
and doesn't compile the current file. The specification only requires that one of command
or arguments
should be set. The following line causes the trouble:
cxx-compiler-explorer/src/compdb.ts
Line 271 in 4dd31d6
The json file seems to be loaded directly at extension activation when running the disasm command for the first time, so if there is an error like missing directory element the extension fails to load and you just get a puzzling command not found error.
Later, even if you fix the json you have to restart VSCode.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.