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
use std::ffi::{CStr, CString};
use std::fmt;
use std::ptr;
use super::address::SBAddress;
use super::instructionlist::SBInstructionList;
use super::stream::SBStream;
use super::target::SBTarget;
use super::{DisassemblyFlavor, SymbolType};
use sys;
pub struct SBSymbol {
pub raw: sys::SBSymbolRef,
}
impl SBSymbol {
pub fn wrap(raw: sys::SBSymbolRef) -> SBSymbol {
SBSymbol { raw: raw }
}
pub fn maybe_wrap(raw: sys::SBSymbolRef) -> Option<SBSymbol> {
if unsafe { sys::SBSymbolIsValid(raw) != 0 } {
Some(SBSymbol { raw: raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBSymbolIsValid(self.raw) != 0 }
}
pub fn name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBSymbolGetName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn display_name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBSymbolGetDisplayName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn mangled_name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBSymbolGetMangledName(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::SBSymbolGetInstructions2(
self.raw,
target.raw,
flavor.map_or(ptr::null(), |s| s.as_ptr()),
)
})
}
pub fn start_address(&self) -> Option<SBAddress> {
SBAddress::maybe_wrap(unsafe { sys::SBSymbolGetStartAddress(self.raw) })
}
pub fn end_address(&self) -> Option<SBAddress> {
SBAddress::maybe_wrap(unsafe { sys::SBSymbolGetEndAddress(self.raw) })
}
pub fn prologue_byte_size(&self) -> u32 {
unsafe { sys::SBSymbolGetPrologueByteSize(self.raw) }
}
pub fn symbol_type(&self) -> SymbolType {
unsafe { sys::SBSymbolGetType(self.raw) }
}
pub fn is_external(&self) -> bool {
unsafe { sys::SBSymbolIsExternal(self.raw) != 0 }
}
pub fn is_synthetic(&self) -> bool {
unsafe { sys::SBSymbolIsSynthetic(self.raw) != 0 }
}
}
impl fmt::Debug for SBSymbol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBSymbolGetDescription(self.raw, stream.raw) };
write!(fmt, "SBSymbol {{ {} }}", stream.data())
}
}
impl Drop for SBSymbol {
fn drop(&mut self) {
unsafe { sys::DisposeSBSymbol(self.raw) };
}
}
#[cfg(feature = "graphql")]
graphql_object!(SBSymbol: 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() -> Option<SBAddress> {
self.start_address()
}
field end_address() -> Option<SBAddress> {
self.end_address()
}
field prologue_byte_size() -> i64 {
self.prologue_byte_size() as i64
}
field is_external() -> bool {
self.is_external()
}
field is_synthetic() -> bool {
self.is_synthetic()
}
});