Skip to content

Commit

Permalink
Complain if an elf file contains no debug info
Browse files Browse the repository at this point in the history
If an elf file was stripped of debug info, then a2ltool would previously
still accept it, and remove all data from the a2l file during an update.
Now an elf file without debug info is rejected.
  • Loading branch information
DanielT committed Oct 31, 2024
1 parent d8e028d commit f7f6bcf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/dwarf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ impl DebugData {
pub(crate) fn load(filename: &OsStr, verbose: bool) -> Result<Self, String> {
let filedata = load_filedata(filename)?;
let elffile = load_elf_file(&filename.to_string_lossy(), &filedata)?;

if elffile.sections().find(|section| section.name() == Ok(".debug_info")).is_none() {
return Err(format!("Error: {} does not contain DWARF2+ debug info. The section .debug_info is missing.", filename.to_string_lossy()));
}

let dwarf = load_dwarf(&elffile)?;

if !verify_dwarf_compile_units(&dwarf) {
return Err(format!("Error: {} does not contain DWARF2+ debug info - zero compile units contain debug info.", filename.to_string_lossy()));
}

let sections = get_elf_sections(&elffile);

let dbg_reader = DebugDataReader {
Expand Down Expand Up @@ -187,6 +196,17 @@ fn load_dwarf<'data>(
gimli::Dwarf::load(loader)
}

// verify that the dwarf data is valid
fn verify_dwarf_compile_units(dwarf: &gimli::Dwarf<SliceType>) -> bool {
let mut units_iter = dwarf.debug_info.units();
let mut units_count = 0;
while let Ok(Some(_)) = units_iter.next() {
units_count += 1;
}

units_count > 0
}

// get a section from the elf file.
// returns a slice referencing the section data if it exists, or an empty slice otherwise
fn get_file_section_reader<'data>(
Expand Down

0 comments on commit f7f6bcf

Please sign in to comment.