Skip to content

Commit 0538044

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#37410 - TimNN:gdb-next-gen, r=alexcrichton
Support GDB with native rust support This PR aims at making the debuginfo tests pass with the newer GDB versions which have native rust support (RGDB) To that end debuginfo tests now support three GDB prefixes: - `gdb` applicable to both GDB varieties - `gdbg` (**G**eneric) only applicable to the old GDB - `gdbr` (**R**ust) only applicable to the new RGDB Whether the GDB has rust support is detected based on it's version: GDB >= 7.11.10 is considered to have rust support. --- **Test updates** All tests have been updated to the new GDB version. Note that some tests currently require the GDB trunk<sup>1</sup>. --- **How to move forward with this PR:** I propose the following steps for moving forward with this PR: - [x] Validate the general approach of this PR (the `gdb-`, `gdbg-` and `gdbr-` split) - [x] Validate the approach taken for updating the debuginfo tests (I've checked this since there's (almost) no `set language c` left, which was my main concern) - [x] Determine how to distinguish between the new and old GDB (and implement that) - [ ] Add one or more non-gating build bots with the new GDB (blocked on the previous item, can happen after this PR has been merged) - [ ] If the new bots pass the tests, gate on them - [x] \(Maybe) update the remaining tests to run without `set syntax c` (in a separate PR) - [ ] \(Maybe) add tests specifically for the new GDB (in a separate PR / open an issue about this) I'm not completely sure about the build bot related steps (cc @alexcrichton), the current approach was suggested to prevent any downtime / broken build time between a new GDB gating builder being added and this PR being merged. --- **Suboptimal RGDB Output** I've found several places where the output of RGDB is not ideal. They are tagged with `// FIXME`, here is an overview: - [x] Trait references are not syntactically correct: `type_names::&Trait2<...>` (**WontFix**: the issue is minor and from @Manishearth below: "to properly address the trait issue we should wait for trait object support") - [x] Univariant enums are printed as `<error reading variable>` (**Fixed** in GDB trunk<sup>1<sup>) - [x] Unions are printed as `<error reading variable>` (**Fixed** in GDB trunk<sup>1</sup>) - [x] "Nil Enums" (`enum Foo {}`) are printed as `<error reading variable>` (**WontFix**: the are not supposed to exist) - [x] I have found no alternative for `sizeof(var)` in rust mode, so had to resort to `set language c` (**Fixed** in GDB trunk<sup>1</sup>) - [x] I have found not way of interpreting a value as a specific enum variant, so had to resort to `set language c` (**Fixed** in GDB trunk<sup>1</sup>) - [x] Before the initial `run` command, gdb does not realise it should be in rust mode (thus, if one want's to print statics before the run one has to explicitly `set language rust`) (maybe this is intended / expected behaviour, if so, someone please tell me ;) (**"Expected"** / current behaviour of GDB: picks up jemalloc, see rust-lang#37410 (comment)) <sup>1</sup>: Or rather in @Manishearth's trunk, waiting to be merged upstream. --- cc @alexcrichton, @michaelwoerister, rust-lang#36323
2 parents 2f98448 + f7107f3 commit 0538044

File tree

77 files changed

+1256
-613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1256
-613
lines changed

configure

-7
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,6 @@ then
868868
fi
869869
fi
870870

871-
if [ -n "$CFG_GDB" ]
872-
then
873-
# Store GDB's version
874-
CFG_GDB_VERSION=$($CFG_GDB --version 2>/dev/null | head -1)
875-
putvar CFG_GDB_VERSION
876-
fi
877-
878871
if [ -n "$CFG_LLDB" ]
879872
then
880873
# Store LLDB's version

mk/tests.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) = \
648648
--host $(3) \
649649
--docck-python $$(CFG_PYTHON) \
650650
--lldb-python $$(CFG_LLDB_PYTHON) \
651-
--gdb-version="$(CFG_GDB_VERSION)" \
651+
--gdb="$(CFG_GDB)" \
652652
--lldb-version="$(CFG_LLDB_VERSION)" \
653653
--llvm-version="$$(LLVM_VERSION_$(3))" \
654654
--android-cross-path=$(CFG_ARM_LINUX_ANDROIDEABI_NDK) \

src/bootstrap/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ pub fn compiletest(build: &Build,
168168
cmd.arg("--lldb-python").arg(python_default);
169169
}
170170

