-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Add --enable-source-map support for WebAssembly module #46873
Comments
Initial support for JS source maps was added in #29564, but as far as I can tell the To build a wasm file with source map support in emscripten you can do Here is an example that I used to test:
|
@bcoe who originally added the --enable-source-maps option |
I believe @bcoe isn't actively involved anymore. Pull request welcome. Node needs to call |
If I understand correctly we are supposed to make a call to Lines 1270 to 1279 in f94ef7c
|
That's for the |
I tried something like this diff --git a/src/api/environment.cc b/src/api/environment.cc
index f56ee8d12b..c73a47a35a 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -260,6 +260,11 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
}
}
+Local<String> WASMLoadSourceMapCb(Isolate* isolate, const char* path) {
+ std::cout << "WASMLoadSourceMapCb" << std::endl;
+ return String::Empty(isolate);
+}
+
void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
isolate->SetMicrotasksPolicy(s.policy);
@@ -267,6 +272,10 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback;
isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb);
+ auto* wasm_load_source_map_callback = s.wasm_load_source_map_callback ?
+ s.wasm_load_source_map_callback : WASMLoadSourceMapCb;
+ isolate->SetWasmLoadSourceMapCallback(wasm_load_source_map_callback);
+
auto* modify_code_generation_from_strings_callback =
ModifyCodeGenerationFromStrings;
if (s.modify_code_generation_from_strings_callback != nullptr) {
diff --git a/src/node.h b/src/node.h
index fc2531f867..3e8003b820 100644
--- a/src/node.h
+++ b/src/node.h
@@ -483,6 +483,7 @@ struct IsolateSettings {
allow_wasm_code_generation_callback = nullptr;
v8::ModifyCodeGenerationFromStringsCallback2
modify_code_generation_from_strings_callback = nullptr;
+ v8::WasmLoadSourceMapCallback wasm_load_source_map_callback = nullptr;
};
// Represents a startup snapshot blob, e.g. created by passing just to test, it seems the callback is never called, I tried searching for any docs on |
On closer inspection it looks like V8 currently supports source maps only for profiling, not for exception stack traces. Your change would improve the usability of e.g. the |
I tried experimenting with loading source maps for profiling here debadree25@60ead86 it seems the callbacks are correctly called and loaded but I don't seem to find much of a difference between flamegraphs created when profiling because I am able to see the C function in both of them so quite confusing 😅 |
WASM files can contain DWARF debug data. V8 uses it if there's no sourcemap available. |
Understood, thank you so much for explaining it seems emscripten automatically adds the DWARF info when building with |
Does it? I thought all the DWARF parsing was in the chrome dev tools extension. I am not aware of any DWARF parser in v8 itself. Can you point to it? |
Yeah, I take that back. V8 recognizes the .debug_info section but it doesn't do much with it. I was thinking of the unwind info (DWARF subset) that's written to |
I think v8 only reads the Adding basic source map support would give us filenames in line numbers in node backtraces which would be really useful in my daily work. |
FWIW heres what I tried and the output Here's the C code i used: #include <stdio.h>
int callme(int a, int b) {
// run a random loop upto 1 million
for (int i = 0; i < 1000000; i++) {
a = a + b;
}
return a;
}
int main() {
printf("hello, world!\n");
int i = callme(3, 2);
printf("i = %d\n", i);
return 0;
} Building from main branch of node: ./node-main --prof a.out.js
./node-main --prof-process --preprocess -j isolate-0x7f79eb816000-60805-v8.log > flames1.json Output from flamebearer Building from debadree25@60ead86 ./node-prof --prof a.out.js
./node-prof --prof-process --preprocess -j isolate-0x7f8513016000-60708-v8.log > flames2.json Note that |
It looks like you have function name in formation there in both cases, but filename and line numbers are not there (like they are for the JS code). Source map would would provide those IIUC. |
Ahh I see, then maybe |
Is your Can you confirm that your wasm file has that section? (Using |
Yes the callback is indeed called, I added some logs and checked diff --git a/src/api/environment.cc b/src/api/environment.cc
index d9b102d9ec..793ce2975d 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -262,9 +262,11 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
}
Local<String> WASMLoadSourceMapCb(Isolate* isolate, const char* path) {
+ std::cout << "callback is called with path: " << path << std::endl;
std::string contents;
int r = ReadFileSync(&contents, path);
if (r == 0) {
+ std::cout << "file was read successfully: " << contents.length() << std::endl;
return String::NewFromUtf8(isolate, contents.c_str()).ToLocalChecked();
}
return String::Empty(isolate); callback is called with path: a.out.wasm.map
file was read successfully: 8799
hello, world!
i = 2000003 |
I wondering should we consider |
Was reading through the v8 code surrounding this found the following comment node/deps/v8/src/wasm/wasm-module-sourcemap.cc Lines 144 to 145 in cce5a8c
|
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Even if the column number is always zero I would still expect to see filename and line number. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Has this feature been implemented? |
What is the problem this feature will solve?
I will allow developers to get better backtrace information from wasm module that are built with source maps.
What is the feature you are proposing to solve the problem?
Reading of the sourceMappingURL section from any WebAssembly modules that get loaded.
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: