Improve debug info debug logging somewhat

This commit is contained in:
Sofia 2025-07-19 13:24:32 +03:00
parent e12d0be08b
commit a5bca6be82
2 changed files with 96 additions and 19 deletions

View File

@ -6,8 +6,13 @@ use std::{
}; };
use crate::{ use crate::{
CmpPredicate, Instr, InstructionData, TerminatorKind, builder::*, CmpPredicate, Instr, InstructionData, TerminatorKind,
debug_information::DebugLocationValue, builder::*,
debug_information::{
DebugBasicType, DebugLocation, DebugLocationValue, DebugMetadataHolder, DebugMetadataValue,
DebugProgramValue, DebugScopeValue, DebugSubprogramType, DebugTypeData, DebugTypeHolder,
DebugTypeValue,
},
}; };
impl Debug for Builder { impl Debug for Builder {
@ -80,15 +85,6 @@ impl Debug for InstructionData {
} }
} }
impl Debug for DebugLocationValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("DebugLocationValue")
.field(&self.0)
.field(&self.1)
.finish()
}
}
impl Debug for ModuleValue { impl Debug for ModuleValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "M[{:0>2}]", self.0) write!(f, "M[{:0>2}]", self.0)
@ -229,3 +225,84 @@ impl Debug for TerminatorKind {
} }
} }
} }
impl Debug for DebugTypeHolder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple(&format!("DebugTypeHolder {:?}", self.value))
.field(&self.data)
.finish()
}
}
impl Debug for DebugTypeData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Basic(basic) => Debug::fmt(basic, f),
Self::Subprogram(subprogram) => Debug::fmt(subprogram, f),
}
}
}
impl Debug for DebugBasicType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("BasicType")
.field(&self.name)
.field(&self.size_bits)
.field(&self.encoding)
.field(&self.flags)
.finish()
}
}
impl Debug for DebugSubprogramType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("Subprogram")
.field(&self.params)
.field(&self.flags)
.finish()
}
}
impl Debug for DebugMetadataValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Meta[{}]", self.0)
}
}
impl Debug for DebugScopeValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Scope[{}]",
self.0
.iter()
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join(", ")
)
}
}
impl Debug for DebugTypeValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Type[{}]", self.0)
}
}
impl Debug for DebugProgramValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Subprogram[{}]", self.0)
}
}
impl Debug for DebugLocationValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Value[{:?}][{}]", self.0, self.1)
}
}
impl Debug for DebugLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ln {}, col {}", self.line, self.column)
}
}

View File

@ -2,20 +2,20 @@ use std::{cell::RefCell, rc::Rc};
use crate::builder::InstructionValue; use crate::builder::InstructionValue;
#[derive(Debug, Clone, Hash, PartialEq, Eq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct DebugScopeValue(pub Vec<usize>); pub struct DebugScopeValue(pub Vec<usize>);
#[derive(Clone, Copy, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct DebugLocationValue(pub DebugProgramValue, pub usize); pub struct DebugLocationValue(pub DebugProgramValue, pub usize);
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct DebugTypeValue(pub usize); pub struct DebugTypeValue(pub usize);
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct DebugMetadataValue(pub usize); pub struct DebugMetadataValue(pub usize);
/// Represents either a subprogram, or the compilation context /// Represents either a subprogram, or the compilation context
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct DebugProgramValue(pub usize); pub struct DebugProgramValue(pub usize);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -39,7 +39,7 @@ pub struct DebugMetadataHolder {
pub(crate) data: DebugMetadata, pub(crate) data: DebugMetadata,
} }
#[derive(Debug, Clone)] #[derive(Clone)]
pub struct DebugTypeHolder { pub struct DebugTypeHolder {
pub(crate) value: DebugTypeValue, pub(crate) value: DebugTypeValue,
pub(crate) data: DebugTypeData, pub(crate) data: DebugTypeData,
@ -200,7 +200,7 @@ impl DebugInformation {
} }
} }
#[derive(Debug, Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub struct DebugLocation { pub struct DebugLocation {
pub line: u32, pub line: u32,
pub column: u32, pub column: u32,
@ -254,13 +254,13 @@ impl Default for DebugSubprogramOptionals {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DwarfFlags; pub struct DwarfFlags;
#[derive(Debug, Clone)] #[derive(Clone)]
pub enum DebugTypeData { pub enum DebugTypeData {
Basic(DebugBasicType), Basic(DebugBasicType),
Subprogram(DebugSubprogramTypeData), Subprogram(DebugSubprogramTypeData),
} }
#[derive(Debug, Clone)] #[derive(Clone)]
pub struct DebugBasicType { pub struct DebugBasicType {
pub name: String, pub name: String,
/// Size of the type. /// Size of the type.