Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::FromFFI;
4 :
5 : use crate::dwarf::editor::types::EditorType;
6 : use crate::dwarf::editor::Type;
7 :
8 : pub struct Variable {
9 : ptr: cxx::UniquePtr<ffi::DWARF_editor_Variable>,
10 : }
11 :
12 : impl FromFFI<ffi::DWARF_editor_Variable> for Variable {
13 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::DWARF_editor_Variable>) -> Self {
14 0 : Self { ptr }
15 0 : }
16 : }
17 :
18 : impl Variable {
19 : /// Set the global address of this variable. Setting this address is only
20 : /// revelant in the case of a static global variable. For stack variable, you
21 : /// should use [`Variable::set_stack_offset`].
22 : ///
23 : /// This function set the `DW_AT_location` attribute
24 0 : pub fn set_addr(&mut self, addr: u64) -> &mut Self {
25 0 : self.ptr.pin_mut().set_addr(addr);
26 0 : self
27 0 : }
28 :
29 : /// Set the stack offset of this variable.
30 : ///
31 : /// This function set the `DW_AT_location` attribute
32 0 : pub fn set_stack_offset(&mut self, addr: u64) -> &mut Self {
33 0 : self.ptr.pin_mut().set_stack_offset(addr);
34 0 : self
35 0 : }
36 :
37 : /// Mark this variable as **imported**
38 0 : pub fn set_external(&mut self) -> &mut Self {
39 0 : self.ptr.pin_mut().set_external();
40 0 : self
41 0 : }
42 :
43 : /// Set the type of the current variable
44 0 : pub fn set_type(&mut self, ty: &Type) -> &mut Self {
45 0 : self.ptr.pin_mut().set_type(ty.get_base());
46 0 : self
47 0 : }
48 :
49 : /// Create a `DW_AT_description` entry with the description
50 : /// provided in parameter.
51 0 : pub fn add_description(&mut self, description: &str) -> &mut Self {
52 0 : self.ptr.pin_mut().add_description(description);
53 0 : self
54 0 : }
55 : }
|