microsoft/vscode-recipes

Debug Emscripten translated C/C++ with source maps

weinand opened this issue · 7 comments

I tried to help a user debugging Emscripten translated C/C++ to JavaScript:

2017-08-18_17-21-59

I compiled with:

./emcc -g4 tests/hello_world.c

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 (without having a C/C++ extension installed), I had to enable a special VS Code option for the workspace:

2017-08-18_17-32-35

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.

Do you mean that this worked for you. If yes, make a vs code recipe and share it with others.

Does this work with the cpptools extension installed?

Can not debug for me on VS Code
Version: 1.44.2
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T17:07:18.473Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0

@hkleynhans I see no reason why this should not work if you have cpptools installed. However, you will have to know what you are doing if you want to translate this with emscripten and debug the result. cpptools are out of the loop here...

@kinglezhuang "Can not debug for me on VS Code" is not a helpful bug descrption.
Please explain in more detail what you are trying to do and what problems you are seeing.
And provide reproducible steps.

js-debug needs to support this first. WebAssembly is no longer 'hacked into' the CDP protocol like before, duplicates microsoft/vscode-js-debug#853

WebAssembly is no longer 'hacked into' the CDP protocol like before, duplicates microsoft/vscode-js-debug#853