Skip to content

Commit 482823f

Browse files
committed
read/line: move LineInstruction Display impl to dwarfdump
This is specific to dwarfdump, and will need further changes there.
1 parent 159f3cf commit 482823f

File tree

2 files changed

+56
-55
lines changed

2 files changed

+56
-55
lines changed

crates/examples/src/bin/dwarfdump.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,62 @@ fn dump_line_program<R: Reader, W: Write>(w: &mut W, unit: gimli::UnitRef<R>) ->
20162016
writeln!(w, "Line Number Instructions:")?;
20172017
let mut instructions = header.instructions();
20182018
while let Some(instruction) = instructions.next_instruction(header)? {
2019-
writeln!(w, " {}", instruction)?;
2019+
use gimli::{constants, LineInstruction};
2020+
write!(w, " ")?;
2021+
match instruction {
2022+
LineInstruction::Special(opcode) => write!(w, "Special opcode {}", opcode),
2023+
LineInstruction::Copy => write!(w, "{}", constants::DW_LNS_copy),
2024+
LineInstruction::AdvancePc(advance) => {
2025+
write!(w, "{} by {}", constants::DW_LNS_advance_pc, advance)
2026+
}
2027+
LineInstruction::AdvanceLine(increment) => {
2028+
write!(w, "{} by {}", constants::DW_LNS_advance_line, increment)
2029+
}
2030+
LineInstruction::SetFile(file) => {
2031+
write!(w, "{} to {}", constants::DW_LNS_set_file, file)
2032+
}
2033+
LineInstruction::SetColumn(column) => {
2034+
write!(w, "{} to {}", constants::DW_LNS_set_column, column)
2035+
}
2036+
LineInstruction::NegateStatement => {
2037+
write!(w, "{}", constants::DW_LNS_negate_stmt)
2038+
}
2039+
LineInstruction::SetBasicBlock => {
2040+
write!(w, "{}", constants::DW_LNS_set_basic_block)
2041+
}
2042+
LineInstruction::ConstAddPc => write!(w, "{}", constants::DW_LNS_const_add_pc),
2043+
LineInstruction::FixedAddPc(advance) => {
2044+
write!(w, "{} by {}", constants::DW_LNS_fixed_advance_pc, advance)
2045+
}
2046+
LineInstruction::SetPrologueEnd => {
2047+
write!(w, "{}", constants::DW_LNS_set_prologue_end)
2048+
}
2049+
LineInstruction::SetEpilogueBegin => {
2050+
write!(w, "{}", constants::DW_LNS_set_epilogue_begin)
2051+
}
2052+
LineInstruction::SetIsa(isa) => {
2053+
write!(w, "{} to {}", constants::DW_LNS_set_isa, isa)
2054+
}
2055+
LineInstruction::UnknownStandard0(opcode) => write!(w, "Unknown {}", opcode),
2056+
LineInstruction::UnknownStandard1(opcode, arg) => {
2057+
write!(w, "Unknown {} with operand {}", opcode, arg)
2058+
}
2059+
LineInstruction::UnknownStandardN(opcode, ref args) => {
2060+
write!(w, "Unknown {} with operands {:?}", opcode, args)
2061+
}
2062+
LineInstruction::EndSequence => write!(w, "{}", constants::DW_LNE_end_sequence),
2063+
LineInstruction::SetAddress(address) => {
2064+
write!(w, "{} to {}", constants::DW_LNE_set_address, address)
2065+
}
2066+
LineInstruction::DefineFile(_) => {
2067+
write!(w, "{}", constants::DW_LNE_define_file)
2068+
}
2069+
LineInstruction::SetDiscriminator(discr) => {
2070+
write!(w, "{} to {}", constants::DW_LNE_set_discriminator, discr)
2071+
}
2072+
LineInstruction::UnknownExtended(opcode, _) => write!(w, "Unknown {}", opcode),
2073+
}?;
2074+
writeln!(w)?;
20202075
}
20212076

20222077
writeln!(w)?;

src/read/line.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use alloc::vec::Vec;
2-
use core::fmt;
32
use core::num::{NonZeroU64, Wrapping};
4-
use core::result;
53

64
use crate::common::{
75
DebugLineOffset, DebugLineStrOffset, DebugStrOffset, DebugStrOffsetsIndex, Encoding, Format,
@@ -518,58 +516,6 @@ where
518516
}
519517
}
520518

521-
impl<R, Offset> fmt::Display for LineInstruction<R, Offset>
522-
where
523-
R: Reader<Offset = Offset>,
524-
Offset: ReaderOffset,
525-
{
526-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
527-
match *self {
528-
LineInstruction::Special(opcode) => write!(f, "Special opcode {}", opcode),
529-
LineInstruction::Copy => write!(f, "{}", constants::DW_LNS_copy),
530-
LineInstruction::AdvancePc(advance) => {
531-
write!(f, "{} by {}", constants::DW_LNS_advance_pc, advance)
532-
}
533-
LineInstruction::AdvanceLine(increment) => {
534-
write!(f, "{} by {}", constants::DW_LNS_advance_line, increment)
535-
}
536-
LineInstruction::SetFile(file) => {
537-
write!(f, "{} to {}", constants::DW_LNS_set_file, file)
538-
}
539-
LineInstruction::SetColumn(column) => {
540-
write!(f, "{} to {}", constants::DW_LNS_set_column, column)
541-
}
542-
LineInstruction::NegateStatement => write!(f, "{}", constants::DW_LNS_negate_stmt),
543-
LineInstruction::SetBasicBlock => write!(f, "{}", constants::DW_LNS_set_basic_block),
544-
LineInstruction::ConstAddPc => write!(f, "{}", constants::DW_LNS_const_add_pc),
545-
LineInstruction::FixedAddPc(advance) => {
546-
write!(f, "{} by {}", constants::DW_LNS_fixed_advance_pc, advance)
547-
}
548-
LineInstruction::SetPrologueEnd => write!(f, "{}", constants::DW_LNS_set_prologue_end),
549-
LineInstruction::SetEpilogueBegin => {
550-
write!(f, "{}", constants::DW_LNS_set_epilogue_begin)
551-
}
552-
LineInstruction::SetIsa(isa) => write!(f, "{} to {}", constants::DW_LNS_set_isa, isa),
553-
LineInstruction::UnknownStandard0(opcode) => write!(f, "Unknown {}", opcode),
554-
LineInstruction::UnknownStandard1(opcode, arg) => {
555-
write!(f, "Unknown {} with operand {}", opcode, arg)
556-
}
557-
LineInstruction::UnknownStandardN(opcode, ref args) => {
558-
write!(f, "Unknown {} with operands {:?}", opcode, args)
559-
}
560-
LineInstruction::EndSequence => write!(f, "{}", constants::DW_LNE_end_sequence),
561-
LineInstruction::SetAddress(address) => {
562-
write!(f, "{} to {}", constants::DW_LNE_set_address, address)
563-
}
564-
LineInstruction::DefineFile(_) => write!(f, "{}", constants::DW_LNE_define_file),
565-
LineInstruction::SetDiscriminator(discr) => {
566-
write!(f, "{} to {}", constants::DW_LNE_set_discriminator, discr)
567-
}
568-
LineInstruction::UnknownExtended(opcode, _) => write!(f, "Unknown {}", opcode),
569-
}
570-
}
571-
}
572-
573519
/// Deprecated. `OpcodesIter` has been renamed to `LineInstructions`.
574520
#[deprecated(note = "OpcodesIter has been renamed to LineInstructions, use that instead.")]
575521
pub type OpcodesIter<R> = LineInstructions<R>;

0 commit comments

Comments
 (0)