1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use std::ffi::{CStr, CString};
use std::fmt;
use std::ptr;
use super::address::SBAddress;
use super::block::SBBlock;
use super::instructionlist::SBInstructionList;
use super::stream::SBStream;
use super::target::SBTarget;
use super::types::SBType;
use super::{DisassemblyFlavor, LanguageType};
use sys;
pub struct SBFunction {
pub raw: sys::SBFunctionRef,
}
impl SBFunction {
pub fn wrap(raw: sys::SBFunctionRef) -> SBFunction {
SBFunction { raw: raw }
}
pub fn maybe_wrap(raw: sys::SBFunctionRef) -> Option<SBFunction> {
if unsafe { sys::SBFunctionIsValid(raw) != 0 } {
Some(SBFunction { raw: raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBFunctionIsValid(self.raw) != 0 }
}
pub fn name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBFunctionGetName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn display_name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBFunctionGetDisplayName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn mangled_name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBFunctionGetMangledName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn get_instructions(
&self,
target: &SBTarget,
flavor: DisassemblyFlavor,
) -> SBInstructionList {
let flavor = match flavor {
DisassemblyFlavor::ATT => CString::new("att").ok(),
DisassemblyFlavor::Default => None,
DisassemblyFlavor::Intel => CString::new("intel").ok(),
};
SBInstructionList::wrap(unsafe {
sys::SBFunctionGetInstructions2(
self.raw,
target.raw,
flavor.map_or(ptr::null(), |s| s.as_ptr()),
)
})
}
pub fn start_address(&self) -> SBAddress {
SBAddress::wrap(unsafe { sys::SBFunctionGetStartAddress(self.raw) })
}
pub fn end_address(&self) -> SBAddress {
SBAddress::wrap(unsafe { sys::SBFunctionGetEndAddress(self.raw) })
}
pub fn prologue_byte_size(&self) -> u32 {
unsafe { sys::SBFunctionGetPrologueByteSize(self.raw) }
}
pub fn return_type(&self) -> SBType {
SBType::wrap(unsafe { sys::SBFunctionGetType(self.raw) })
}
pub fn block(&self) -> SBBlock {
SBBlock::wrap(unsafe { sys::SBFunctionGetBlock(self.raw) })
}
pub fn language(&self) -> LanguageType {
unsafe { sys::SBFunctionGetLanguage(self.raw) }
}
pub fn is_optimized(&self) -> bool {
unsafe { sys::SBFunctionGetIsOptimized(self.raw) != 0 }
}
}
impl fmt::Debug for SBFunction {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBFunctionGetDescription(self.raw, stream.raw) };
write!(fmt, "SBFunction {{ {} }}", stream.data())
}
}
impl Drop for SBFunction {
fn drop(&mut self) {
unsafe { sys::DisposeSBFunction(self.raw) };
}
}
#[cfg(feature = "graphql")]
graphql_object!(SBFunction: super::debugger::SBDebugger | &self | {
field is_valid() -> bool {
self.is_valid()
}
field name() -> &str {
self.name()
}
field display_name() -> &str {
self.display_name()
}
field mangled_name() -> &str {
self.mangled_name()
}
field start_address() -> SBAddress {
self.start_address()
}
field end_address() -> SBAddress {
self.end_address()
}
field prologue_byte_size() -> i64 {
self.prologue_byte_size() as i64
}
field return_type() -> SBType {
self.return_type()
}
field block() -> SBBlock {
self.block()
}
field is_optimized() -> bool {
self.is_optimized()
}
});