fn load_variables<'a>(
    dwarf: &gimli::Dwarf<EndianSlice<'a, RunTimeEndian>>,
    verbose: bool
) -> (HashMap<String, VarInfo>, UnitList<'a>) {
    let mut variables = HashMap::<String, VarInfo>::new();
    let mut unit_list = UnitList::new();

    let mut iter = dwarf.debug_info.units();
    while let Ok(Some(unit)) = iter.next() {
        let abbreviations = unit.abbreviations(&dwarf.debug_abbrev).unwrap();

        // the root of the tree inside of a unit is always a DW_TAG_compile_unit
        // the global variables are among the immediate children of the DW_TAG_compile_unit
        // static variable in functions are hidden further down inside of DW_TAG_subprogram[/DW_TAG_lexical_block]*
        // we can easily find all of them by using depth-first traversal of the tree
        let mut entries_cursor = unit.entries(&abbreviations);
        while let Ok(Some((_depth_delta, entry))) = entries_cursor.next_dfs() {
            if entry.tag() == gimli::constants::DW_TAG_variable {
                match get_global_variable(entry, &unit, &abbreviations, dwarf) {
                    Ok(Some((name, typeref, address))) => {
                        variables.insert(name, VarInfo{address, typeref});
                    }
                    Ok(None) => {
                        // unremarkable, the variable is not a global variable
                    }
                    Err(errmsg) => {
                        if verbose {
                            let offset = entry.offset().to_debug_info_offset(&unit).unwrap_or(gimli::DebugInfoOffset(0)).0;
                            println!("Error loading variable @{:x}: {}", offset, errmsg);
                        }
                    }
                }
            }
        }

        unit_list.add(unit, abbreviations);
    }

    (variables, unit_list)
}
// load all global variables from the dwarf data
load all global variables from the dwarf data
load all global variables from the dwarf data
fn load_variables<'a>(
    dwarf: &gimli::Dwarf<EndianSlice<'a, RunTimeEndian>>,
    verbose: bool
) -> (HashMap<String, VarInfo>, UnitList<'a>) {
    let mut variables = HashMap::<String, VarInfo>::new();
    let mut unit_list = UnitList::new();
    let mut iter = dwarf.debug_info.units();
    while let Ok(Some(unit)) = iter.next() {
        let abbreviations = unit.abbreviations(&dwarf.debug_abbrev).unwrap();
        // the root of the tree inside of a unit is always a DW_TAG_compile_unit
        // the global variables are among the immediate children of the DW_TAG_compile_unit
        // static variable in functions are hidden further down inside of DW_TAG_subprogram[/DW_TAG_lexical_block]*
        // we can easily find all of them by using depth-first traversal of the tree
        let mut entries_cursor = unit.entries(&abbreviations);
        while let Ok(Some((_depth_delta, entry))) = entries_cursor.next_dfs() {
            if entry.tag() == gimli::constants::DW_TAG_variable {
                match get_global_variable(entry, &unit, &abbreviations, dwarf) {
                    Ok(Some((name, typeref, address))) => {
                        variables.insert(name, VarInfo{address, typeref});
                    }
                    Ok(None) => {
                        // unremarkable, the variable is not a global variable
                    }
                    Err(errmsg) => {
                        if verbose {
                            let offset = entry.offset().to_debug_info_offset(&unit).unwrap_or(gimli::DebugInfoOffset(0)).0;
                            println!("Error loading variable @{:x}: {}", offset, errmsg);
                        }
                    }
                }
            }
        }
        unit_list.add(unit, abbreviations);
    }
    (variables, unit_list)
}
fn load_variables < ' a > ( dwarf : & gimli :: Dwarf < EndianSlice < ' a , RunTimeEndian > > , verbose : bool ) -> ( HashMap < String , VarInfo > , UnitList < ' a > ) { let mut variables = HashMap :: < String , VarInfo > :: new ( ) ; let mut unit_list = UnitList :: new ( ) ; let mut iter = dwarf . debug_info . units ( ) ; while let Ok ( Some ( unit ) ) = iter . next ( ) { let abbreviations = unit . abbreviations ( & dwarf . debug_abbrev ) . unwrap ( ) ; // the root of the tree inside of a unit is always a DW_TAG_compile_unit // the global variables are among the immediate children of the DW_TAG_compile_unit // static variable in functions are hidden further down inside of DW_TAG_subprogram[/DW_TAG_lexical_block]* // we can easily find all of them by using depth-first traversal of the tree let mut entries_cursor = unit . entries ( & abbreviations ) ; while let Ok ( Some ( ( _depth_delta , entry ) ) ) = entries_cursor . next_dfs ( ) { if entry . tag ( ) == gimli :: constants :: DW_TAG_variable { match get_global_variable ( entry , & unit , & abbreviations , dwarf ) { Ok ( Some ( ( name , typeref , address ) ) ) => { variables . insert ( name , VarInfo { address , typeref } ) ; } Ok ( None ) => { // unremarkable, the variable is not a global variable } Err ( errmsg ) => { if verbose { let offset = entry . offset ( ) . to_debug_info_offset ( & unit ) . unwrap_or ( gimli :: DebugInfoOffset ( 0 ) ) . 0 ; println ! ( " " offset errmsg ) ; } } } } } unit_list . add ( unit , abbreviations ) ; } ( variables , unit_list ) }
load all global variables from the dwarf data
load all global variables from the dwarf data
dwarf
&gimli::Dwarf<EndianSlice<'a, RunTimeEndian>>
verbose
bool