-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1775 from multiversx/wasm-extractor-fix
wasm extractor - fix report parameters
- Loading branch information
Showing
8 changed files
with
444 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::fmt::Display; | ||
|
||
use wasmparser::DataSectionReader; | ||
const PANIC_WITH_MESSAGE: &[u8; 16] = b"panic occurred: "; | ||
const PANIC_WITHOUT_MESSAGE: &[u8; 14] = b"panic occurred"; | ||
|
||
#[derive(Default, PartialEq, Clone)] | ||
pub enum PanicReport { | ||
#[default] | ||
None, | ||
WithoutMessage, | ||
WithMessage, | ||
} | ||
|
||
impl Display for PanicReport { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let panic_status = match self { | ||
PanicReport::None => "None", | ||
PanicReport::WithoutMessage => "without message", | ||
PanicReport::WithMessage => "with message", | ||
}; | ||
write!(f, "{}", panic_status) | ||
} | ||
} | ||
|
||
impl PanicReport { | ||
pub fn data_section_severity(&self, data_section: DataSectionReader) -> Self { | ||
if is_panic_with_message_triggered(data_section.clone()) { | ||
return Self::WithMessage; | ||
} | ||
|
||
if is_panic_without_message_triggered(data_section) { | ||
println!("here"); | ||
return Self::WithoutMessage; | ||
} | ||
|
||
Self::None | ||
} | ||
|
||
pub fn max_severity(&mut self, data_section: DataSectionReader) { | ||
if *self == PanicReport::WithMessage { | ||
return; | ||
} | ||
|
||
let panic_report = self.data_section_severity(data_section); | ||
if panic_report == PanicReport::None { | ||
return; | ||
} | ||
|
||
*self = panic_report; | ||
} | ||
} | ||
|
||
fn is_panic_with_message_triggered(data_section: DataSectionReader) -> bool { | ||
for data_fragment in data_section.into_iter().flatten() { | ||
if data_fragment | ||
.data | ||
.windows(PANIC_WITH_MESSAGE.len()) | ||
.any(|data| data == PANIC_WITH_MESSAGE) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
false | ||
} | ||
|
||
fn is_panic_without_message_triggered(data_section: DataSectionReader) -> bool { | ||
for data_fragment in data_section.into_iter().flatten() { | ||
if data_fragment | ||
.data | ||
.windows(PANIC_WITHOUT_MESSAGE.len()) | ||
.any(|data| data == PANIC_WITHOUT_MESSAGE) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
pub const WITH_MESSAGE: &str = "with message"; | ||
pub const WITHOUT_MESSAGE: &str = "without message"; | ||
use super::panic_report::PanicReport; | ||
|
||
pub struct ReportCreator { | ||
pub path: String, | ||
pub has_allocator: bool, | ||
pub has_panic: String, | ||
pub has_panic: PanicReport, | ||
} | ||
|
||
impl ReportCreator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.