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 :
28 : pub mod debug_info;
29 : pub mod compilation_unit;
30 : pub mod function;
31 : pub mod variable;
32 : pub mod types;
33 : pub mod scope;
34 : pub mod parameters;
35 :
36 : use crate::common::into_optional;
37 :
38 : #[doc(inline)]
39 : pub use debug_info::DebugInfo;
40 :
41 : #[doc(inline)]
42 : pub use compilation_unit::CompilationUnit;
43 :
44 : #[doc(inline)]
45 : pub use function::Function;
46 :
47 : #[doc(inline)]
48 : pub use variable::Variable;
49 :
50 : #[doc(inline)]
51 : pub use scope::Scope;
52 :
53 : #[doc(inline)]
54 : pub use types::Type;
55 :
56 : #[doc(inline)]
57 : pub use parameters::{Parameter, Parameters};
58 :
59 : /// Load a DWARF from its file path
60 0 : pub fn load(path: &str) -> Option<DebugInfo> {
61 0 : into_optional(ffi::DWARF_DebugInfo::from_file(path))
62 0 : }
|