Skip to content

Commit

Permalink
Extract stack-overflow output printing to module
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrimmel committed Sep 22, 2024
1 parent a424e76 commit a4fe601
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ fn main() {
Err(valgrind::Error::ValgrindFailure(output))
if output.contains("main thread stack using the --main-stacksize= flag") =>
{
let error = "Error".red().bold();
let info = "Info".cyan().bold();
eprintln!("{error:>12}: looks like the program overflowed its stack");
eprintln!("{info:>12}: valgrind says:");
output
.lines()
.for_each(|line| eprintln!(" {line}"));
output::display_stack_overflow(&output);
134 // default exit code for stack overflows
}
Err(e) => {
Expand Down
11 changes: 11 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,14 @@ fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) {
.iter()
.for_each(|frame| eprintln!(" at {frame}"));
}

/// Write out an error message for describing the stack overflow message.
pub fn display_stack_overflow(output: &str) {
let error = "Error".red().bold();
let info = "Info".cyan().bold();
eprintln!("{error:>12}: looks like the program overflowed its stack");
eprintln!("{info:>12}: valgrind says:");
output
.lines()
.for_each(|line| eprintln!(" {line}"));
}

0 comments on commit a4fe601

Please sign in to comment.