
There are several cases where names of types and functions in the debug info are either ambiguous, or not helpful, such as including ambiguous placeholders (e.g., `{{impl}}`, `{{closure}}` or `dyn _'`) or dropping qualifications (e.g., for dynamic types). Instead, each debug symbol name should be unique and useful: * Include disambiguators for anonymous `DefPathDataName` (closures and generators), and unify their formatting when used as a path-qualifier vs item being qualified. * Qualify the principal trait for dynamic types. * If there is no principal trait for a dynamic type, emit all other traits instead. * Respect the `qualified` argument when emitting ref and pointer types. * For implementations, emit the disambiguator. * Print const generics when emitting generic parameters or arguments. Additionally, when targeting MSVC, its debugger treats many command arguments as C++ expressions, even when the argument is defined to be a symbol name. As such names in the debug info need to be more C++-like to be parsed correctly: * Avoid characters with special meaning (`#`, `[`, `"`, `+`). * Never start a name with `<` or `{` as this is treated as an operator. * `>>` is always treated as a right-shift, even when parsing generic arguments (so add a space to avoid this). * Emit function declarations using C/C++ style syntax (e.g., leading return type). * Emit arrays as a synthetic `array$<type, size>` type. * Include a `$` in all synthetic types as this is a legal character for C++, but not Rust (thus we avoid collisions with user types).
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
// Namespace Handling.
|
|
|
|
use super::utils::{debug_context, DIB};
|
|
use rustc_codegen_ssa::debuginfo::type_names;
|
|
use rustc_middle::ty::{self, Instance};
|
|
|
|
use crate::common::CodegenCx;
|
|
use crate::llvm;
|
|
use crate::llvm::debuginfo::DIScope;
|
|
use rustc_hir::def_id::DefId;
|
|
|
|
pub fn mangled_name_of_instance<'a, 'tcx>(
|
|
cx: &CodegenCx<'a, 'tcx>,
|
|
instance: Instance<'tcx>,
|
|
) -> ty::SymbolName<'tcx> {
|
|
let tcx = cx.tcx;
|
|
tcx.symbol_name(instance)
|
|
}
|
|
|
|
pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
|
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
|
|
return scope;
|
|
}
|
|
|
|
let def_key = cx.tcx.def_key(def_id);
|
|
let parent_scope = def_key
|
|
.parent
|
|
.map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
|
|
|
|
let namespace_name_string = {
|
|
let mut output = String::new();
|
|
type_names::push_item_name(cx.tcx, def_id, false, &mut output);
|
|
output
|
|
};
|
|
|
|
let scope = unsafe {
|
|
llvm::LLVMRustDIBuilderCreateNameSpace(
|
|
DIB(cx),
|
|
parent_scope,
|
|
namespace_name_string.as_ptr().cast(),
|
|
namespace_name_string.len(),
|
|
false, // ExportSymbols (only relevant for C++ anonymous namespaces)
|
|
)
|
|
};
|
|
|
|
debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
|
|
scope
|
|
}
|