Rollup merge of #99488 - luqmana:debuginfo-revisions, r=tmiasko

compiletest: Allow using revisions with debuginfo tests.

A small wart that came up in https://github.com/rust-lang/rust/pull/95685#issuecomment-1089184951.
This commit is contained in:
Matthias Krüger 2022-07-20 18:58:18 +02:00 committed by GitHub
commit a0c696484f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 105 deletions

View File

@ -1,81 +0,0 @@
// Caveat - gdb doesn't know about UTF-32 character encoding and will print a
// rust char as only its numerical value.
// min-lldb-version: 310
// min-gdb-version: 8.0
// no-prefer-dynamic
// compile-flags:-g -C lto
// gdb-command:run
// gdbg-command:print 'basic_types_globals::B'
// gdbr-command:print B
// gdb-check:$1 = false
// gdbg-command:print 'basic_types_globals::I'
// gdbr-command:print I
// gdb-check:$2 = -1
// gdbg-command:print 'basic_types_globals::C'
// gdbr-command:print/d C
// gdbg-check:$3 = 97
// gdbr-check:$3 = 97
// gdbg-command:print/d 'basic_types_globals::I8'
// gdbr-command:print I8
// gdb-check:$4 = 68
// gdbg-command:print 'basic_types_globals::I16'
// gdbr-command:print I16
// gdb-check:$5 = -16
// gdbg-command:print 'basic_types_globals::I32'
// gdbr-command:print I32
// gdb-check:$6 = -32
// gdbg-command:print 'basic_types_globals::I64'
// gdbr-command:print I64
// gdb-check:$7 = -64
// gdbg-command:print 'basic_types_globals::U'
// gdbr-command:print U
// gdb-check:$8 = 1
// gdbg-command:print/d 'basic_types_globals::U8'
// gdbr-command:print U8
// gdb-check:$9 = 100
// gdbg-command:print 'basic_types_globals::U16'
// gdbr-command:print U16
// gdb-check:$10 = 16
// gdbg-command:print 'basic_types_globals::U32'
// gdbr-command:print U32
// gdb-check:$11 = 32
// gdbg-command:print 'basic_types_globals::U64'
// gdbr-command:print U64
// gdb-check:$12 = 64
// gdbg-command:print 'basic_types_globals::F32'
// gdbr-command:print F32
// gdb-check:$13 = 2.5
// gdbg-command:print 'basic_types_globals::F64'
// gdbr-command:print F64
// gdb-check:$14 = 3.5
// gdb-command:continue
#![allow(unused_variables)]
#![feature(omit_gdb_pretty_printer_section)]
#![omit_gdb_pretty_printer_section]
// N.B. These are `mut` only so they don't constant fold away.
static mut B: bool = false;
static mut I: isize = -1;
static mut C: char = 'a';
static mut I8: i8 = 68;
static mut I16: i16 = -16;
static mut I32: i32 = -32;
static mut I64: i64 = -64;
static mut U: usize = 1;
static mut U8: u8 = 100;
static mut U16: u16 = 16;
static mut U32: u32 = 32;
static mut U64: u64 = 64;
static mut F32: f32 = 2.5;
static mut F64: f64 = 3.5;
fn main() {
_zzz(); // #break
let a = unsafe { (B, I, C, I8, I16, I32, I64, U, U8, U16, U32, U64, F32, F64) };
}
fn _zzz() {()}

View File

@ -4,7 +4,13 @@
// min-lldb-version: 310
// min-gdb-version: 8.0
// revisions: lto no-lto
// compile-flags:-g
// [lto] compile-flags:-C lto
// [lto] no-prefer-dynamic
// gdb-command:run
// gdbg-command:print 'basic_types_globals::B'
// gdbr-command:print B

View File

@ -535,6 +535,29 @@ impl TestProps {
}
}
pub fn line_directive<'line>(
comment: &str,
ln: &'line str,
) -> Option<(Option<&'line str>, &'line str)> {
if ln.starts_with(comment) {
let ln = ln[comment.len()..].trim_start();
if ln.starts_with('[') {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let lncfg = &ln[1..close_brace];
Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
} else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
}
} else {
Some((None, ln))
}
} else {
None
}
}
fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) {
if testfile.is_dir() {
return;
@ -557,17 +580,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
let ln = ln.trim();
if ln.starts_with("fn") || ln.starts_with("mod") {
return;
} else if ln.starts_with(comment) && ln[comment.len()..].trim_start().starts_with('[') {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let open_brace = ln.find('[').unwrap();
let lncfg = &ln[open_brace + 1..close_brace];
it(Some(lncfg), ln[(close_brace + 1)..].trim_start());
} else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
}
} else if ln.starts_with(comment) {
it(None, ln[comment.len()..].trim_start());
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
it(lncfg, ln);
}
}
}

View File

@ -648,8 +648,6 @@ impl<'test> TestCx<'test> {
}
fn run_debuginfo_cdb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");
let config = Config {
target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
@ -695,7 +693,12 @@ impl<'test> TestCx<'test> {
// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
@ -756,8 +759,6 @@ impl<'test> TestCx<'test> {
}
fn run_debuginfo_gdb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");
let config = Config {
target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
@ -783,7 +784,12 @@ impl<'test> TestCx<'test> {
};
let DebuggerCommands { commands, check_lines, breakpoint_lines } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
@ -1005,8 +1011,6 @@ impl<'test> TestCx<'test> {
}
fn run_debuginfo_lldb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");
if self.config.lldb_python_dir.is_none() {
self.fatal("Can't run LLDB test because LLDB's python path is not set.");
}
@ -1059,7 +1063,12 @@ impl<'test> TestCx<'test> {
// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};

View File

@ -1,4 +1,5 @@
use crate::common::Config;
use crate::header::line_directive;
use crate::runtest::ProcRes;
use std::fs::File;
@ -16,6 +17,7 @@ impl DebuggerCommands {
file: &Path,
config: &Config,
debugger_prefixes: &[&str],
rev: Option<&str>,
) -> Result<Self, String> {
let directives = debugger_prefixes
.iter()
@ -25,13 +27,19 @@ impl DebuggerCommands {
let mut breakpoint_lines = vec![];
let mut commands = vec![];
let mut check_lines = vec![];
let mut counter = 1;
let mut counter = 0;
let reader = BufReader::new(File::open(file).unwrap());
for line in reader.lines() {
counter += 1;
match line {
Ok(line) => {
let line =
if line.starts_with("//") { line[2..].trim_start() } else { line.as_str() };
let (lnrev, line) = line_directive("//", &line).unwrap_or((None, &line));
// Skip any revision specific directive that doesn't match the current
// revision being tested
if lnrev.is_some() && lnrev != rev {
continue;
}
if line.contains("#break") {
breakpoint_lines.push(counter);
@ -49,7 +57,6 @@ impl DebuggerCommands {
}
Err(e) => return Err(format!("Error while parsing debugger commands: {}", e)),
}
counter += 1;
}
Ok(Self { commands, check_lines, breakpoint_lines })