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