Skip to content

Commit 21a0d52

Browse files
committed
auto merge of #4876 : brson/rust/debuginfo, r=brson
Update of #4862
2 parents 210fa2d + 79e9b6d commit 21a0d52

File tree

8 files changed

+178
-13
lines changed

8 files changed

+178
-13
lines changed

configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ probe CFG_PDFLATEX pdflatex
394394
probe CFG_XETEX xetex
395395
probe CFG_LUATEX luatex
396396
probe CFG_NODE nodejs node
397+
probe CFG_GDB gdb
397398
if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
398399
then
399400
probe CFG_PAXCTL paxctl /sbin/paxctl
@@ -619,6 +620,7 @@ do
619620
make_dir $h/test/bench
620621
make_dir $h/test/perf
621622
make_dir $h/test/pretty
623+
make_dir $h/test/debug-info
622624
make_dir $h/test/doc-tutorial
623625
make_dir $h/test/doc-tutorial-ffi
624626
make_dir $h/test/doc-tutorial-macros

mk/tests.mk

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ cleantestlibs:
103103
-name '*.dSYM' -o \
104104
-name '*.libaux' -o \
105105
-name '*.out' -o \
106-
-name '*.err' \
106+
-name '*.err' -o \
107+
-name '*.debugger.script' \
107108
| xargs rm -rf
108109

109110

@@ -170,6 +171,7 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
170171
check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
171172
check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
172173
check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
174+
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
173175
check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
174176
check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
175177

