Repository: microsoft/onefuzz
File: src/agent/srcview/src/pdbcache.rs (Rust)

Code before:
        let pdbfile = File::open(pdb)?;
        let mut pdb = PDB::open(pdbfile)?;

        let address_map = pdb.address_map()?;
        let string_table = pdb.string_table()?;

        let dbi = pdb.debug_information()?;
        let mut modules = dbi.modules()?;
        while let Some(module) = modules.next()? {
            let info = match pdb.module_info(&module)? {
                Some(info) => info,
                None => {
                    warn!("no module info: {:?}", &module);
                    continue;
                }
            };

            let program = info.line_program()?;
            let mut symbols = info.symbols()?;

            while let Some(symbol) = symbols.next()? {
                if let Ok(SymbolData::Procedure(proc)) = symbol.parse() {
                    let proc_name = proc.name.to_string();
                    let mut lines = program.lines_at_offset(proc.offset);

                    let symbol_to_lines = symbol_to_lines.entry(proc_name.to_string()).or_default();

                    while let Some(line_info) = lines.next()? {
                        let rva = line_info
                            .offset
                            .to_rva(&address_map)
                            .ok_or_else(|| format_err!("invalid RVA: {:?}", line_info))?;
                        let file_info = program.get_file_info(line_info.file_index)?;
                        let file_name = file_info.name.to_string_lossy(&string_table)?;

                        let path = file_name.into_owned();
                        let line = line_info.line_start as usize;

                        let srcloc = SrcLine::new(path.clone(), line);

                        offset_to_line.insert(rva.0 as usize, srcloc.clone());
                        path_to_symbols
                            .entry(path.clone())
                            .or_default()
                            .push(proc_name.to_string());
                        symbol_to_lines.push(srcloc.clone());
                        path_to_lines.entry(path.clone()).or_default().push(line);
                    }
                }
            }
        }

Review comment (suggestion):
Stylistic but `clone` instead of `to_string` to be explicit about what's happening, since it's already a `String`? And another instance of this below…

Code after:
        let pdbfile = File::open(pdb)?;
        let mut pdb = PDB::open(pdbfile)?;

        let address_map = pdb.address_map()?;
        let string_table = pdb.string_table()?;

        let dbi = pdb.debug_information()?;
        let mut modules = dbi.modules()?;
        while let Some(module) = modules.next()? {
            let info = match pdb.module_info(&module)? {
                Some(info) => info,
                None => {
                    warn!("no module info: {:?}", &module);
                    continue;
                }
            };

            let program = info.line_program()?;
            let mut symbols = info.symbols()?;

            while let Some(symbol) = symbols.next()? {
                if let Ok(SymbolData::Procedure(proc)) = symbol.parse() {
                    let proc_name = proc.name.to_string();
                    let mut lines = program.lines_for_symbol(proc.offset);

                    let symbol_to_lines = symbol_to_lines.entry(proc_name.to_string()).or_default();

                    while let Some(line_info) = lines.next()? {
                        let rva = line_info
                            .offset
                            .to_rva(&address_map)
                            .ok_or_else(|| format_err!("invalid RVA: {:?}", line_info))?;
                        let file_info = program.get_file_info(line_info.file_index)?;
                        let file_name = file_info.name.to_string_lossy(&string_table)?;

                        let path = file_name.into_owned();
                        let line = line_info.line_start as usize;

                        let srcloc = SrcLine::new(path.clone(), line);

                        offset_to_line.insert(rva.0 as usize, srcloc.clone());
                        path_to_symbols
                            .entry(path.clone())
                            .or_default()
                            .push(proc_name.to_string());
                        symbol_to_lines.push(srcloc.clone());
                        path_to_lines.entry(path.clone()).or_default().push(line);
                    }
                }
            }
        }