Skip to content

Commit e34d36b

Browse files
debuginfo: Emit different autotest debugger scripts depending on GDB version.
1 parent 3e727b0 commit e34d36b

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

configure

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,14 @@ probe CFG_LUALATEX lualatex
509509
probe CFG_GDB gdb
510510
probe CFG_LLDB lldb
511511

512+
if [ ! -z "$CFG_GDB" ]
513+
then
514+
# Extract the version
515+
CFG_GDB_VERSION=$($CFG_GDB --version 2>/dev/null | head -1 \
516+
| sed -e 's/.*\([0-9]\+\.[0-9]\+$\)/\1/' )
517+
putvar CFG_GDB_VERSION
518+
fi
519+
512520
if [ ! -z "$CFG_LLDB" ]
513521
then
514522
# If CFG_LLDB_PYTHON_DIR is not already set from the outside and valid, try to read it from

mk/tests.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
623623
--stage-id stage$(1)-$(2) \
624624
--target $(2) \
625625
--host $(3) \
626+
--gdb-version=$(CFG_GDB_VERSION) \
626627
--android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
627628
--adb-path=$(CFG_ADB) \
628629
--adb-test-dir=$(CFG_ADB_TEST_DIR) \

src/compiletest/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ pub struct Config {
130130
// Host triple for the compiler being invoked
131131
pub host: String,
132132

133+
// Version of GDB
134+
pub gdb_version: Option<String>,
135+
133136
// Path to the android tools
134137
pub android_cross_path: Path,
135138

src/compiletest/compiletest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
8181
optflag("", "jit", "run tests under the JIT"),
8282
optopt("", "target", "the target to build for", "TARGET"),
8383
optopt("", "host", "the host to build for", "HOST"),
84+
optopt("", "gdb-version", "the version of GDB used", "MAJOR.MINOR"),
8485
optopt("", "android-cross-path", "Android NDK standalone path", "PATH"),
8586
optopt("", "adb-path", "path to the android debugger", "PATH"),
8687
optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"),
@@ -157,6 +158,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
157158
jit: matches.opt_present("jit"),
158159
target: opt_str2(matches.opt_str("target")),
159160
host: opt_str2(matches.opt_str("host")),
161+
gdb_version: matches.opt_str("gdb-version"),
160162
android_cross_path: opt_path(matches, "android-cross-path"),
161163
adb_path: opt_str2(matches.opt_str("adb-path")),
162164
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")),

src/compiletest/runtest.rs

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use util::logv;
2020
#[cfg(stage0, target_os = "win32")] // NOTE: Remove after snapshot
2121
use util;
2222

23+
use std::from_str::FromStr;
2324
use std::io::File;
2425
use std::io::fs;
2526
use std::io::net::tcp;
@@ -317,6 +318,7 @@ actual:\n\
317318
}
318319

319320
fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
321+
320322
let mut config = Config {
321323
target_rustcflags: cleanup_debug_info_options(&config.target_rustcflags),
322324
host_rustcflags: cleanup_debug_info_options(&config.host_rustcflags),
@@ -467,11 +469,38 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
467469
.unwrap()
468470
.to_string();
469471
// write debugger script
470-
let script_str = [
471-
"set charset UTF-8".to_string(),
472-
cmds,
473-
"quit\n".to_string()
474-
].connect("\n");
472+
let mut script_str = String::with_capacity(2048);
473+
474+
script_str.push_str("set charset UTF-8\n");
475+
script_str.push_str("show version\n");
476+
477+
match config.gdb_version {
478+
Some(ref version) => {
479+
if gdb_version_to_int(version.as_slice()) > gdb_version_to_int("7.3") {
480+
// Add the directory containing the pretty printers to
481+
// GDB's script auto loading safe path ...
482+
script_str.push_str(
483+
format!("add-auto-load-safe-path {}\n",
484+
rust_pp_module_abs_path.as_slice())
485+
.as_slice());
486+
// ... and also the test directory
487+
script_str.push_str(
488+
format!("add-auto-load-safe-path {}\n",
489+
config.build_base.as_str().unwrap())
490+
.as_slice());
491+
}
492+
}
493+
_ => { /* nothing to do */ }
494+
}
495+
496+
// Load the target executable
497+
script_str.push_str(format!("file {}\n",
498+
exe_file.as_str().unwrap())
499+
.as_slice());
500+
501+
script_str.push_str(cmds.as_slice());
502+
script_str.push_str("quit\n");
503+
475504
debug!("script_str = {}", script_str);
476505
dump_output_file(config,
477506
testfile,
@@ -501,15 +530,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
501530
vec!("-quiet".to_string(),
502531
"-batch".to_string(),
503532
"-nx".to_string(),
504-
// Add the directory containing the pretty printers to
505-
// GDB's script auto loading safe path ...
506-
format!("-iex=add-auto-load-safe-path {}",
507-
rust_pp_module_abs_path.as_slice()),
508-
// ... and also the test directory
509-
format!("-iex=add-auto-load-safe-path {}",
510-
config.build_base.as_str().unwrap()),
511-
format!("-command={}", debugger_script.as_str().unwrap()),
512-
exe_file.as_str().unwrap().to_string());
533+
format!("-command={}", debugger_script.as_str().unwrap()));
513534

514535
let proc_args = ProcArgs {
515536
prog: debugger(),
@@ -546,6 +567,23 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
546567

547568
File::create(&script_path).write(script_content).unwrap();
548569
}
570+
571+
fn gdb_version_to_int(version_string: &str) -> int {
572+
let error_string = format!(
573+
"Encountered GDB version string with unexpected format: {}",
574+
version_string);
575+
576+
let components: Vec<&str> = version_string.trim().split('.').collect();
577+
578+
if components.len() != 2 {
579+
fatal(error_string.as_slice());
580+
}
581+
582+
let major: int = FromStr::from_str(components[0]).expect(error_string.as_slice());
583+
let minor: int = FromStr::from_str(components[1]).expect(error_string.as_slice());
584+
585+
return major * 1000 + minor;
586+
}
549587
}
550588

551589
fn find_rust_src_root(config: &Config) -> Option<Path> {

0 commit comments

Comments
 (0)