fn find_entry_location<'unit>(
    dwarf: &Dwarf<DefaultReader>,
    unit: &'unit Unit<DefaultReader, usize>,
    entry: &DebuggingInformationEntry<DefaultReader, usize>,
) -> Result<Location, TraceError> {
    // Get the attributes
    let variable_decl_file = entry
        .attr_value(gimli::constants::DW_AT_decl_file)?
        .and_then(|f| match f {
            AttributeValue::FileIndex(index) => Some(index),
            _ => None,
        });
    let variable_decl_line = entry
        .attr_value(gimli::constants::DW_AT_decl_line)?
        .and_then(|l| l.udata_value());
    let variable_decl_column = entry
        .attr_value(gimli::constants::DW_AT_decl_column)?
        .and_then(|c| c.udata_value());

    fn path_push(path: &mut String, p: &str) {
        /// Check if the path in the given string has a unix style root
        fn has_unix_root(p: &str) -> bool {
            p.starts_with('/')
        }

        /// Check if the path in the given string has a windows style root
        fn has_windows_root(p: &str) -> bool {
            p.starts_with('\\') || p.get(1..3) == Some(":\\")
        }

        if has_unix_root(p) || has_windows_root(p) {
            *path = p.to_string();
        } else {
            let dir_separator = if has_windows_root(path.as_str()) {
                '\\'
            } else {
                '/'
            };

            if !path.ends_with(dir_separator) {
                path.push(dir_separator);
            }
            *path += p;
        }
    }

    // The file is given as a number, so we need to search for the real file path
    let variable_file = if let (Some(variable_decl_file), Some(line_program)) =
        (variable_decl_file, unit.line_program.as_ref())
    {
        // The file paths are stored in the line_program
        if let Some(file_entry) = line_program.header().file(variable_decl_file) {
            let mut path = if let Some(comp_dir) = &unit.comp_dir {
                comp_dir.to_string_lossy()?.into_owned()
            } else {
                String::new()
            };

            // The directory index 0 is defined to correspond to the compilation unit directory
            if variable_decl_file != 0 {
                if let Some(directory) = file_entry.directory(line_program.header()) {
                    path_push(
                        &mut path,
                        &dwarf.attr_string(unit, directory)?.to_string_lossy()?,
                    )
                }
            }

            path_push(
                &mut path,
                &dwarf
                    .attr_string(unit, file_entry.path_name())?
                    .to_string()?,
            );

            Some(path)
        } else {
            None
        }
    } else {
        None
    };

    Ok(Location {
        file: variable_file,
        line: variable_decl_line,
        column: variable_decl_column,
    })
}
/// Finds the [Location] of the given entry.
///
/// This is done based on the `DW_AT_decl_file`, `DW_AT_decl_line` and `DW_AT_decl_column` attributes.
/// These are normally present on variables and functions.
Finds the [Location] of the given entry.
Finds the [ Location ] of the given entry .
fn find_entry_location<'unit>(
    dwarf: &Dwarf<DefaultReader>,
    unit: &'unit Unit<DefaultReader, usize>,
    entry: &DebuggingInformationEntry<DefaultReader, usize>,
) -> Result<Location, TraceError> {
    // Get the attributes
    let variable_decl_file = entry
        .attr_value(gimli::constants::DW_AT_decl_file)?
        .and_then(|f| match f {
            AttributeValue::FileIndex(index) => Some(index),
            _ => None,
        });
    let variable_decl_line = entry
        .attr_value(gimli::constants::DW_AT_decl_line)?
        .and_then(|l| l.udata_value());
    let variable_decl_column = entry
        .attr_value(gimli::constants::DW_AT_decl_column)?
        .and_then(|c| c.udata_value());
    fn path_push(path: &mut String, p: &str) {
        /// Check if the path in the given string has a unix style root
        fn has_unix_root(p: &str) -> bool {
            p.starts_with('/')
        }
        /// Check if the path in the given string has a windows style root
        fn has_windows_root(p: &str) -> bool {
            p.starts_with('\\') || p.get(1..3) == Some(":\\")
        }
        if has_unix_root(p) || has_windows_root(p) {
            *path = p.to_string();
        } else {
            let dir_separator = if has_windows_root(path.as_str()) {
                '\\'
            } else {
                '/'
            };
            if !path.ends_with(dir_separator) {
                path.push(dir_separator);
            }
            *path += p;
        }
    }
    // The file is given as a number, so we need to search for the real file path
    let variable_file = if let (Some(variable_decl_file), Some(line_program)) =
        (variable_decl_file, unit.line_program.as_ref())
    {
        // The file paths are stored in the line_program
        if let Some(file_entry) = line_program.header().file(variable_decl_file) {
            let mut path = if let Some(comp_dir) = &unit.comp_dir {
                comp_dir.to_string_lossy()?.into_owned()
            } else {
                String::new()
            };
            // The directory index 0 is defined to correspond to the compilation unit directory
            if variable_decl_file != 0 {
                if let Some(directory) = file_entry.directory(line_program.header()) {
                    path_push(
                        &mut path,
                        &dwarf.attr_string(unit, directory)?.to_string_lossy()?,
                    )
                }
            }
            path_push(
                &mut path,
                &dwarf
                    .attr_string(unit, file_entry.path_name())?
                    .to_string()?,
            );
            Some(path)
        } else {
            None
        }
    } else {
        None
    };
    Ok(Location {
        file: variable_file,
        line: variable_decl_line,
        column: variable_decl_column,
    })
}
fn find_entry_location < ' unit > ( dwarf : & Dwarf < DefaultReader > , unit : & ' unit Unit < DefaultReader , usize > , entry : & DebuggingInformationEntry < DefaultReader , usize > , ) -> Result < Location , TraceError > { // Get the attributes let variable_decl_file = entry . attr_value ( gimli :: constants :: DW_AT_decl_file ) ? . and_then ( | f | match f { AttributeValue :: FileIndex ( index ) => Some ( index ) , _ => None , } ) ; let variable_decl_line = entry . attr_value ( gimli :: constants :: DW_AT_decl_line ) ? . and_then ( | l | l . udata_value ( ) ) ; let variable_decl_column = entry . attr_value ( gimli :: constants :: DW_AT_decl_column ) ? . and_then ( | c | c . udata_value ( ) ) ; fn path_push ( path : & mut String , p : & str ) { /// Check if the path in the given string has a unix style root fn has_unix_root ( p : & str ) -> bool { p . starts_with ( '/' ) } /// Check if the path in the given string has a windows style root fn has_windows_root ( p : & str ) -> bool { p . starts_with ( '\\' ) || p . get ( 1 .. 3 ) == Some ( " \\ " ) } if has_unix_root ( p ) || has_windows_root ( p ) { * path = p . to_string ( ) ; } else { let dir_separator = if has_windows_root ( path . as_str ( ) ) { '\\' } else { '/' } ; if ! path . ends_with ( dir_separator ) { path . push ( dir_separator ) ; } * path += p ; } } // The file is given as a number, so we need to search for the real file path let variable_file = if let ( Some ( variable_decl_file ) , Some ( line_program ) ) = ( variable_decl_file , unit . line_program . as_ref ( ) ) { // The file paths are stored in the line_program if let Some ( file_entry ) = line_program . header ( ) . file ( variable_decl_file ) { let mut path = if let Some ( comp_dir ) = & unit . comp_dir { comp_dir . to_string_lossy ( ) ? . into_owned ( ) } else { String :: new ( ) } ; // The directory index 0 is defined to correspond to the compilation unit directory if variable_decl_file != 0 { if let Some ( directory ) = file_entry . directory ( line_program . header ( ) ) { path_push ( & mut path , & dwarf . attr_string ( unit , directory ) ? . to_string_lossy ( ) ? , ) } } path_push ( & mut path , & dwarf . attr_string ( unit , file_entry . path_name ( ) ) ? . to_string ( ) ? , ) ; Some ( path ) } else { None } } else { None } ; Ok ( Location { file : variable_file , line : variable_decl_line , column : variable_decl_column , } ) }
Finds the [Location] of the given entry.
Finds the [ Location ] of the given entry .
dwarf
&Dwarf<DefaultReader>
unit
&'unit Unit<DefaultReader, usize>
entry
&DebuggingInformationEntry<DefaultReader, usize>
dwarf
&Dwarf<DefaultReader>
unit
&'unit Unit<DefaultReader, usize>
entry
&DebuggingInformationEntry<DefaultReader, usize>