171-
if let Some(ref vers) = build.gdb_version {
172-
cmd.arg("--gdb-version").arg(vers);
171+
if let Some(ref gdb) = build.config.gdb {
172+
cmd.arg("--gdb").arg(gdb);
173173
}
174174
if let Some(ref vers) = build.lldb_version {
175175
cmd.arg("--lldb-version").arg(vers);

src/bootstrap/config.rs

+46-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::process;
2323
use num_cpus;
2424
use rustc_serialize::Decodable;
2525
use toml::{Parser, Decoder, Value};
26+
use util::push_exe_path;
2627

2728
/// Global configuration for the entire build and/or bootstrap.
2829
///
@@ -86,6 +87,7 @@ pub struct Config {
8687
pub mandir: Option<String>,
8788
pub codegen_tests: bool,
8889
pub nodejs: Option<PathBuf>,
90+
pub gdb: Option<PathBuf>,
8991
}
9092

9193
/// Per-target configuration stored in the global configuration structure.
@@ -123,6 +125,7 @@ struct Build {
123125
compiler_docs: Option<bool>,
124126
docs: Option<bool>,
125127
submodules: Option<bool>,
128+
gdb: Option<String>,
126129
}
127130

128131
/// TOML representation of how the LLVM build is configured.
@@ -227,6 +230,7 @@ impl Config {
227230
}
228231
config.rustc = build.rustc.map(PathBuf::from);
229232
config.cargo = build.cargo.map(PathBuf::from);
233+
config.gdb = build.gdb.map(PathBuf::from);
230234
set(&mut config.compiler_docs, build.compiler_docs);
231235
set(&mut config.docs, build.docs);
232236
set(&mut config.submodules, build.submodules);
@@ -356,44 +360,47 @@ impl Config {
356360
.collect();
357361
}
358362
"CFG_MUSL_ROOT" if value.len() > 0 => {
359-
self.musl_root = Some(PathBuf::from(value));
363+
self.musl_root = Some(parse_configure_path(value));
360364
}
361365
"CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
362366
let target = "x86_64-unknown-linux-musl".to_string();
363367
let target = self.target_config.entry(target)
364368
.or_insert(Target::default());
365-
target.musl_root = Some(PathBuf::from(value));
369+
target.musl_root = Some(parse_configure_path(value));
366370
}
367371
"CFG_MUSL_ROOT_I686" if value.len() > 0 => {
368372
let target = "i686-unknown-linux-musl".to_string();
369373
let target = self.target_config.entry(target)
370374
.or_insert(Target::default());
371-
target.musl_root = Some(PathBuf::from(value));
375+
target.musl_root = Some(parse_configure_path(value));
372376
}
373377
"CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
374378
let target = "arm-unknown-linux-musleabi".to_string();
375379
let target = self.target_config.entry(target)
376380
.or_insert(Target::default());
377-
target.musl_root = Some(PathBuf::from(value));
381+
target.musl_root = Some(parse_configure_path(value));
378382
}
379383
"CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
380384
let target = "arm-unknown-linux-musleabihf".to_string();
381385
let target = self.target_config.entry(target)
382386
.or_insert(Target::default());
383-
target.musl_root = Some(PathBuf::from(value));
387+
target.musl_root = Some(parse_configure_path(value));
384388
}
385389
"CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
386390
let target = "armv7-unknown-linux-musleabihf".to_string();
387391
let target = self.target_config.entry(target)
388392
.or_insert(Target::default());
389-
target.musl_root = Some(PathBuf::from(value));
393+
target.musl_root = Some(parse_configure_path(value));
390394
}
391395
"CFG_DEFAULT_AR" if value.len() > 0 => {
392396
self.rustc_default_ar = Some(value.to_string());
393397
}
394398
"CFG_DEFAULT_LINKER" if value.len() > 0 => {
395399
self.rustc_default_linker = Some(value.to_string());
396400
}
401+
"CFG_GDB" if value.len() > 0 => {
402+
self.gdb = Some(parse_configure_path(value));
403+
}
397404
"CFG_RELEASE_CHANNEL" => {
398405
self.channel = value.to_string();
399406
}
@@ -412,48 +419,72 @@ impl Config {
412419
"CFG_LLVM_ROOT" if value.len() > 0 => {
413420
let target = self.target_config.entry(self.build.clone())
414421
.or_insert(Target::default());
415-
let root = PathBuf::from(value);
416-
target.llvm_config = Some(root.join("bin/llvm-config"));
422+
let root = parse_configure_path(value);
423+
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
417424
}
418425
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
419426
let target = self.target_config.entry(self.build.clone())
420427
.or_insert(Target::default());
421-
target.jemalloc = Some(PathBuf::from(value));
428+
target.jemalloc = Some(parse_configure_path(value));
422429
}
423430
"CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
424431
let target = "arm-linux-androideabi".to_string();
425432
let target = self.target_config.entry(target)
426433
.or_insert(Target::default());
427-
target.ndk = Some(PathBuf::from(value));
434+
target.ndk = Some(parse_configure_path(value));
428435
}
429436
"CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
430437
let target = "armv7-linux-androideabi".to_string();
431438
let target = self.target_config.entry(target)
432439
.or_insert(Target::default());
433-
target.ndk = Some(PathBuf::from(value));
440+
target.ndk = Some(parse_configure_path(value));
434441
}
435442
"CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
436443
let target = "i686-linux-android".to_string();
437444
let target = self.target_config.entry(target)
438445
.or_insert(Target::default());
439-
target.ndk = Some(PathBuf::from(value));
446+
target.ndk = Some(parse_configure_path(value));
440447
}
441448
"CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
442449
let target = "aarch64-linux-android".to_string();
443450
let target = self.target_config.entry(target)
444451
.or_insert(Target::default());
445-
target.ndk = Some(PathBuf::from(value));
452+
target.ndk = Some(parse_configure_path(value));
446453
}
447454
"CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
448-
self.rustc = Some(PathBuf::from(value).join("bin/rustc"));
449-
self.cargo = Some(PathBuf::from(value).join("bin/cargo"));
455+
let path = parse_configure_path(value);
456+
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
457+
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
450458
}
451459
_ => {}
452460
}
453461
}
454462
}
455463
}
456464

