Skip to content

Commit 4053276

Browse files
committed
Auto merge of #38109 - tromey:main-subprogram, r=michaelwoerister
Emit DW_AT_main_subprogram This changes rustc to emit DW_AT_main_subprogram on the "main" program. This lets gdb suitably stop at the user's main in response to "start" (rather than the library's main, which is what happens currently). Fixes #32620 r? michaelwoerister
2 parents e7fc53b + b037c52 commit 4053276

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

src/librustc_llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ pub mod debuginfo {
468468
const FlagStaticMember = (1 << 12),
469469
const FlagLValueReference = (1 << 13),
470470
const FlagRValueReference = (1 << 14),
471+
const FlagMainSubprogram = (1 << 21),
471472
}
472473
}
473474
}

src/librustc_trans/debuginfo/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
257257
let function_name = CString::new(name).unwrap();
258258
let linkage_name = CString::new(linkage_name).unwrap();
259259

260+
let mut flags = DIFlags::FlagPrototyped;
261+
match *cx.sess().entry_fn.borrow() {
262+
Some((id, _)) => {
263+
if local_id == Some(id) {
264+
flags = flags | DIFlags::FlagMainSubprogram;
265+
}
266+
}
267+
None => {}
268+
};
269+
260270
let fn_metadata = unsafe {
261271
llvm::LLVMRustDIBuilderCreateFunction(
262272
DIB(cx),
@@ -269,7 +279,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
269279
is_local_to_unit,
270280
true,
271281
scope_line as c_uint,
272-
DIFlags::FlagPrototyped,
282+
flags,
273283
cx.sess().opts.optimize != config::OptLevel::No,
274284
llfn,
275285
template_parameters,

src/rustllvm/RustWrapper.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ enum class LLVMRustDIFlags : uint32_t {
352352
FlagStaticMember = (1 << 12),
353353
FlagLValueReference = (1 << 13),
354354
FlagRValueReference = (1 << 14),
355+
FlagMainSubprogram = (1 << 21),
355356
// Do not add values that are not supported by the minimum LLVM
356357
// version we support!
357358
};
@@ -438,6 +439,11 @@ static unsigned fromRust(LLVMRustDIFlags Flags) {
438439
if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) {
439440
Result |= DINode::DIFlags::FlagRValueReference;
440441
}
442+
#if LLVM_RUSTLLVM || LLVM_VERSION_GE(4, 0)
443+
if (isSet(Flags & LLVMRustDIFlags::FlagMainSubprogram)) {
444+
Result |= DINode::DIFlags::FlagMainSubprogram;
445+
}
446+
#endif
441447

442448
return Result;
443449
}

src/test/codegen/mainsubprogram.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
// The minimum LLVM version is set to 3.8, but really this test
12+
// depends on a patch that is was committed to upstream LLVM before
13+
// 4.0; and also backported to the Rust LLVM fork.
14+
15+
// ignore-tidy-linelength
16+
// ignore-windows
17+
// ignore-macos
18+
// min-llvm-version 3.8
19+
20+
// compile-flags: -g -C no-prepopulate-passes
21+
22+
// CHECK-LABEL: @main
23+
// CHECK: {{.*}}DISubprogram{{.*}}name: "main",{{.*}}DIFlagMainSubprogram{{.*}}
24+
25+
pub fn main() {
26+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 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+
// The minimum LLVM version is set to 3.8, but really this test
12+
// depends on a patch that is was committed to upstream LLVM before
13+
// 4.0; and also backported to the Rust LLVM fork.
14+
15+
// ignore-tidy-linelength
16+
// ignore-windows
17+
// ignore-macos
18+
// min-llvm-version 3.8
19+
20+
// compile-flags: -g -C no-prepopulate-passes
21+
22+
#![feature(start)]
23+
24+
// CHECK-LABEL: @main
25+
// CHECK: {{.*}}DISubprogram{{.*}}name: "start",{{.*}}DIFlagMainSubprogram{{.*}}
26+
27+
#[start]
28+
fn start(_: isize, _: *const *const u8) -> isize {
29+
return 0;
30+
}

0 commit comments

Comments
 (0)