Skip to content
DwarfFunctions

DwarfFunctions

Description

Function-name index built from .debug_info + .debug_abbrev (+ .debug_str for indirect names). Entries are sorted by low_pc to allow a binary-search lookup.

Fields

Name Description
allocator Allocator backing entries + string_pool.
entries Sorted-by-low_pc list of DwarfFunction rows.
string_pool Owned buffer holding function-name strings that entries.name borrows from. We copy because DWARF strings can come from either inline byte-strings or the separately-located .debug_str section.

Usage example (Cross-references)

Usage examples (Cross-references)
        // when .symtab and .dynsym yield no name. Built for both main and
        // sidecar if either lookup misses.
        DwarfFunctions functions;
        bool           functions_built;
        bool           functions_ok;
        bool           functions_built;
        bool           functions_ok;
        DwarfFunctions sidecar_functions;
        bool           sidecar_functions_built;
        bool           sidecar_functions_ok;
        Macho          dsym;
        bool           dsym_open;
        DwarfFunctions fns;
        bool           fns_built;
        bool           fns_ok;
        DwarfFunctionEntries entries;
        Str                  string_pool;
    } DwarfFunctions;
    
    ///
    ///
    bool DwarfFunctionsBuildFromSlices(
        DwarfFunctions *out,
        const u8       *info_bytes,
        u64             info_size,
    /// TAGS: Parser, DWARF, Lookup
    ///
    const DwarfFunction *DwarfFunctionsResolve(const DwarfFunctions *self, u64 vaddr);
    
    ///
    /// TAGS: Parser, DWARF, Cleanup
    ///
    void DwarfFunctionsDeinit(DwarfFunctions *self);
    
    #endif // MISRA_PARSERS_DWARF_H
    
    bool DwarfFunctionsBuildFromSlices(
        DwarfFunctions *out,
        const u8       *info_bytes,
        u64             info_size,
    }
    
    bool dwarf_functions_build_from_elf(DwarfFunctions *out, const Elf *elf, Allocator *alloc) {
        if (!out || !elf || !alloc) {
            LOG_FATAL("DwarfFunctionsBuildFromElf: NULL argument");
    }
    
    const DwarfFunction *DwarfFunctionsResolve(const DwarfFunctions *self, u64 vaddr) {
        if (!self || VecLen(&self->entries) == 0)
            return NULL;
    }
    
    void DwarfFunctionsDeinit(DwarfFunctions *self) {
        if (!self)
            return;
    
        // (4) DwarfFunctions on the stripped copy MUST find the name.
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromElf(&fns, &stripped, base);
        bool           ok    = false;
        }
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromElf(&fns, &elf, base);
        bool           ok    = false;
        u64 info_len = build_debug_info(info, 4, 0, 0x4000, 0x40, "widget_init");
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromSlices(&fns, info, info_len, kAbbrev, sizeof(kAbbrev), NULL, 0, base);
        bool           ok    = built && VecLen(&fns.entries) == 1;
        put_u32(info + 8, 0);
    
        DwarfFunctions fns;
        bool built = DwarfFunctionsBuildFromSlices(&fns, info, sizeof(info), kAbbrev, sizeof(kAbbrev), NULL, 0, base);
        bool ok    = !built; // rejected
        u64 info_len = build_debug_info(info, 4, 0, 0x4000, 0x40, "widget_init");
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromSlices(&fns, info, info_len, NULL, 0, NULL, 0, base);
        bool           ok    = !built;
        put_u32(info + 6, 0xdeadbeefu);
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromSlices(&fns, info, info_len, kAbbrev, sizeof(kAbbrev), NULL, 0, base);
        bool           ok    = !built;
        u64 info_len = build_debug_info(info, 4, 0x7fffff00u, 0x4000, 0x40, "widget_init");
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromSlices(&fns, info, info_len, kAbbrev, sizeof(kAbbrev), NULL, 0, base);
        bool           ok    = !built;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        DwarfFunctions fns;
        bool           built = DwarfFunctionsBuildFromSlices(&fns, NULL, 0, NULL, 0, NULL, 0, base);
        bool           ok    = built && VecLen(&fns.entries) == 0 && DwarfFunctionsResolve(&fns, 0x4000) == NULL;
Last updated on