1 // We disable tail merging here because it can't preserve debuginfo and thus
2 // potentially breaks the backtraces. Also, subtle changes can decide whether
3 // tail merging succeeds, so the test might work today but fail tomorrow due to a
4 // seemingly completely unrelated change.
5 // Unfortunately, LLVM has no "disable" option for this, so we have to set
6 // "enable" to 0 instead.
8 // compile-flags:-g -Cllvm-args=-enable-tail-merge=0 -Cllvm-args=-opt-bisect-limit=0
9 // compile-flags:-Cforce-frame-pointers=yes
10 // ignore-pretty issue #37195
11 // ignore-cloudabi spawning processes is not supported
12 // ignore-emscripten spawning processes is not supported
14 // note that above `-opt-bisect-limit=0` is used to basically disable
19 #[path = "backtrace-debuginfo-aux.rs"] mod aux;
22 () => ((file!(), line!()))
25 macro_rules! dump_and_die {
26 ($($pos:expr),*) => ({
27 // FIXME(#18285): we cannot include the current position because
28 // the macro span takes over the last frame's file/line.
29 if cfg!(any(target_os = "android",
30 all(target_os = "linux", target_arch = "arm"),
31 target_os = "freebsd",
32 target_os = "dragonfly",
34 target_os = "openbsd")) {
35 // skip these platforms as this support isn't implemented yet.
37 dump_filelines(&[$($pos),*]);
43 // we can't use a function as it will alter the backtrace
45 ($counter:expr; $($pos:expr),*) => ({
47 dump_and_die!($($pos),*)
54 type Pos = (&'static str, u32);
56 // this goes to stdout and each line has to be occurred
57 // in the following backtrace to stderr with a correct order.
58 fn dump_filelines(filelines: &[Pos]) {
59 for &(file, line) in filelines.iter().rev() {
61 let basename = file.split(&['/', '\\'][..]).last().unwrap();
62 println!("{}:{}", basename, line);
67 fn inner(counter: &mut i32, main_pos: Pos, outer_pos: Pos) {
68 check!(counter; main_pos, outer_pos);
69 check!(counter; main_pos, outer_pos);
70 let inner_pos = pos!(); aux::callback(|aux_pos| {
71 check!(counter; main_pos, outer_pos, inner_pos, aux_pos);
73 let inner_pos = pos!(); aux::callback_inlined(|aux_pos| {
74 check!(counter; main_pos, outer_pos, inner_pos, aux_pos);
78 // We emit the wrong location for the caller here when inlined on MSVC
79 #[cfg_attr(not(target_env = "msvc"), inline(always))]
80 #[cfg_attr(target_env = "msvc", inline(never))]
81 fn inner_inlined(counter: &mut i32, main_pos: Pos, outer_pos: Pos) {
82 check!(counter; main_pos, outer_pos);
83 check!(counter; main_pos, outer_pos);
85 // Again, disable inlining for MSVC.
86 #[cfg_attr(not(target_env = "msvc"), inline(always))]
87 #[cfg_attr(target_env = "msvc", inline(never))]
88 fn inner_further_inlined(counter: &mut i32, main_pos: Pos, outer_pos: Pos, inner_pos: Pos) {
89 check!(counter; main_pos, outer_pos, inner_pos);
91 inner_further_inlined(counter, main_pos, outer_pos, pos!());
93 let inner_pos = pos!(); aux::callback(|aux_pos| {
94 check!(counter; main_pos, outer_pos, inner_pos, aux_pos);
96 let inner_pos = pos!(); aux::callback_inlined(|aux_pos| {
97 check!(counter; main_pos, outer_pos, inner_pos, aux_pos);
100 // this tests a distinction between two independent calls to the inlined function.
101 // (un)fortunately, LLVM somehow merges two consecutive such calls into one node.
102 inner_further_inlined(counter, main_pos, outer_pos, pos!());
106 fn outer(mut counter: i32, main_pos: Pos) {
107 inner(&mut counter, main_pos, pos!());
108 inner_inlined(&mut counter, main_pos, pos!());
111 fn check_trace(output: &str, error: &str) -> Result<(), String> {
112 // reverse the position list so we can start with the last item (which was the first line)
113 let mut remaining: Vec<&str> = output.lines().map(|s| s.trim()).rev().collect();
115 if !error.contains("stack backtrace") {
116 return Err(format!("no backtrace found in stderr:\n{}", error))
118 for line in error.lines() {
119 if !remaining.is_empty() && line.contains(remaining.last().unwrap()) {
123 if !remaining.is_empty() {
124 return Err(format!("trace does not match position list\n\
125 still need to find {:?}\n\n\
128 remaining, output, error))
133 fn run_test(me: &str) {
135 use std::process::Command;
138 let mut errors = Vec::new();
140 let out = Command::new(me)
141 .env("RUST_BACKTRACE", "full")
142 .arg(i.to_string()).output().unwrap();
143 let output = str::from_utf8(&out.stdout).unwrap();
144 let error = str::from_utf8(&out.stderr).unwrap();
145 if out.status.success() {
146 assert!(output.contains("done."), "bad output for successful run: {}", output);
149 if let Err(e) = check_trace(output, error) {
155 if errors.len() > 0 {
156 for error in errors {
157 println!("---------------------------------------");
158 println!("{}", error);
161 panic!("found some errors");
167 let args: Vec<String> = env::args().collect();
169 let case = args[1].parse().unwrap();
170 eprintln!("test case {}", case);