From ab06897871eb96633ca30a946757500230b2e969 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 11:25:17 -0400 Subject: [PATCH 01/11] Add regression test for SIGPIPE on macOS --- tests/smoke.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/smoke.rs b/tests/smoke.rs index 7f90d2947..a72bc511e 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -248,3 +248,27 @@ fn is_serde() { is_serialize::(); is_deserialize::(); } + +// Copied from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs +#[test] +#[cfg(target_os = "macos")] +fn simple_test() { + use std::{env, panic, fs}; + + // Find our dSYM and replace the DWARF binary with an empty file + let mut dsym_path = env::current_exe().unwrap(); + let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); + assert!(dsym_path.pop()); // Pop executable + dsym_path.push(format!("{}.dSYM/Contents/Resources/DWARF/{0}", executable_name)); + { + let file = fs::OpenOptions::new().read(false).write(true).truncate(true).create(false) + .open(&dsym_path).unwrap(); + } + + env::set_var("RUST_BACKTRACE", "1"); + + // We don't need to die of panic, just trigger a backtrace + let _ = panic::catch_unwind(|| { + assert!(false); + }); +} From b585df804fed5b2070669e3110561adc4a403923 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 13:16:59 -0400 Subject: [PATCH 02/11] Disable `mmap` on macOS See https://github.com/rust-lang/rust/pull/45866 for more details --- crates/backtrace-sys/build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index 564f23a91..6c500536d 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -36,7 +36,9 @@ fn main() { // `mmap` does not exist on Windows, so we use // the less efficient `read`-based code. - if target.contains("windows") { + // Using `mmap` on macOS causes weird isseus - see + // https://github.com/rust-lang/rust/pull/45866 + if target.contains("windows") || target.contains("macos") { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); From ed000ab074c70bb1cf4fa60026b6d0e1e7ffa915 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 13:19:29 -0400 Subject: [PATCH 03/11] Run `cargo fmt` --- tests/smoke.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/smoke.rs b/tests/smoke.rs index a72bc511e..3e758f300 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -253,16 +253,24 @@ fn is_serde() { #[test] #[cfg(target_os = "macos")] fn simple_test() { - use std::{env, panic, fs}; + use std::{env, fs, panic}; // Find our dSYM and replace the DWARF binary with an empty file let mut dsym_path = env::current_exe().unwrap(); let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); assert!(dsym_path.pop()); // Pop executable - dsym_path.push(format!("{}.dSYM/Contents/Resources/DWARF/{0}", executable_name)); + dsym_path.push(format!( + "{}.dSYM/Contents/Resources/DWARF/{0}", + executable_name + )); { - let file = fs::OpenOptions::new().read(false).write(true).truncate(true).create(false) - .open(&dsym_path).unwrap(); + let file = fs::OpenOptions::new() + .read(false) + .write(true) + .truncate(true) + .create(false) + .open(&dsym_path) + .unwrap(); } env::set_var("RUST_BACKTRACE", "1"); From 23328fecf7a3e9657a3c4b9fa75c8caecfdc38c6 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 13:28:36 -0400 Subject: [PATCH 04/11] Remove unused variable name --- tests/smoke.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke.rs b/tests/smoke.rs index 3e758f300..b2d55af68 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -264,7 +264,7 @@ fn simple_test() { executable_name )); { - let file = fs::OpenOptions::new() + let _ = fs::OpenOptions::new() .read(false) .write(true) .truncate(true) From 86e4a37cd5a26336309a584b33c6db02b6e6c5e1 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 14:24:05 -0400 Subject: [PATCH 05/11] s/macos/darwin/ --- crates/backtrace-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index 6c500536d..e96311356 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -38,7 +38,7 @@ fn main() { // the less efficient `read`-based code. // Using `mmap` on macOS causes weird isseus - see // https://github.com/rust-lang/rust/pull/45866 - if target.contains("windows") || target.contains("macos") { + if target.contains("windows") || target.contains("darwin") { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); From 99a78f42ed37ee6f599e55c13e34bedafdd0fa12 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 9 Mar 2020 14:31:16 -0400 Subject: [PATCH 06/11] Move macOS test to its own file --- tests/macos_frames.rs | 33 +++++++++++++++++++++++++++++++++ tests/smoke.rs | 32 -------------------------------- 2 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 tests/macos_frames.rs diff --git a/tests/macos_frames.rs b/tests/macos_frames.rs new file mode 100644 index 000000000..0b9f147aa --- /dev/null +++ b/tests/macos_frames.rs @@ -0,0 +1,33 @@ +// Copied from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs +// This needs to go in its own file, since it modifies the dSYM +// for the entire test +#[test] +#[cfg(target_os = "macos")] +fn simple_test() { + use std::{env, fs, panic}; + + // Find our dSYM and replace the DWARF binary with an empty file + let mut dsym_path = env::current_exe().unwrap(); + let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); + assert!(dsym_path.pop()); // Pop executable + dsym_path.push(format!( + "{}.dSYM/Contents/Resources/DWARF/{0}", + executable_name + )); + { + let _ = fs::OpenOptions::new() + .read(false) + .write(true) + .truncate(true) + .create(false) + .open(&dsym_path) + .unwrap(); + } + + env::set_var("RUST_BACKTRACE", "1"); + + // We don't need to die of panic, just trigger a backtrace + let _ = panic::catch_unwind(|| { + assert!(false); + }); +} diff --git a/tests/smoke.rs b/tests/smoke.rs index b2d55af68..7f90d2947 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -248,35 +248,3 @@ fn is_serde() { is_serialize::(); is_deserialize::(); } - -// Copied from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs -#[test] -#[cfg(target_os = "macos")] -fn simple_test() { - use std::{env, fs, panic}; - - // Find our dSYM and replace the DWARF binary with an empty file - let mut dsym_path = env::current_exe().unwrap(); - let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); - assert!(dsym_path.pop()); // Pop executable - dsym_path.push(format!( - "{}.dSYM/Contents/Resources/DWARF/{0}", - executable_name - )); - { - let _ = fs::OpenOptions::new() - .read(false) - .write(true) - .truncate(true) - .create(false) - .open(&dsym_path) - .unwrap(); - } - - env::set_var("RUST_BACKTRACE", "1"); - - // We don't need to die of panic, just trigger a backtrace - let _ = panic::catch_unwind(|| { - assert!(false); - }); -} From 997edabcc561440f163d531b200518ff6469688a Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 10 Mar 2020 12:10:38 -0400 Subject: [PATCH 07/11] Move macOS dSYM test to its own directory --- tests/macos_frames.rs | 33 --------------------------------- tests/macos_frames/main.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 tests/macos_frames.rs create mode 100644 tests/macos_frames/main.rs diff --git a/tests/macos_frames.rs b/tests/macos_frames.rs deleted file mode 100644 index 0b9f147aa..000000000 --- a/tests/macos_frames.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copied from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs -// This needs to go in its own file, since it modifies the dSYM -// for the entire test -#[test] -#[cfg(target_os = "macos")] -fn simple_test() { - use std::{env, fs, panic}; - - // Find our dSYM and replace the DWARF binary with an empty file - let mut dsym_path = env::current_exe().unwrap(); - let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); - assert!(dsym_path.pop()); // Pop executable - dsym_path.push(format!( - "{}.dSYM/Contents/Resources/DWARF/{0}", - executable_name - )); - { - let _ = fs::OpenOptions::new() - .read(false) - .write(true) - .truncate(true) - .create(false) - .open(&dsym_path) - .unwrap(); - } - - env::set_var("RUST_BACKTRACE", "1"); - - // We don't need to die of panic, just trigger a backtrace - let _ = panic::catch_unwind(|| { - assert!(false); - }); -} diff --git a/tests/macos_frames/main.rs b/tests/macos_frames/main.rs new file mode 100644 index 000000000..7485600e4 --- /dev/null +++ b/tests/macos_frames/main.rs @@ -0,0 +1,26 @@ +// Based on from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs +// This needs to go in its own file in its own directory, since it modifies the dSYM +// for the entire directory +#[test] +#[cfg(target_os = "macos")] +fn backtrace_no_dsym() { + use std::{env, fs, panic}; + + // Find our dSYM and replace the DWARF binary with an empty file + let mut dsym_path = env::current_exe().unwrap(); + let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); + assert!(dsym_path.pop()); // Pop executable + dsym_path.push(format!( + "{}.dSYM/Contents/Resources/DWARF/{0}", + executable_name + )); + let _ = fs::OpenOptions::new() + .read(false) + .write(true) + .truncate(true) + .create(false) + .open(&dsym_path) + .unwrap(); + + backtrace::Backtrace::new(); +} From 3c90856e7eae35b2e31f1bc3c02923bf58455a8d Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 10 Mar 2020 12:11:22 -0400 Subject: [PATCH 08/11] Remove 'darwin' check to verify new test --- crates/backtrace-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index e96311356..86f4d275a 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -38,7 +38,7 @@ fn main() { // the less efficient `read`-based code. // Using `mmap` on macOS causes weird isseus - see // https://github.com/rust-lang/rust/pull/45866 - if target.contains("windows") || target.contains("darwin") { + if target.contains("windows")/* || target.contains("darwin")*/ { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); From e482844da54ed14e7ccd902028b0425ee25ad0b0 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 10 Mar 2020 12:14:55 -0400 Subject: [PATCH 09/11] Fix rustfmt --- crates/backtrace-sys/build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index 86f4d275a..bdac2cbc6 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -38,7 +38,9 @@ fn main() { // the less efficient `read`-based code. // Using `mmap` on macOS causes weird isseus - see // https://github.com/rust-lang/rust/pull/45866 - if target.contains("windows")/* || target.contains("darwin")*/ { + if target.contains("windows") + /* || target.contains("darwin")*/ + { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); From cadd87cf55e8b5aae2931ca0828dc03a4b8f2be8 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 10 Mar 2020 12:30:39 -0400 Subject: [PATCH 10/11] Re-add darwin check --- crates/backtrace-sys/build.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index bdac2cbc6..e96311356 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -38,9 +38,7 @@ fn main() { // the less efficient `read`-based code. // Using `mmap` on macOS causes weird isseus - see // https://github.com/rust-lang/rust/pull/45866 - if target.contains("windows") - /* || target.contains("darwin")*/ - { + if target.contains("windows") || target.contains("darwin") { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); From 3cc3e0759bdb08252e685ba4eb5eb83f70a40609 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 10 Mar 2020 13:15:51 -0400 Subject: [PATCH 11/11] Move macOS test to a non-workspace crate --- .github/workflows/main.yml | 1 + Cargo.toml | 2 +- crates/macos_frames_test/Cargo.toml | 8 ++++++++ crates/macos_frames_test/src/lib.rs | 1 + .../macos_frames_test/tests}/main.rs | 8 ++++++-- 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 crates/macos_frames_test/Cargo.toml create mode 100644 crates/macos_frames_test/src/lib.rs rename {tests/macos_frames => crates/macos_frames_test/tests}/main.rs (70%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd0fc4bf9..a039f23df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,7 @@ jobs: - run: cargo test --no-default-features --features "dbghelp std" - run: cargo test --no-default-features --features "dbghelp std verify-winapi" - run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml + - run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml - run: cargo test --features libbacktrace --manifest-path crates/without_debuginfo/Cargo.toml - run: cargo test --features "libbacktrace coresymbolication" --manifest-path crates/without_debuginfo/Cargo.toml - run: cargo test --features "libbacktrace gimli-symbolize" --manifest-path crates/without_debuginfo/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 1b5300cf7..61e350895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" [workspace] members = ['crates/cpp_smoke_test'] -exclude = ['crates/without_debuginfo'] +exclude = ['crates/without_debuginfo', 'crates/macos_frames_test'] [dependencies] cfg-if = "0.1.10" diff --git a/crates/macos_frames_test/Cargo.toml b/crates/macos_frames_test/Cargo.toml new file mode 100644 index 000000000..278d51e79 --- /dev/null +++ b/crates/macos_frames_test/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "macos_frames_test" +version = "0.1.0" +authors = ["Aaron Hill "] +edition = "2018" + +[dependencies.backtrace] +path = "../.." diff --git a/crates/macos_frames_test/src/lib.rs b/crates/macos_frames_test/src/lib.rs new file mode 100644 index 000000000..65e2cc340 --- /dev/null +++ b/crates/macos_frames_test/src/lib.rs @@ -0,0 +1 @@ +// intentionally blank diff --git a/tests/macos_frames/main.rs b/crates/macos_frames_test/tests/main.rs similarity index 70% rename from tests/macos_frames/main.rs rename to crates/macos_frames_test/tests/main.rs index 7485600e4..1d28f2022 100644 --- a/tests/macos_frames/main.rs +++ b/crates/macos_frames_test/tests/main.rs @@ -1,6 +1,10 @@ // Based on from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs -// This needs to go in its own file in its own directory, since it modifies the dSYM -// for the entire directory +// This needs to go in a crate by itself, since it modifies the dSYM for the entire test +// output directory. +// +// Note that this crate is *not* part of the overall `backtrace-rs` workspace, +// so that it gets its own 'target' directory. We manually invoke this test +// in .github/workflows/main.yml by passing `--manifest-path` to Cargo #[test] #[cfg(target_os = "macos")] fn backtrace_no_dsym() {