Skip to content

Commit cafa475

Browse files
committed
auto merge of #16497 : michaelwoerister/rust/no_debug_attribute, r=pcwalton
Fixes #15332.
2 parents 406de8d + 910dd26 commit cafa475

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/librustc/lint/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ impl LintPass for UnusedAttribute {
579579
"packed",
580580
"static_assert",
581581
"thread_local",
582+
"no_debug",
582583

583584
// not used anywhere (!?) but apparently we want to keep them around
584585
"comment",

src/librustc/middle/trans/debuginfo.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ pub fn create_function_debug_context(cx: &CrateContext,
11281128

11291129
let (ident, fn_decl, generics, top_level_block, span, has_path) = match fnitem {
11301130
ast_map::NodeItem(ref item) => {
1131+
if contains_nodebug_attribute(item.attrs.as_slice()) {
1132+
return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
1133+
}
1134+
11311135
match item.node {
11321136
ast::ItemFn(fn_decl, _, _, ref generics, top_level_block) => {
11331137
(item.ident, fn_decl, generics, top_level_block, item.span, true)
@@ -1141,6 +1145,12 @@ pub fn create_function_debug_context(cx: &CrateContext,
11411145
ast_map::NodeImplItem(ref item) => {
11421146
match **item {
11431147
ast::MethodImplItem(ref method) => {
1148+
if contains_nodebug_attribute(method.attrs.as_slice()) {
1149+
return FunctionDebugContext {
1150+
repr: FunctionWithoutDebugInfo
1151+
};
1152+
}
1153+
11441154
(method.pe_ident(),
11451155
method.pe_fn_decl(),
11461156
method.pe_generics(),
@@ -1173,6 +1183,12 @@ pub fn create_function_debug_context(cx: &CrateContext,
11731183
ast_map::NodeTraitItem(ref trait_method) => {
11741184
match **trait_method {
11751185
ast::ProvidedMethod(ref method) => {
1186+
if contains_nodebug_attribute(method.attrs.as_slice()) {
1187+
return FunctionDebugContext {
1188+
repr: FunctionWithoutDebugInfo
1189+
};
1190+
}
1191+
11761192
(method.pe_ident(),
11771193
method.pe_fn_decl(),
11781194
method.pe_generics(),
@@ -3169,6 +3185,16 @@ fn set_debug_location(cx: &CrateContext, debug_location: DebugLocation) {
31693185
// Utility Functions
31703186
//=-----------------------------------------------------------------------------
31713187

3188+
fn contains_nodebug_attribute(attributes: &[ast::Attribute]) -> bool {
3189+
attributes.iter().any(|attr| {
3190+
let meta_item: &ast::MetaItem = &*attr.node.value;
3191+
match meta_item.node {
3192+
ast::MetaWord(ref value) => value.get() == "no_debug",
3193+
_ => false
3194+
}
3195+
})
3196+
}
3197+
31723198
/// Return codemap::Loc corresponding to the beginning of the span
31733199
fn span_start(cx: &CrateContext, span: Span) -> codemap::Loc {
31743200
cx.sess().codemap().lookup_char_pos(span.lo)
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2013-2014 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+
// ignore-android: FIXME(#10381)
12+
// ignore-lldb
13+
14+
// compile-flags:-g
15+
16+
// gdb-command:break 'no-debug-attribute.rs':32
17+
// gdb-command:break 'no-debug-attribute.rs':38
18+
// gdb-command:run
19+
20+
// gdb-command:info locals
21+
// gdb-check:No locals.
22+
// gdb-command:continue
23+
24+
// gdb-command:info locals
25+
// gdb-check:abc = 10
26+
// gdb-command:continue
27+
28+
#![allow(unused_variable)]
29+
30+
fn function_with_debuginfo() {
31+
let abc = 10u;
32+
return (); // #break
33+
}
34+
35+
#[no_debug]
36+
fn function_without_debuginfo() {
37+
let abc = -57i32;
38+
return (); // #break
39+
}
40+
41+
fn main() {
42+
function_without_debuginfo();
43+
function_with_debuginfo();
44+
}
45+

0 commit comments

Comments
 (0)