-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing c++ bugs in javascript - feature request #32591
Comments
What exactly is the feature you are asking for? |
To be able to use the chrome debugger and profiler in ansi c++ development, and according to debug info produced by Emscripten any changes being made in javascript code Visual studio code applies immediately on the c++ source. |
I still don't understand. Since Emscripten converts C++ into JavaScript, you can just use the JavaScript debuggers "chrome-debug" or "node-debug" to debug the generated JavaScript. If Emscripten generates sourcemaps that map the generated JavaScript back to the original C++ source, the JavaScript debuggers will pick up those SourceMaps and VS Code should show the C++ source. Have you tried this? |
There is a manual debugging feature, which puts in javascript comments where the c++ code is. Emscripten would be responsible only the translation to javascript. As my understanding is that code with some flags of the Emscripten compiler, even if it's staticly typed and using asm. js, can be partly human readable code. The Visual Code editor respinsibility would be to find that debug informations in javascript and index with the underlying c++ source. So you have a chrome debugger plugin and javascript to c++ parser. Emscripten is helping the editor on the indexing, but it cannot translate back any code to c++. As the Emscripten is making a conversion through llvm, there is no way back to translate back c++, but through what debugging information puts to the file, it might be tracked back to the original one, what some programmers doing anyway. The feature request might be something which is a new path. It'a simply not working with new projects, but there are plenty of free source old one. |
Before using the clumsy "manual debugging feature" you should try the "sourcemap" approach. From the emscripten doc:
These source maps are understood by VS Code's JavaScript debuggers too. |
I'm not sure about your approach. Intersting point, but i have no idea, how to achieve it. I'm not sure that Emscripten generates any source map. I think it is generating line numbers and file names in the javascript comment, and i need to manually traxk back opening the file where is the c++ line exactly, which is tedious. |
I will try that, thanks. |
Use of source maps is not "my" approach. It is Emscripten's recommended way to debug C/C++ source code in your browser’s debugger on Firefox, Chrome or Safari! Just pass |
Yes, but what i would have liked, if i would change something in javascript code it would reflect back automatically to c++. So i have confidence that when i build the c++ source, it will work. |
So i'm not talking debugging, i'm talking to change debug profile in javascript, build in c++, as the c++ code automatically changed by vs editor. |
That would require a "reverse compiler" that translates JavaScript into C++ (which is very hard if not impossible). But anyway, it is completely outside of VS Code's scope. We are not doing transpilers. I suggest to create a feature request against Emscripten. They know how to translate C++ to JavaScript, so they are in the best position to do the reverse translation. |
I accept your answer, but through source map info, there is no way to find back the original c++ code, what the debugger does anyway and from javascript source code to c++ source code make changes on the file? So no compiler. I thought that when i open a c++ project in Visual studio code, it's indexing, not just formatting c++/javascript files, so it's aware of the structure of class and functions, and can match lines, like an svn editor. It was just an idea, thanks for your effort. |
I just tried to debug an Emscripten translated hello.c with VS Code: I compiled with:
The launch config for this looks like this: {
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"protocol": "inspector",
"program": "${workspaceRoot}/a.out.js"
}
]
} In order to set breakpoints in *.c files, I had to enable a special VS Code option for the workspace: The source map looks like this: {
"version": 3,
"sources": [
"tests/hello_world.c"
],
"names": [
],
"mappings": ";;;;;;;;;;;;;AAGA;AAAA;;;;AACA;AAAA;AAAA;AADA;AAAA;AAAA;;AAGA",
"file": "a.out.js",
"sourcesContent": [
"#include <stdio.h>\n\nint main() {\n for (int i; i < 100; i++) {\n printf(\"hello, world: %d\\n\", i);\n }\n return 0;\n}\n"
]
} As you can see the hello_world.c file is inlined in the source map. |
You wrote:
VS Code has no builtin C/C++ support. You need to install a C/C++ extension before VS Code understands C/C++. But even a C/C++ extension is of no help if you transpile C/C++ to JavaScript and run it in a node.js runtime. Node.js has no idea that the JavaScript comes from C/C++. It runs it as JavaScript. However, by using source maps VS Code at least understands how to map JavaScript source lines back to C/C++ source lines. But of course this does not allow allow to transpile modified JavaScript back to C/C++. |
Emscripten is a very good project to port c/c++ projects to javascript,
there is a feature called Manual print debugging, which prints out the line number of the given c++ code in the ported javascript code.
http://kripken.github.io/emscripten-site/docs/porting/Debugging.html
My feature request sounds crazy, but there is a valid reason.
Because of emscripten you can debug ported javascript code from c++,
what i would like to achieve, to make changes in javascript and automatically converted back to c++.
I think that functionality can empower the free source world.
Especially when you have a badly written aging project like ffmpeg and you would like to find bugs in it,
so you can use emscripten debug it in the browser and convert back the changes into c++.
So any freesource project which misses manpower can get free hands quickly as javascript is a well known and easy to use language for everyone.
There are special cases, but to check and validate an encoder algorithm make it more efficient programatically can be a valid reason to use that technic. If you would be able to read the algorithm in a better way and debug in a better way, you can get an idea to write far better algorithm than the heavily patented mpeg h264 and aac. (I think it's a common problem in every browsers nowadays)
Not to mention c++ projects, which has been ended because lots of resources was needed to fix bugs further. (Osmosis is a good example on open street map - everybody is using it as a google alternative, but the osmisis itself is in 0.55 version, and finished the development after 2016)
The text was updated successfully, but these errors were encountered: