LCOV - code coverage report
Current view: top level - src/dwarf - debug_info.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 27 0
Test Date: 2024-11-30:00:00:00 Functions: 0.0 % 8 0

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : 
       3              : use std::marker::PhantomData;
       4              : use crate::common::{into_optional, FromFFI};
       5              : use crate::generic;
       6              : use crate::dwarf::function::Function;
       7              : use crate::dwarf::variable::Variable;
       8              : use crate::dwarf::types::Type;
       9              : 
      10              : use super::compilation_unit::CompilationUnits;
      11              : 
      12              : /// This class represents a DWARF debug information. It can embed different
      13              : /// compilation units which can be accessed through [`DebugInfo::compilation_units`].
      14              : ///
      15              : /// This class can be instantiated from [`crate::generic::Binary::debug_info`] or using the
      16              : /// function [`crate::dwarf::load`]
      17              : pub struct DebugInfo<'a> {
      18              :     ptr: cxx::UniquePtr<ffi::DWARF_DebugInfo>,
      19              :     _owner: PhantomData<&'a ()>,
      20              : }
      21              : 
      22              : impl FromFFI<ffi::DWARF_DebugInfo> for DebugInfo<'_> {
      23            0 :     fn from_ffi(info: cxx::UniquePtr<ffi::DWARF_DebugInfo>) -> Self {
      24            0 :         Self {
      25            0 :             ptr: info,
      26            0 :             _owner: PhantomData
      27            0 :         }
      28            0 :     }
      29              : }
      30              : 
      31              : impl DebugInfo<'_> {
      32              :     /// Iterator on the [`crate::dwarf::CompilationUnit`] embedded in this dwarf
      33            0 :     pub fn compilation_units(&self) -> CompilationUnits {
      34            0 :         CompilationUnits::new(self.ptr.compilation_units())
      35            0 :     }
      36              : 
      37              :     /// Try to find the function with the given name (mangled or not)
      38              :     ///
      39              :     /// ```
      40              :     /// if let Some(func) = info.function_by_name("_ZNSt6localeD1Ev") {
      41              :     ///     // Found
      42              :     /// }
      43              :     /// if let Some(func) = info.function_by_name("std::locale::~locale()") {
      44              :     ///     // Found
      45              :     /// }
      46              :     /// ```
      47            0 :     pub fn function_by_name(&self, name: &str) -> Option<Function> {
      48            0 :         into_optional(self.ptr.function_by_name(name))
      49            0 :     }
      50              : 
      51              :     /// Try to find the function at the given **virtual** address
      52            0 :     pub fn function_by_addr(&self, addr: u64) -> Option<Function> {
      53            0 :         into_optional(self.ptr.function_by_addr(addr))
      54            0 :     }
      55              : 
      56              :     /// Try to find the variable with the given name. This name can be mangled or
      57              :     /// not.
      58            0 :     pub fn variable_by_name(&self, name: &str) -> Option<Variable> {
      59            0 :         into_optional(self.ptr.variable_by_name(name))
      60            0 :     }
      61              : 
      62              :     /// Try to find the (static) variable at the given **virtual** address
      63            0 :     pub fn variable_by_addr(&self, addr: u64) -> Option<Variable> {
      64            0 :         into_optional(self.ptr.variable_by_addr(addr))
      65            0 :     }
      66              : 
      67              :     /// Try to find the (static) variable at the given **virtual** address
      68            0 :     pub fn type_by_name(&self, name: &str) -> Option<Type> {
      69            0 :         into_optional(self.ptr.type_by_name(name))
      70            0 :     }
      71              : }
      72              : 
      73              : impl generic::DebugInfo for DebugInfo<'_> {
      74            0 :     fn as_generic(&self) -> &ffi::AbstracDebugInfo {
      75            0 :         self.ptr.as_ref().unwrap().as_ref()
      76            0 :     }
      77              : }
        

Generated by: LCOV version 2.1-1