Skip to content

Commit 102bab3

Browse files
committed
Auto merge of #33225 - michaelwoerister:fix-debuginfo-struct-ns, r=eddyb
debuginfo: Fix regression in namespace handling for struct types. Fixes a small regression that has been introduced in recent refactorings. Fixes #33193 r? @eddyb
2 parents 5158f3b + bb0e525 commit 102bab3

File tree

3 files changed

+124
-50
lines changed

3 files changed

+124
-50
lines changed

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,12 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
11591159
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
11601160
let struct_llvm_type = type_of::in_memory_type_of(cx, struct_type);
11611161

1162-
let (variant, substs) = match struct_type.sty {
1163-
ty::TyStruct(def, substs) => (def.struct_variant(), substs),
1162+
let (struct_def_id, variant, substs) = match struct_type.sty {
1163+
ty::TyStruct(def, substs) => (def.did, def.struct_variant(), substs),
11641164
_ => bug!("prepare_struct_metadata on a non-struct")
11651165
};
11661166

1167-
let (containing_scope, _) = get_namespace_and_span_for_item(cx, variant.did);
1167+
let (containing_scope, _) = get_namespace_and_span_for_item(cx, struct_def_id);
11681168

11691169
let struct_metadata_stub = create_struct_stub(cx,
11701170
struct_llvm_type,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2013-2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-gdb
12+
// compile-flags:-g
13+
// min-lldb-version: 310
14+
15+
// Check that structs get placed in the correct namespace
16+
17+
// lldb-command:run
18+
// lldb-command:p struct1
19+
// lldb-check:(struct_namespace::Struct1) $0 = [...]
20+
// lldb-command:p struct2
21+
// lldb-check:(struct_namespace::Struct2) $1 = [...]
22+
23+
// lldb-command:p mod1_struct1
24+
// lldb-check:(struct_namespace::mod1::Struct1) $2 = [...]
25+
// lldb-command:p mod1_struct2
26+
// lldb-check:(struct_namespace::mod1::Struct2) $3 = [...]
27+
28+
#![allow(unused_variables)]
29+
#![allow(dead_code)]
30+
#![feature(omit_gdb_pretty_printer_section)]
31+
#![omit_gdb_pretty_printer_section]
32+
33+
struct Struct1 {
34+
a: u32,
35+
b: u64,
36+
}
37+
38+
struct Struct2(u32);
39+
40+
mod mod1 {
41+
42+
pub struct Struct1 {
43+
pub a: u32,
44+
pub b: u64,
45+
}
46+
47+
pub struct Struct2(pub u32);
48+
}
49+
50+
51+
fn main() {
52+
let struct1 = Struct1 {
53+
a: 0,
54+
b: 1,
55+
};
56+
57+
let struct2 = Struct2(2);
58+
59+
let mod1_struct1 = mod1::Struct1 {
60+
a: 3,
61+
b: 4,
62+
};
63+
64+
let mod1_struct2 = mod1::Struct2(5);
65+
66+
zzz(); // #break
67+
}
68+
69+
#[inline(never)]
70+
fn zzz() {()}

src/tools/compiletest/src/runtest.rs

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -880,58 +880,62 @@ fn cleanup_debug_info_options(options: &Option<String>) -> Option<String> {
880880

881881
fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String]) {
882882
let num_check_lines = check_lines.len();
883-
if num_check_lines > 0 {
883+
884+
let mut check_line_index = 0;
885+
for line in debugger_run_result.stdout.lines() {
886+
if check_line_index >= num_check_lines {
887+
break;
888+
}
889+
890+
if check_single_line(line, &(check_lines[check_line_index])[..]) {
891+
check_line_index += 1;
892+
}
893+
}
894+
if check_line_index != num_check_lines && num_check_lines > 0 {
895+
fatal_proc_rec(None, &format!("line not found in debugger output: {}",
896+
check_lines[check_line_index]),
897+
debugger_run_result);
898+
}
899+
900+
fn check_single_line(line: &str, check_line: &str) -> bool {
884901
// Allow check lines to leave parts unspecified (e.g., uninitialized
885-
// bits in the wrong case of an enum) with the notation "[...]".
886-
let check_fragments: Vec<Vec<String>> =
887-
check_lines.iter().map(|s| {
888-
s
889-
.trim()
890-
.split("[...]")
891-
.map(str::to_owned)
892-
.collect()
893-
}).collect();
894-
// check if each line in props.check_lines appears in the
895-
// output (in order)
896-
let mut i = 0;
897-
for line in debugger_run_result.stdout.lines() {
898-
let mut rest = line.trim();
899-
let mut first = true;
900-
let mut failed = false;
901-
for frag in &check_fragments[i] {
902-
let found = if first {
903-
if rest.starts_with(frag) {
904-
Some(0)
905-
} else {
906-
None
907-
}
908-
} else {
909-
rest.find(frag)
910-
};
911-
match found {
912-
None => {
913-
failed = true;
914-
break;
915-
}
916-
Some(i) => {
917-
rest = &rest[(i + frag.len())..];
918-
}
919-
}
920-
first = false;
921-
}
922-
if !failed && rest.is_empty() {
923-
i += 1;
902+
// bits in the wrong case of an enum) with the notation "[...]".
903+
let line = line.trim();
904+
let check_line = check_line.trim();
905+
let can_start_anywhere = check_line.starts_with("[...]");
906+
let can_end_anywhere = check_line.ends_with("[...]");
907+
908+
let check_fragments: Vec<&str> = check_line.split("[...]")
909+
.filter(|frag| !frag.is_empty())
910+
.collect();
911+
if check_fragments.is_empty() {
912+
return true;
913+
}
914+
915+
let (mut rest, first_fragment) = if can_start_anywhere {
916+
match line.find(check_fragments[0]) {
917+
Some(pos) => (&line[pos + check_fragments[0].len() ..], 1),
918+
None => return false
924919
}
925-
if i == num_check_lines {
926-
// all lines checked
927-
break;
920+
} else {
921+
(line, 0)
922+
};
923+
924+
for fragment_index in first_fragment .. check_fragments.len() {
925+
let current_fragment = check_fragments[fragment_index];
926+
match rest.find(current_fragment) {
927+
Some(pos) => {
928+
rest = &rest[pos + current_fragment.len() .. ];
929+
}
930+
None => return false
928931
}
929932
}
930-
if i != num_check_lines {
931-
fatal_proc_rec(None, &format!("line not found in debugger output: {}",
932-
check_lines.get(i).unwrap()),
933-
debugger_run_result);
933+
934+
if !can_end_anywhere && !rest.is_empty() {
935+
return false;
934936
}
937+
938+
return true;
935939
}
936940
}
937941

0 commit comments

Comments
 (0)