From cc35b5e7246672b0768a14d4e004c76026dcf84c Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 12 Sep 2017 08:59:35 -0700 Subject: [PATCH] Flush the debug trace file after each dbg!(). When debugging code built with panic=about, the debug trace buffer is not flushed on a panic and important messages are lost. This does slow down debug tracing a bit, but this is still better than unbuffered or line buffered I/O since the dbg!() macro can write out many lines like a whole function. --- lib/cretonne/src/dbg.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index 0ac03f4c4f..9bd5500e3c 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -63,7 +63,11 @@ thread_local! { /// /// This is for use by the `dbg!` macro. pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { - WRITER.with(|rc| writeln!(*rc.borrow_mut(), "{}", args)) + WRITER.with(|rc| { + let mut w = rc.borrow_mut(); + writeln!(*w, "{}", args)?; + w.flush() + }) } /// Open the tracing file for the current thread.