@@ -284,6 +286,7 @@ CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
284286
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
285287
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
286288
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
289+
DEBUGINFO_RS := $(wildcard $(S)src/test/debug-info/*.rs)
287290

288291
# perf tests are the same as bench tests only they run under
289292
# a performance monitor.
@@ -296,6 +299,7 @@ CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
296299
BENCH_TESTS := $(BENCH_RS)
297300
PERF_TESTS := $(PERF_RS)
298301
PRETTY_TESTS := $(PRETTY_RS)
302+
DEBUGINFO_TESTS := $(DEBUGINFO_RS)
299303

300304
CTEST_SRC_BASE_rpass = run-pass
301305
CTEST_BUILD_BASE_rpass = run-pass
@@ -327,6 +331,15 @@ CTEST_BUILD_BASE_perf = perf
327331
CTEST_MODE_perf = run-pass
328332
CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
329333

334+
CTEST_SRC_BASE_debuginfo = debug-info
335+
CTEST_BUILD_BASE_debuginfo = debug-info
336+
CTEST_MODE_debuginfo = debug-info
337+
CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)
338+
339+
ifeq ($(CFG_GDB),)
340+
CTEST_DISABLE_debuginfo = "no gdb found"
341+
endif
342+
330343
define DEF_CTEST_VARS
331344

332345
# All the per-stage build rules you might want to call from the
@@ -349,7 +362,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
349362
--rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X) \
350363
--aux-base $$(S)src/test/auxiliary/ \
351364
--stage-id stage$(1)-$(2) \
352-
--rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2)" \
365+
--rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2)" \
353366
$$(CTEST_TESTARGS)
354367

355368
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
@@ -358,6 +371,7 @@ CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
358371
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
359372
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
360373
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
374+
CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)
361375

362376
endef
363377

@@ -377,6 +391,8 @@ CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
377391

378392
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
379393

394+
ifeq ($$(CTEST_DISABLE_$(4)),)
395+
380396
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
381397
$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
382398
$$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
@@ -386,9 +402,20 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
386402
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
387403
&& touch $$@
388404

405+
else
406+
407+
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
408+
$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
409+
$$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
410+
@$$(call E, run $(4): $$<)
411+
@$$(call E, warning: tests disabled: $$(CTEST_DISABLE_$(4)))
412+
touch $$@
413+
414+
endif
415+
389416
endef
390417

391-
CTEST_NAMES = rpass rpass-full rfail cfail bench perf
418+
CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo
392419

393420
$(foreach host,$(CFG_TARGET_TRIPLES), \
394421
$(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
@@ -496,6 +523,7 @@ TEST_GROUPS = \
496523
cfail \
497524
bench \
498525
perf \
526+
debuginfo \
499527
doc \
500528
$(foreach docname,$(DOC_TEST_NAMES),$(docname)) \
501529
pretty \

src/compiletest/common.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
1+
// Copyright 2012-2013 The Rust Project Developers. See the
2+
// COPYRIGHT file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
55
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@@ -18,6 +18,7 @@ pub enum mode {
1818
mode_run_fail,
1919
mode_run_pass,
2020
mode_pretty,
21+
mode_debug_info,
2122
}
2223

2324
pub type config = {

src/compiletest/compiletest.rc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use common::mode_run_pass;
4141
use common::mode_run_fail;
4242
use common::mode_compile_fail;
4343
use common::mode_pretty;
44+
use common::mode_debug_info;
4445
use common::mode;
4546
use util::logv;
4647

@@ -131,6 +132,7 @@ pub fn str_mode(s: ~str) -> mode {
131132
~"run-fail" => mode_run_fail,
132133
~"run-pass" => mode_run_pass,
133134
~"pretty" => mode_pretty,
135+
~"debug-info" => mode_debug_info,
134136
_ => die!(~"invalid mode")
135137
}
136138
}
@@ -140,7 +142,8 @@ pub fn mode_str(mode: mode) -> ~str {
140142
mode_compile_fail => ~"compile-fail",
141143
mode_run_fail => ~"run-fail",
142144
mode_run_pass => ~"run-pass",
143-
mode_pretty => ~"pretty"
145+
mode_pretty => ~"pretty",
146+
mode_debug_info => ~"debug-info",
144147
}
145148
}
146149

src/compiletest/header.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
1+
// Copyright 2012-2013 The Rust Project Developers. See the
2+
// COPYRIGHT file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
55
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@@ -28,7 +28,11 @@ pub struct TestProps {
2828
// Modules from aux directory that should be compiled
2929
aux_builds: ~[~str],
3030
// Environment settings to use during execution
31-
exec_env: ~[(~str,~str)]
31+
exec_env: ~[(~str,~str)],
32+
// Commands to be given to the debugger, when testing debug info
33+
debugger_cmds: ~[~str],
34+
// Lines to check if they appear in the expected debugger output
35+
check_lines: ~[~str],
3236
}
3337

3438
// Load any test directives embedded in the file
@@ -38,6 +42,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
3842
let mut exec_env = ~[];
3943
let mut compile_flags = None;
4044
let mut pp_exact = None;
45+
let mut debugger_cmds = ~[];
46+
let mut check_lines = ~[];
4147
for iter_header(testfile) |ln| {
4248
match parse_error_pattern(ln) {
4349
Some(ep) => error_patterns.push(ep),
@@ -59,13 +65,25 @@ pub fn load_props(testfile: &Path) -> TestProps {
5965
do parse_exec_env(ln).iter |ee| {
6066
exec_env.push(*ee);
6167
}
68+
69+
match parse_debugger_cmd(ln) {
70+
Some(dc) => debugger_cmds.push(dc),
71+
None => ()
72+
};
73+
74+
match parse_check_line(ln) {
75+
Some(cl) => check_lines.push(cl),
76+
None => ()
77+
};
6278
};
6379
return TestProps {
6480
error_patterns: error_patterns,
6581
compile_flags: compile_flags,
6682
pp_exact: pp_exact,
6783
aux_builds: aux_builds,
68-
exec_env: exec_env
84+
exec_env: exec_env,
85+
debugger_cmds: debugger_cmds,
86+
check_lines: check_lines
6987
};
7088
}
7189

@@ -112,6 +130,14 @@ fn parse_compile_flags(line: ~str) -> Option<~str> {
112130
parse_name_value_directive(line, ~"compile-flags")
113131
}
114132

133+
fn parse_debugger_cmd(line: ~str) -> Option<~str> {
134+
parse_name_value_directive(line, ~"debugger")
135+
}
136+
137+
fn parse_check_line(line: ~str) -> Option<~str> {
138+
parse_name_value_directive(line, ~"check")
139+
}
140+
115141
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
116142
do parse_name_value_directive(line, ~"exec-env").map |nv| {
117143
// nv is either FOO or FOO=BAR

src/compiletest/runtest.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
1+
// Copyright 2012-2013 The Rust Project Developers. See the
2+
// COPYRIGHT file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
55
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@@ -39,11 +39,13 @@ pub fn run(config: config, testfile: ~str) {
3939
let testfile = Path(testfile);
4040
debug!("running %s", testfile.to_str());
4141
let props = load_props(&testfile);
42+
debug!("loaded props");
4243
match config.mode {
4344
mode_compile_fail => run_cfail_test(config, props, &testfile),
4445
mode_run_fail => run_rfail_test(config, props, &testfile),
4546
mode_run_pass => run_rpass_test(config, props, &testfile),
46-
mode_pretty => run_pretty_test(config, props, &testfile)
47+
mode_pretty => run_pretty_test(config, props, &testfile),
48+
mode_debug_info => run_debuginfo_test(config, props, &testfile)
4749
}
4850
}
4951

@@ -224,6 +226,55 @@ actual:\n\
224226
}
225227
}
226228

229+
fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
230+
// compile test file (it shoud have 'compile-flags:-g' in the header)
231+
let mut ProcRes = compile_test(config, props, testfile);
232+
if ProcRes.status != 0 {
233+
fatal_ProcRes(~"compilation failed!", ProcRes);
234+
}
235+
236+
// write debugger script
237+
let script_str = str::append(str::connect(props.debugger_cmds, "\n"),
238+
~"\nquit\n");
239+
debug!("script_str = %s", script_str);
240+
dump_output_file(config, testfile, script_str, ~"debugger.script");
241+
242+
// run debugger script with gdb
243+
#[cfg(windows)]
244+
fn debugger() -> ~str { ~"gdb.exe" }
245+
#[cfg(unix)]
246+
fn debugger() -> ~str { ~"gdb" }
247+
let debugger_script = make_out_name(config, testfile, ~"debugger.script");
248+
let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx",
249+
~"-command=" + debugger_script.to_str(),
250+
make_exe_name(config, testfile).to_str()];
251+
let ProcArgs = ProcArgs {prog: debugger(), args: debugger_opts};
252+
ProcRes = compose_and_run(config, testfile, ProcArgs, ~[], ~"", None);
253+
if ProcRes.status != 0 {
254+
fatal(~"gdb failed to execute");
255+
}
256+
257+
let num_check_lines = vec::len(props.check_lines);
258+
if num_check_lines > 0 {
259+
// check if each line in props.check_lines appears in the
260+
// output (in order)
261+
let mut i = 0u;
262+
for str::lines(ProcRes.stdout).each |line| {
263+
if props.check_lines[i].trim() == line.trim() {
264+
i += 1u;
265+
}
266+
if i == num_check_lines {
267+
// all lines checked
268+
break;
269+
}
270+
}
271+
if i != num_check_lines {
272+
fatal(fmt!("line not found in debugger output: %s",
273+
props.check_lines[i]));
274+
}
275+
}
276+
}
277+
227278
fn check_error_patterns(props: TestProps,
228279
testfile: &Path,
229280
ProcRes: ProcRes) {

src/test/debug-info/simple.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
// xfail-test
12+
// compile-flags:-g
13+
// debugger:break 20
14+
// debugger:run
15+
// debugger:print x
16+
// check:$1 = 42
17+
18+
fn main() {
19+
let x = 42;
20+
debug!("The answer is %d", x);
21+
}

src/test/debug-info/struct.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2013 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+
// xfail-test
12+
// compile-flags:-g
13+
// debugger:break 32
14+
// debugger:run
15+
// debugger:print pair
16+
// check:$1 = {
17+
// check:x = 1,
18+
// check:y = 2,
19+
// check:}
20+
// debugger:print pair.x
21+
// check:$2 = 1
22+
// debugger:print pair.y
23+
// check:$3 = 2
24+
25+
struct Pair {
26+
x: int,
27+
y: int
28+
}
29+
30+
fn main() {
31+
let pair = Pair { x: 1, y: 2 };
32+
debug!("x = %d, y = %d", pair.x, pair.y);
33+
}

0 commit comments

Comments
 (0)