Skip to content

Commit ab45dbf

Browse files
committed
Move several DWARF constants into their own submodule
The main advantage of doing this is that we can apply a single `#![allow(non_upper_case_globals)]` to the whole module, though it's also helpful when manually checking values against LLVM or the DWARF spec.
1 parent 1891c28 commit ab45dbf

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Definitions of various DWARF-related constants.
2+
//! These should agree with `llvm/include/llvm/BinaryFormat/Dwarf.def`.
3+
4+
#![allow(non_upper_case_globals)] // Allow names to match their LLVM equivalents
5+
6+
use libc::c_uint;
7+
8+
/// DWARF constant representing the Rust language. Introduced in DWARF 5.
9+
/// Defined by <http://www.dwarfstd.org/ShowIssue.php?issue=140129.1>.
10+
pub(crate) const DW_LANG_RUST: c_uint = 0x1c;
11+
12+
// DWARF attribute type encodings
13+
14+
pub(crate) const DW_ATE_boolean: c_uint = 0x02;
15+
pub(crate) const DW_ATE_float: c_uint = 0x04;
16+
pub(crate) const DW_ATE_signed: c_uint = 0x05;
17+
pub(crate) const DW_ATE_unsigned: c_uint = 0x07;
18+
pub(crate) const DW_ATE_UTF: c_uint = 0x10;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_target::spec::DebuginfoKind;
2222
use smallvec::smallvec;
2323
use tracing::{debug, instrument};
2424

25+
pub(crate) use self::type_map::TypeMap;
2526
use self::type_map::{DINodeCreationResult, Stub, UniqueTypeId};
2627
use super::CodegenUnitDebugContext;
2728
use super::namespace::mangled_name_of_instance;
@@ -30,6 +31,7 @@ use super::utils::{
3031
DIB, create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit,
3132
};
3233
use crate::common::{AsCCharPtr, CodegenCx};
34+
use crate::debuginfo::dwarf_const;
3335
use crate::debuginfo::metadata::type_map::build_type_with_children;
3436
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
3537
use crate::llvm::debuginfo::{
@@ -59,20 +61,6 @@ impl fmt::Debug for llvm::Metadata {
5961
}
6062
}
6163

62-
// From DWARF 5.
63-
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1.
64-
const DW_LANG_RUST: c_uint = 0x1c;
65-
#[allow(non_upper_case_globals)]
66-
const DW_ATE_boolean: c_uint = 0x02;
67-
#[allow(non_upper_case_globals)]
68-
const DW_ATE_float: c_uint = 0x04;
69-
#[allow(non_upper_case_globals)]
70-
const DW_ATE_signed: c_uint = 0x05;
71-
#[allow(non_upper_case_globals)]
72-
const DW_ATE_unsigned: c_uint = 0x07;
73-
#[allow(non_upper_case_globals)]
74-
const DW_ATE_UTF: c_uint = 0x10;
75-
7664
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0;
7765
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
7866

@@ -87,8 +75,6 @@ type SmallVec<T> = smallvec::SmallVec<[T; 16]>;
8775
mod enums;
8876
mod type_map;
8977

90-
pub(crate) use type_map::TypeMap;
91-
9278
/// Returns from the enclosing function if the type debuginfo node with the given
9379
/// unique ID can be found in the type map.
9480
macro_rules! return_if_di_node_created_in_meantime {
@@ -519,7 +505,7 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D
519505
name.as_c_char_ptr(),
520506
name.len(),
521507
cx.tcx.data_layout.pointer_size.bits(),
522-
DW_ATE_unsigned,
508+
dwarf_const::DW_ATE_unsigned,
523509
)
524510
}
525511
})
@@ -778,6 +764,8 @@ fn build_basic_type_di_node<'ll, 'tcx>(
778764
// .natvis visualizers (and perhaps other existing native debuggers?)
779765
let cpp_like_debuginfo = cpp_like_debuginfo(cx.tcx);
780766

767+
use dwarf_const::{DW_ATE_UTF, DW_ATE_boolean, DW_ATE_float, DW_ATE_signed, DW_ATE_unsigned};
768+
781769
let (name, encoding) = match t.kind() {
782770
ty::Never => ("!", DW_ATE_unsigned),
783771
ty::Tuple(elements) if elements.is_empty() => {
@@ -958,7 +946,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
958946

959947
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
960948
debug_context.builder,
961-
DW_LANG_RUST,
949+
dwarf_const::DW_LANG_RUST,
962950
compile_unit_file,
963951
producer.as_c_char_ptr(),
964952
producer.len(),

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::llvm::debuginfo::{
3939
use crate::value::Value;
4040

4141
mod create_scope_map;
42+
mod dwarf_const;
4243
mod gdb;
4344
pub(crate) mod metadata;
4445
mod namespace;

0 commit comments

Comments
 (0)