Line data Source code
1 : //! Module for processing DWARF debug info
2 : //!
3 : //! This module exposes an API similar to the [`crate::pdb`] module to process DWARF
4 : //! debug info (embedded or not).
5 : //!
6 : //! One can instantiate a [`crate::dwarf::DebugInfo`] using either [`crate::generic::Binary::debug_info`] or
7 : //! [`crate::dwarf::load`] for external DWARF files.
8 : //!
9 : //! ```
10 : //! fn from_binary(elf: &lief::elf::Binary) {
11 : //! if let Some(lief::DebugInfo::Dwarf(dwarf)) = elf.debug_info() {
12 : //! for complilation_unit in dwarf.compilation_units() {
13 : //! println!("{}", complilation_unit.name());
14 : //! }
15 : //! }
16 : //! }
17 : //!
18 : //! fn from_external(dwarf_file: &str) {
19 : //! let debug_info = lief::dwarf::load(dwarf_file).unwrap();
20 : //! for complilation_unit in debug_info.compilation_units() {
21 : //! println!("{}", complilation_unit.name());
22 : //! }
23 : //! }
24 : //! ```
25 :
26 : use lief_ffi as ffi;
27 : use std::path::Path;
28 :
29 : pub mod debug_info;
30 : pub mod compilation_unit;
31 : pub mod function;
32 : pub mod variable;
33 : pub mod types;
34 : pub mod scope;
35 : pub mod parameters;
36 : pub mod editor;
37 :
38 : use crate::common::into_optional;
39 :
40 : #[doc(inline)]
41 : pub use debug_info::DebugInfo;
42 :
43 : #[doc(inline)]
44 : pub use compilation_unit::CompilationUnit;
45 :
46 : #[doc(inline)]
47 : pub use function::Function;
48 :
49 : #[doc(inline)]
50 : pub use variable::Variable;
51 :
52 : #[doc(inline)]
53 : pub use scope::Scope;
54 :
55 : #[doc(inline)]
56 : pub use types::Type;
57 :
58 : #[doc(inline)]
59 : pub use editor::Editor;
60 :
61 : #[doc(inline)]
62 : pub use parameters::{Parameter, Parameters};
63 :
64 : /// Load a DWARF from its file path
65 0 : pub fn load<P: AsRef<Path>>(path: P) -> Option<DebugInfo<'static>> {
66 0 : into_optional(ffi::DWARF_DebugInfo::from_file(path.as_ref().to_str().unwrap()))
67 0 : }
|