Skip to content

DwarfLines

Description

Parsed .debug_line content. Entries are flat and sorted-by- address per the line-number program’s natural emission order inside each compilation unit. Lookups do a linear scan across all CUs.

Fields

Name Description
allocator Allocator backing entries + string_pool.
entries All (address, file, line, …) rows, in CU / program order.
string_pool Owned buffer holding the file / directory strings that entries borrows from. Required because .debug_line file/dir entries are interleaved byte-strings inside the section — we copy them into a contiguous pool so the ElfFile’s lifetime doesn’t have to match ours.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        DwarfLines lines;
        bool       built = DwarfLinesBuildFromElf(&lines, &elf, ALLOCATOR_OF(&alloc));
        bool       ok    = built && lines.entries.length > 0;
        }
    
        DwarfLines lines;
        bool       built = DwarfLinesBuildFromElf(&lines, &elf, base);
        bool       ok    = false;
    
    static bool lnp_emit(
        DwarfLines      *out,
        Str             *pool,
        const CuStrings *cs,
        const LineProgHeader *hdr,
        const CuStrings      *cs,
        DwarfLines           *out,
        U64Vec               *pending_file_offsets,
        U64Vec               *pending_dir_offsets
    // ---------------------------------------------------------------------------
    
    bool DwarfLinesBuildFromElf(DwarfLines *out, const ElfFile *elf, Allocator *alloc) {
        if (!out || !elf || !alloc) {
            LOG_ERROR("DwarfLinesBuildFromElf: NULL argument");
    }
    
    void DwarfLinesDeinit(DwarfLines *self) {
        if (!self)
            return;
    // ---------------------------------------------------------------------------
    
    const DwarfLineEntry *DwarfLinesResolve(const DwarfLines *self, u64 vaddr) {
        if (!self || self->entries.length == 0)
            return NULL;
        ElfFile     elf;
    #if MISRA_HAVE_PARSER_DWARF
        DwarfLines dwarf;
        bool       dwarf_built;
        bool       dwarf_ok;
        DwarfLineEntries entries;
        Str              string_pool;
    } DwarfLines;
    
    ///
    /// TAGS: Parser, DWARF, Lines
    ///
    bool DwarfLinesBuildFromElf(DwarfLines *out, const ElfFile *elf, Allocator *alloc);
    
    ///
    /// TAGS: Parser, DWARF, Lookup
    ///
    const DwarfLineEntry *DwarfLinesResolve(const DwarfLines *self, u64 vaddr);
    
    ///
    /// Release storage owned by a `DwarfLines`. Safe on a zeroed struct.
    ///
    void DwarfLinesDeinit(DwarfLines *self);
    
    #endif // MISRA_PARSERS_DWARF_H
Last updated on