-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Show function names in explore tool instead of only function indices #8639
Show function names in explore tool instead of only function indices #8639
Conversation
9ef98c3
to
deccfe3
Compare
Very nice! This can be further improved by demangling the function names first. For some example code that does that, see: wasmtime/crates/wasmtime/src/runtime/profiling.rs Lines 194 to 200 in 54e53cc
I don't think we need to be nearly so careful about sanitizing function names in this setting. These strings are first serialized to JSON, and that should ensure that any string we provide is valid JSON. The JSON string is then used in a As a result I think we should just give the user whatever they provided, preferably after demangling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One nitpick below before we merge this.
Agreed demangling would be great -- also fine with deferring that to a follow up PR. |
Ooh, the pop-up is a nice touch. There's a lot more that could be done with I'd be happy to review this next week, or just as happy if you want to approve it @fitzgen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Really excited to get this, and your other PR, in wasmtime explore
.
I have a few comments and suggestions below that we should address before merging this however. I'll also hold off on reviewing the other PR until after this one merges.
Let me know if anything I said isn't clear or something like that. Thanks again!
crates/explorer/src/index.js
Outdated
@@ -7,27 +7,12 @@ class State { | |||
} | |||
} | |||
|
|||
const state = window.STATE = new State(window.WAT, window.ASM); | |||
const state = (window.STATE = new State(window.WAT, window.ASM)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revert this change; it just introduces unnecessary parens.
crates/explorer/src/index.js
Outdated
@@ -36,7 +21,7 @@ const nextHue = (function () { | |||
return () => { | |||
return hues[++i % hues.length]; | |||
}; | |||
}()); | |||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Let's not change code style when making unrelated changes.
crates/explorer/src/index.js
Outdated
@@ -45,7 +30,7 @@ const offsetToHue = new Map(); | |||
|
|||
// Get the hue for the given offset, or assign it a new one if it doesn't have | |||
// one already. | |||
const hueForOffset = offset => { | |||
const hueForOffset = (offset) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
crates/explorer/src/index.js
Outdated
@@ -57,7 +42,7 @@ const hueForOffset = offset => { | |||
|
|||
// Get the hue for the given offset, only if the offset has already been | |||
// assigned a hue. | |||
const existingHueForOffset = offset => { | |||
const existingHueForOffset = (offset) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
crates/explorer/src/index.js
Outdated
funcHeader.textContent = `Disassembly of function <${func.demangled_name}>:`; | ||
funcHeader.title = func.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, this is the only non-stylistic change to the whole JS file? Can we remove all the other changes to this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. It was the auto-formatting tool that my editor uses. I'll have to force-push to fix this easily.
crates/explorer/src/lib.rs
Outdated
let demangled_name = match name.splitn(2, "::").nth(1) { | ||
Some(name) => { | ||
let mut demangled = String::new(); | ||
demangle_function_name(&mut demangled, name) | ||
.map_or_else(|_| format!("demangle-error::{}", name), |_| demangled) | ||
} | ||
None => name.to_string(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to let demangled_name
be an Option<String>
rather than making a clone of name
and then have the JS choose the demangled name when available and fall back to the plain name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
Map the iterator returned by Module::function_locations() to another one that returns a 3-tuple containing the function name, the offset, and the length of each function defined in this particular module.
4304bb3
to
c18e755
Compare
Alright, force-pushed (sorry!) due to the formatting changes, but it should be a whole lot clearer now. I'll rebase the other PR once this one lands. |
c18e755
to
277f57c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks just about ready to merge, couple tiny things still to go first.
Alright, @fitzgen, pushed a new revision that should address your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! And thanks for your patience with review :)
Another one in the "let's make debugging a bit easier": show function names in the "explore" tool. (There's a bit of code repetition here to clean up the names, but it's slightly different when we're considering HTML output, so I think that's OK.)
Here's how it works on my machine: