Skip to content

Commit

Permalink
Rollup merge of rust-lang#126365 - Dirbaio:collapse-debuginfo-statics…
Browse files Browse the repository at this point in the history
…, r=workingjubilee

Honor collapse_debuginfo for statics.

fixes rust-lang#126363

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
  • Loading branch information
jieyouxu authored Jun 16, 2024
2 parents a033dab + b89a0a7 commit 1af0e6e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_middle::ty::{
};
use rustc_session::config::{self, DebugInfo, Lto};
use rustc_span::symbol::Symbol;
use rustc_span::FileName;
use rustc_span::{hygiene, FileName, DUMMY_SP};
use rustc_span::{FileNameDisplayPreference, SourceFile};
use rustc_symbol_mangling::typeid_for_trait_ref;
use rustc_target::abi::{Align, Size};
Expand Down Expand Up @@ -1306,7 +1306,7 @@ pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, glo
// We may want to remove the namespace scope if we're in an extern block (see
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
let var_scope = get_namespace_for_item(cx, def_id);
let span = tcx.def_span(def_id);
let span = hygiene::walk_chain_collapsed(tcx.def_span(def_id), DUMMY_SP);

let (file_metadata, line_number) = if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo());
Expand Down
24 changes: 24 additions & 0 deletions tests/debuginfo/collapse-debuginfo-static-external.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ ignore-lldb

// Test that static debug info is not collapsed with #[collapse_debuginfo(external)]

//@ compile-flags:-g

// === GDB TESTS ===================================================================================

// gdb-command:info line collapse_debuginfo_static_external::FOO
// gdb-check:[...]Line 15[...]

#[collapse_debuginfo(external)]
macro_rules! decl_foo {
() => {
static FOO: u32 = 0;
};
}

decl_foo!();

fn main() {
// prevent FOO from getting optimized out
std::hint::black_box(&FOO);
}
24 changes: 24 additions & 0 deletions tests/debuginfo/collapse-debuginfo-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ ignore-lldb

// Test that static debug info is collapsed with #[collapse_debuginfo(yes)]

//@ compile-flags:-g

// === GDB TESTS ===================================================================================

// gdb-command:info line collapse_debuginfo_static::FOO
// gdb-check:[...]Line 19[...]

#[collapse_debuginfo(yes)]
macro_rules! decl_foo {
() => {
static FOO: u32 = 0;
};
}

decl_foo!();

fn main() {
// prevent FOO from getting optimized out
std::hint::black_box(&FOO);
}

0 comments on commit 1af0e6e

Please sign in to comment.