fn parse_subprogram(
    dwarf: &Dwarf<EndianSlice<RunTimeEndian>>,
    entry: &DebuggingInformationEntry<EndianSlice<RunTimeEndian>>,
) -> Result<Option<Subprogram>> {
    let mut attrs = entry.attrs();

    let mut subprogram: Option<Subprogram> = None;
    let mut linkage_name: String = String::from("");
    let mut name: Option<String> = None;
    let mut low_pc: Option<u64> = None;
    let mut high_pc: Option<u64> = None;

    while let Some(attr) = attrs.next()? {
        if attr.name() == gimli::constants::DW_AT_low_pc {
            match attr.value() {
                AttributeValue::Addr(a) => low_pc = Some(a),
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_high_pc {
            match attr.value() {
                AttributeValue::Udata(a) => high_pc = Some(a),
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_name {
            match attr.value() {
                AttributeValue::DebugStrRef(offset) => {
                    let sub_name = dwarf
                        .string(offset)
                        .unwrap()
                        .to_string()
                        .unwrap()
                        .to_string();
                    // Ignore reserved functions
                    if !sub_name.starts_with("__") {
                        name = Some(sub_name);
                    }
                }
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_linkage_name {
            match attr.value() {
                AttributeValue::DebugStrRef(offset) => {
                    let sub_name = dwarf
                        .string(offset)
                        .unwrap()
                        .to_string()
                        .unwrap()
                        .to_string();
                    linkage_name = demangle(&sub_name).to_string();
                }
                _ => (),
            }
        }
    }

    match (name, low_pc, high_pc) {
        (Some(name), Some(low), Some(high)) => {
            subprogram = Some(Subprogram {
                name,
                linkage_name,
                low_pc: low,
                high_pc: low + high,
            })
        }
        _ => (),
    }

    Ok(subprogram)
}
/// Tries to parse a `DW_TAG_subprogram` in the current DWARF entry.
/// If the current entry is not a subprogram it will simply return `None`.
Tries to parse a `DW_TAG_subprogram` in the current DWARF entry.
If the current entry is not a subprogram it will simply return `None`.
Tries to parse a ` DW_TAG_subprogram ` in the current DWARF entry . If the current entry is not a subprogram it will simply return ` None ` .
fn parse_subprogram(
    dwarf: &Dwarf<EndianSlice<RunTimeEndian>>,
    entry: &DebuggingInformationEntry<EndianSlice<RunTimeEndian>>,
) -> Result<Option<Subprogram>> {
    let mut attrs = entry.attrs();
    let mut subprogram: Option<Subprogram> = None;
    let mut linkage_name: String = String::from("");
    let mut name: Option<String> = None;
    let mut low_pc: Option<u64> = None;
    let mut high_pc: Option<u64> = None;
    while let Some(attr) = attrs.next()? {
        if attr.name() == gimli::constants::DW_AT_low_pc {
            match attr.value() {
                AttributeValue::Addr(a) => low_pc = Some(a),
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_high_pc {
            match attr.value() {
                AttributeValue::Udata(a) => high_pc = Some(a),
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_name {
            match attr.value() {
                AttributeValue::DebugStrRef(offset) => {
                    let sub_name = dwarf
                        .string(offset)
                        .unwrap()
                        .to_string()
                        .unwrap()
                        .to_string();
                    // Ignore reserved functions
                    if !sub_name.starts_with("__") {
                        name = Some(sub_name);
                    }
                }
                _ => (),
            }
        } else if attr.name() == gimli::constants::DW_AT_linkage_name {
            match attr.value() {
                AttributeValue::DebugStrRef(offset) => {
                    let sub_name = dwarf
                        .string(offset)
                        .unwrap()
                        .to_string()
                        .unwrap()
                        .to_string();
                    linkage_name = demangle(&sub_name).to_string();
                }
                _ => (),
            }
        }
    }
    match (name, low_pc, high_pc) {
        (Some(name), Some(low), Some(high)) => {
            subprogram = Some(Subprogram {
                name,
                linkage_name,
                low_pc: low,
                high_pc: low + high,
            })
        }
        _ => (),
    }
    Ok(subprogram)
}
fn parse_subprogram ( dwarf : & Dwarf < EndianSlice < RunTimeEndian > > , entry : & DebuggingInformationEntry < EndianSlice < RunTimeEndian > > , ) -> Result < Option < Subprogram > > { let mut attrs = entry . attrs ( ) ; let mut subprogram : Option < Subprogram > = None ; let mut linkage_name : String = String :: from ( " " ) ; let mut name : Option < String > = None ; let mut low_pc : Option < u64 > = None ; let mut high_pc : Option < u64 > = None ; while let Some ( attr ) = attrs . next ( ) ? { if attr . name ( ) == gimli :: constants :: DW_AT_low_pc { match attr . value ( ) { AttributeValue :: Addr ( a ) => low_pc = Some ( a ) , _ => ( ) , } } else if attr . name ( ) == gimli :: constants :: DW_AT_high_pc { match attr . value ( ) { AttributeValue :: Udata ( a ) => high_pc = Some ( a ) , _ => ( ) , } } else if attr . name ( ) == gimli :: constants :: DW_AT_name { match attr . value ( ) { AttributeValue :: DebugStrRef ( offset ) => { let sub_name = dwarf . string ( offset ) . unwrap ( ) . to_string ( ) . unwrap ( ) . to_string ( ) ; // Ignore reserved functions if ! sub_name . starts_with ( " " ) { name = Some ( sub_name ) ; } } _ => ( ) , } } else if attr . name ( ) == gimli :: constants :: DW_AT_linkage_name { match attr . value ( ) { AttributeValue :: DebugStrRef ( offset ) => { let sub_name = dwarf . string ( offset ) . unwrap ( ) . to_string ( ) . unwrap ( ) . to_string ( ) ; linkage_name = demangle ( & sub_name ) . to_string ( ) ; } _ => ( ) , } } } match ( name , low_pc , high_pc ) { ( Some ( name ) , Some ( low ) , Some ( high ) ) => { subprogram = Some ( Subprogram { name , linkage_name , low_pc : low , high_pc : low + high , } ) } _ => ( ) , } Ok ( subprogram ) }
Tries to parse a `DW_TAG_subprogram` in the current DWARF entry.
Tries to parse a ` DW_TAG_subprogram ` in the current DWARF entry .
dwarf
&Dwarf<EndianSlice<RunTimeEndian>>
entry
&DebuggingInformationEntry<EndianSlice<RunTimeEndian>>
dwarf
&Dwarf<EndianSlice<RunTimeEndian>>
entry
&DebuggingInformationEntry<EndianSlice<RunTimeEndian>>