Skip to content

Commit

Permalink
Clean up compiletest
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Aug 18, 2024
1 parent 156088f commit e2523c1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/tools/compiletest/src/command-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-relocation-model-pic",
"needs-run-enabled",
"needs-rust-lld",
"needs-rust-lldb",
"needs-sanitizer-address",
"needs-sanitizer-cfi",
"needs-sanitizer-dataflow",
Expand Down
6 changes: 0 additions & 6 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,9 @@ pub struct Config {
/// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
pub gdb_version: Option<u32>,

/// Whether GDB has native rust support
pub gdb_native_rust: bool,

/// Version of LLDB
pub lldb_version: Option<u32>,

/// Whether LLDB has native rust support
pub lldb_native_rust: bool,

/// Version of LLVM
pub llvm_version: Option<u32>,

Expand Down
7 changes: 1 addition & 6 deletions src/tools/compiletest/src/header/needs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::common::{Config, Debugger, Sanitizer};
use crate::common::{Config, Sanitizer};
use crate::header::IgnoreDecision;

pub(super) fn handle_needs(
Expand Down Expand Up @@ -114,11 +114,6 @@ pub(super) fn handle_needs(
condition: cache.rust_lld,
ignore_reason: "ignored on targets without Rust's LLD",
},
Need {
name: "needs-rust-lldb",
condition: config.debugger != Some(Debugger::Lldb) || config.lldb_native_rust,
ignore_reason: "ignored on targets without Rust's LLDB",
},
Need {
name: "needs-dlltool",
condition: cache.dlltool,
Expand Down
36 changes: 11 additions & 25 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
let target = opt_str2(matches.opt_str("target"));
let android_cross_path = opt_path(matches, "android-cross-path");
let (cdb, cdb_version) = analyze_cdb(matches.opt_str("cdb"), &target);
let (gdb, gdb_version, gdb_native_rust) =
analyze_gdb(matches.opt_str("gdb"), &target, &android_cross_path);
let (lldb_version, lldb_native_rust) = matches
.opt_str("lldb-version")
.as_deref()
.and_then(extract_lldb_version)
.map(|(v, b)| (Some(v), b))
.unwrap_or((None, false));
let (gdb, gdb_version) = analyze_gdb(matches.opt_str("gdb"), &target, &android_cross_path);
let lldb_version = matches.opt_str("lldb-version").as_deref().and_then(extract_lldb_version);
let color = match matches.opt_str("color").as_deref() {
Some("auto") | None => ColorConfig::AutoColor,
Some("always") => ColorConfig::AlwaysColor,
Expand Down Expand Up @@ -298,9 +292,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
cdb_version,
gdb,
gdb_version,
gdb_native_rust,
lldb_version,
lldb_native_rust,
llvm_version,
system_llvm: matches.opt_present("system-llvm"),
android_cross_path,
Expand Down Expand Up @@ -1035,19 +1027,17 @@ fn extract_cdb_version(full_version_line: &str) -> Option<[u16; 4]> {
Some([major, minor, patch, build])
}

/// Returns (Path to GDB, GDB Version, GDB has Rust Support)
/// Returns (Path to GDB, GDB Version)
fn analyze_gdb(
gdb: Option<String>,
target: &str,
android_cross_path: &PathBuf,
) -> (Option<String>, Option<u32>, bool) {
) -> (Option<String>, Option<u32>) {
#[cfg(not(windows))]
const GDB_FALLBACK: &str = "gdb";
#[cfg(windows)]
const GDB_FALLBACK: &str = "gdb.exe";

const MIN_GDB_WITH_RUST: u32 = 7011010;

let fallback_gdb = || {
if is_android_gdb_target(target) {
let mut gdb_path = match android_cross_path.to_str() {
Expand Down Expand Up @@ -1076,12 +1066,10 @@ fn analyze_gdb(

let version = match version_line {
Some(line) => extract_gdb_version(&line),
None => return (None, None, false),
None => return (None, None),
};

let gdb_native_rust = version.map_or(false, |v| v >= MIN_GDB_WITH_RUST);

(Some(gdb), version, gdb_native_rust)
(Some(gdb), version)
}

fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
Expand Down Expand Up @@ -1131,8 +1119,8 @@ fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
Some(((major * 1000) + minor) * 1000 + patch)
}

/// Returns (LLDB version, LLDB is rust-enabled)
fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
/// Returns LLDB version
fn extract_lldb_version(full_version_line: &str) -> Option<u32> {
// Extract the major LLDB version from the given version string.
// LLDB version strings are different for Apple and non-Apple platforms.
// The Apple variant looks like this:
Expand All @@ -1149,9 +1137,7 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
// There doesn't seem to be a way to correlate the Apple version
// with the upstream version, and since the tests were originally
// written against Apple versions, we make a fake Apple version by
// multiplying the first number by 100. This is a hack, but
// normally fine because the only non-Apple version we test is
// rust-enabled.
// multiplying the first number by 100. This is a hack.

let full_version_line = full_version_line.trim();

Expand All @@ -1160,12 +1146,12 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
{
if let Some(idx) = apple_ver.find(not_a_digit) {
let version: u32 = apple_ver[..idx].parse().unwrap();
return Some((version, full_version_line.contains("rust-enabled")));
return Some(version);
}
} else if let Some(lldb_ver) = full_version_line.strip_prefix("lldb version ") {
if let Some(idx) = lldb_ver.find(not_a_digit) {
let version: u32 = lldb_ver[..idx].parse().ok()?;
return Some((version * 100, full_version_line.contains("rust-enabled")));
return Some(version * 100);
}
}
None
Expand Down
20 changes: 3 additions & 17 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,10 @@ impl<'test> TestCx<'test> {
}

fn run_debuginfo_gdb_test_no_opt(&self) {
let prefixes = &["gdb"];

let dbg_cmds = DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
&["gdb"],
self.revision,
)
.unwrap_or_else(|e| self.fatal(&e));
Expand Down Expand Up @@ -1043,9 +1041,7 @@ impl<'test> TestCx<'test> {
.push_str(&format!("file {}\n", exe_file.to_str().unwrap().replace(r"\", r"\\")));

// Force GDB to print values in the Rust format.
if self.config.gdb_native_rust {
script_str.push_str("set language rust\n");
}
script_str.push_str("set language rust\n");

// Add line breakpoints
for line in &dbg_cmds.breakpoint_lines {
Expand Down Expand Up @@ -1130,21 +1126,11 @@ impl<'test> TestCx<'test> {
}
}

let prefixes = if self.config.lldb_native_rust {
static PREFIXES: &[&str] = &["lldb", "lldbr"];
println!("NOTE: compiletest thinks it is using LLDB with native rust support");
PREFIXES
} else {
static PREFIXES: &[&str] = &["lldb", "lldbg"];
println!("NOTE: compiletest thinks it is using LLDB without native rust support");
PREFIXES
};

// Parse debugger commands etc from test files
let dbg_cmds = DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
&["lldb"],
self.revision,
)
.unwrap_or_else(|e| self.fatal(&e));
Expand Down
8 changes: 4 additions & 4 deletions src/tools/compiletest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ fn test_extract_gdb_version() {
#[test]
fn test_extract_lldb_version() {
// Apple variants
assert_eq!(extract_lldb_version("LLDB-179.5"), Some((179, false)));
assert_eq!(extract_lldb_version("lldb-300.2.51"), Some((300, false)));
assert_eq!(extract_lldb_version("LLDB-179.5"), Some(179));
assert_eq!(extract_lldb_version("lldb-300.2.51"), Some(300));

// Upstream versions
assert_eq!(extract_lldb_version("lldb version 6.0.1"), Some((600, false)));
assert_eq!(extract_lldb_version("lldb version 9.0.0"), Some((900, false)));
assert_eq!(extract_lldb_version("lldb version 6.0.1"), Some(600));
assert_eq!(extract_lldb_version("lldb version 9.0.0"), Some(900));
}

#[test]
Expand Down

0 comments on commit e2523c1

Please sign in to comment.