Skip to content
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

No dwarf #51

Merged
merged 5 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ Released YYYY-MM-DD.

--------------------------------------------------------------------------------

## 0.2.0

Released 2019-02-14.

### Added

* Added configuration options for controlling emission of the DWARF and name
custom sections.

### Changed

* Changed the synthetic naming option from "generate_names" to
"generate_synthetic_names_for_anonymous_items" to more accurately reflect what
it does.

--------------------------------------------------------------------------------

## 0.1.0

Released 2019-02-12.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Nick Fitzgerald <[email protected]>"]
edition = "2018"
name = "walrus"
version = "0.1.0"
version = "0.2.0"
license = "MIT/Apache-2.0"
readme = "README.md"
categories = ["wasm"]
Expand All @@ -19,7 +19,7 @@ id-arena = { version = "2.2.0", features = ['rayon'] }
leb128 = "0.2.3"
log = "0.4"
rayon = "1.0.3"
walrus-macro = { path = './crates/macro', version = '=0.1.0' }
walrus-macro = { path = './crates/macro', version = '=0.2.0' }
wasmparser = "0.28"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Nick Fitzgerald <[email protected]>"]
edition = "2018"
name = "walrus-macro"
version = "0.1.0"
version = "0.2.0"
license = "MIT/Apache-2.0"
categories = ["wasm"]
repository = "https://github.com/rustwasm/walrus/tree/crates/macro"
Expand Down
47 changes: 41 additions & 6 deletions src/module/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,58 @@ use crate::module::Module;
/// Configuration for a `Module` which currently affects parsing.
#[derive(Clone, Debug, Default)]
pub struct ModuleConfig {
pub(crate) generate_names: bool,
pub(crate) generate_dwarf: bool,
pub(crate) generate_name_section: bool,
pub(crate) generate_synthetic_names_for_anonymous_items: bool,
pub(crate) skip_strict_validate: bool,
}

impl ModuleConfig {
/// Creates a fresh new configuration with default settings.
pub fn new() -> ModuleConfig {
ModuleConfig::default()
ModuleConfig {
generate_dwarf: false,
generate_name_section: true,
generate_synthetic_names_for_anonymous_items: false,
skip_strict_validate: false,
}
}

/// Sets a flag to whether debugging names are generated for
/// locals/functions/etc when parsing and running passes for this module.
/// Sets a flag to whether DWARF debug sections are generated for this
/// module.
///
/// By default this flag is `false`. Note that any emitted DWARF is
/// currently wildly incorrect and buggy, and is also larger than the wasm
/// itself!
pub fn generate_dwarf(&mut self, generate: bool) -> &mut ModuleConfig {
self.generate_dwarf = generate;
self
}

/// Sets a flag to whether the custom "name" section is generated for this
/// module.
///
/// The "name" section contains symbol names for the module, functions, and
/// locals. When enabled, stack traces will use these names, instead of
/// `wasm-function[123]`.
///
/// By default this flag is `true`.
pub fn generate_name_section(&mut self, generate: bool) -> &mut ModuleConfig {
self.generate_name_section = generate;
self
}

/// Sets a flag to whether synthetic debugging names are generated for
/// anonymous locals/functions/etc when parsing and running passes for this
/// module.
///
/// By default this flag is `false`, and it will generate quite a few names
/// if enabled!
pub fn generate_names(&mut self, generate: bool) -> &mut ModuleConfig {
self.generate_names = generate;
pub fn generate_synthetic_names_for_anonymous_items(
&mut self,
generate: bool,
) -> &mut ModuleConfig {
self.generate_synthetic_names_for_anonymous_items = generate;
self
}

Expand Down
6 changes: 3 additions & 3 deletions src/module/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl Module {
let id = self.funcs.arena.next_id();
self.funcs.arena.alloc(Function::new_uninitialized(id, ty));
let idx = ids.push_func(id);
if self.config.generate_names {
if self.config.generate_synthetic_names_for_anonymous_items {
self.funcs.get_mut(id).name = Some(format!("f{}", idx));
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ impl Module {
let local_id = self.locals.add(*ty);
let idx = indices.push_local(id, local_id);
args.push(local_id);
if self.config.generate_names {
if self.config.generate_synthetic_names_for_anonymous_items {
let name = format!("arg{}", idx);
self.locals.get_mut(local_id).name = Some(name);
}
Expand All @@ -349,7 +349,7 @@ impl Module {
for _ in 0..count {
let local_id = self.locals.add(ty);
let idx = indices.push_local(id, local_id);
if self.config.generate_names {
if self.config.generate_synthetic_names_for_anonymous_items {
let name = format!("l{}", idx);
self.locals.get_mut(local_id).name = Some(name);
}
Expand Down
14 changes: 12 additions & 2 deletions src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,17 @@ impl Module {
self.funcs.emit(&mut cx);
self.data.emit(&mut cx);

emit_name_section(&mut cx);
if self.config.generate_name_section {
emit_name_section(&mut cx);
}

self.producers.emit(&mut cx);
for section in self.custom.iter() {
if !self.config.generate_dwarf && section.name.starts_with(".debug") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should also be skipped when parsing to avoid keeping the dwarf sections in memory?

log::debug!("skipping DWARF custom section {}", section.name);
continue;
}

log::debug!("emitting custom section {}", section.name);
cx.custom_section(&section.name).encoder.raw(&section.value);
}
Expand Down Expand Up @@ -303,7 +311,9 @@ impl Module {
// names for locals if they aren't specified, so
// just ignore empty names which would in theory
// make debugging a bit harder.
if self.config.generate_names && naming.name.is_empty() {
if self.config.generate_synthetic_names_for_anonymous_items
&& naming.name.is_empty()
{
continue;
}
let id = indices.get_local(func_id, naming.index)?;
Expand Down