465+
#[cfg(not(windows))]
466+
fn parse_configure_path(path: &str) -> PathBuf {
467+
path.into()
468+
}
469+
470+
#[cfg(windows)]
471+
fn parse_configure_path(path: &str) -> PathBuf {
472+
// on windows, configure produces unix style paths e.g. /c/some/path but we
473+
// only want real windows paths
474+
475+
use build_helper;
476+
477+
// '/' is invalid in windows paths, so we can detect unix paths by the presence of it
478+
if !path.contains('/') {
479+
return path.into();
480+
}
481+
482+
let win_path = build_helper::output(Command::new("cygpath").arg("-w").arg(path));
483+
let win_path = win_path.trim();
484+
485+
win_path.into()
486+
}
487+
457488
fn set<T>(field: &mut T, val: Option<T>) {
458489
if let Some(v) = val {
459490
*field = v;

src/bootstrap/config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
# Indicate whether submodules are managed and updated automatically.
8080
#submodules = true
8181

82+
# The path to (or name of) the GDB executable to use
83+
#gdb = "gdb"
84+
8285
# =============================================================================
8386
# Options for compiling Rust code itself
8487
# =============================================================================

src/bootstrap/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ pub struct Build {
123123
bootstrap_key_stage0: String,
124124

125125
// Probed tools at runtime
126-
gdb_version: Option<String>,
127126
lldb_version: Option<String>,
128127
lldb_python_dir: Option<String>,
129128

@@ -196,7 +195,6 @@ impl Build {
196195
package_vers: String::new(),
197196
cc: HashMap::new(),
198197
cxx: HashMap::new(),
199-
gdb_version: None,
200198
lldb_version: None,
201199
lldb_python_dir: None,
202200
}

src/bootstrap/sanity.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ pub fn check(build: &mut Build) {
9292
need_cmd(s.as_ref());
9393
}
9494

95+
if let Some(ref gdb) = build.config.gdb {
96+
need_cmd(gdb.as_ref());
97+
} else {
98+
build.config.gdb = have_cmd("gdb".as_ref());
99+
}
100+
95101
// We're gonna build some custom C code here and there, host triples
96102
// also build some C++ shims for LLVM so we need a C++ compiler.
97103
for target in build.config.target.iter() {
@@ -198,7 +204,6 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
198204
.to_string()
199205
})
200206
};
201-
build.gdb_version = run(Command::new("gdb").arg("--version")).ok();
202207
build.lldb_version = run(Command::new("lldb").arg("--version")).ok();
203208
if build.lldb_version.is_some() {
204209
build.lldb_python_dir = run(Command::new("lldb").arg("-P")).ok();

src/bootstrap/util.rs

+18
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,21 @@ pub fn dylib_path() -> Vec<PathBuf> {
172172
env::split_paths(&env::var_os(dylib_path_var()).unwrap_or(OsString::new()))
173173
.collect()
174174
}
175+
176+
/// `push` all components to `buf`. On windows, append `.exe` to the last component.
177+
pub fn push_exe_path(mut buf: PathBuf, components: &[&str]) -> PathBuf {
178+
let (&file, components) = components.split_last().expect("at least one component required");
179+
let mut file = file.to_owned();
180+
181+
if cfg!(windows) {
182+
file.push_str(".exe");
183+
}
184+
185+
for c in components {
186+
buf.push(c);
187+
}
188+
189+
buf.push(file);
190+
191+
buf
192+
}

src/test/debuginfo/associated-types.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// gdb-command:run
1717

1818
// gdb-command:print arg
19-
// gdb-check:$1 = {b = -1, b1 = 0}
19+
// gdbg-check:$1 = {b = -1, b1 = 0}
20+
// gdbr-check:$1 = associated_types::Struct<i32> {b: -1, b1: 0}
2021
// gdb-command:continue
2122

2223
// gdb-command:print inferred
@@ -30,7 +31,8 @@
3031
// gdb-command:continue
3132

3233
// gdb-command:print arg
33-
// gdb-check:$5 = {__0 = 4, __1 = 5}
34+
// gdbg-check:$5 = {__0 = 4, __1 = 5}
35+
// gdbr-check:$5 = (4, 5)
3436
// gdb-command:continue
3537

3638
// gdb-command:print a

src/test/debuginfo/basic-types-globals-metadata.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,47 @@
1212

1313
// compile-flags:-g
1414
// gdb-command:run
15-
// gdb-command:whatis 'basic_types_globals_metadata::B'
15+
// gdbg-command:whatis 'basic_types_globals_metadata::B'
16+
// gdbr-command:whatis basic_types_globals_metadata::B
1617
// gdb-check:type = bool
17-
// gdb-command:whatis 'basic_types_globals_metadata::I'
18+
// gdbg-command:whatis 'basic_types_globals_metadata::I'
19+
// gdbr-command:whatis basic_types_globals_metadata::I
1820
// gdb-check:type = isize
19-
// gdb-command:whatis 'basic_types_globals_metadata::C'
21+
// gdbg-command:whatis 'basic_types_globals_metadata::C'
22+
// gdbr-command:whatis basic_types_globals_metadata::C
2023
// gdb-check:type = char
21-
// gdb-command:whatis 'basic_types_globals_metadata::I8'
24+
// gdbg-command:whatis 'basic_types_globals_metadata::I8'
25+
// gdbr-command:whatis basic_types_globals_metadata::I8
2226
// gdb-check:type = i8
23-
// gdb-command:whatis 'basic_types_globals_metadata::I16'
27+
// gdbg-command:whatis 'basic_types_globals_metadata::I16'
28+
// gdbr-command:whatis basic_types_globals_metadata::I16
2429
// gdb-check:type = i16
25-
// gdb-command:whatis 'basic_types_globals_metadata::I32'
30+
// gdbg-command:whatis 'basic_types_globals_metadata::I32'
31+
// gdbr-command:whatis basic_types_globals_metadata::I32
2632
// gdb-check:type = i32
27-
// gdb-command:whatis 'basic_types_globals_metadata::I64'
33+
// gdbg-command:whatis 'basic_types_globals_metadata::I64'
34+
// gdbr-command:whatis basic_types_globals_metadata::I64
2835
// gdb-check:type = i64
29-
// gdb-command:whatis 'basic_types_globals_metadata::U'
36+
// gdbg-command:whatis 'basic_types_globals_metadata::U'
37+
// gdbr-command:whatis basic_types_globals_metadata::U
3038
// gdb-check:type = usize
31-
// gdb-command:whatis 'basic_types_globals_metadata::U8'
39+
// gdbg-command:whatis 'basic_types_globals_metadata::U8'
40+
// gdbr-command:whatis basic_types_globals_metadata::U8
3241
// gdb-check:type = u8
33-
// gdb-command:whatis 'basic_types_globals_metadata::U16'
42+
// gdbg-command:whatis 'basic_types_globals_metadata::U16'
43+
// gdbr-command:whatis basic_types_globals_metadata::U16
3444
// gdb-check:type = u16
35-
// gdb-command:whatis 'basic_types_globals_metadata::U32'
45+
// gdbg-command:whatis 'basic_types_globals_metadata::U32'
46+
// gdbr-command:whatis basic_types_globals_metadata::U32
3647
// gdb-check:type = u32
37-
// gdb-command:whatis 'basic_types_globals_metadata::U64'
48+
// gdbg-command:whatis 'basic_types_globals_metadata::U64'
49+
// gdbr-command:whatis basic_types_globals_metadata::U64
3850
// gdb-check:type = u64
39-
// gdb-command:whatis 'basic_types_globals_metadata::F32'
51+
// gdbg-command:whatis 'basic_types_globals_metadata::F32'
52+
// gdbr-command:whatis basic_types_globals_metadata::F32
4053
// gdb-check:type = f32
41-
// gdb-command:whatis 'basic_types_globals_metadata::F64'
54+
// gdbg-command:whatis 'basic_types_globals_metadata::F64'
55+
// gdbr-command:whatis basic_types_globals_metadata::F64
4256
// gdb-check:type = f64
4357
// gdb-command:continue
4458

0 commit comments

Comments
 (0)