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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
use std::ffi::{CStr, CString};
use std::fmt;
use super::address::SBAddress;
use super::block::SBBlock;
use super::compileunit::SBCompileUnit;
use super::expressionoptions::SBExpressionOptions;
use super::function::SBFunction;
use super::lineentry::SBLineEntry;
use super::module::SBModule;
use super::stream::SBStream;
use super::symbol::SBSymbol;
use super::symbolcontext::SBSymbolContext;
use super::thread::SBThread;
use super::value::SBValue;
use super::valuelist::SBValueList;
use super::variablesoptions::SBVariablesOptions;
use super::lldb_addr_t;
use sys;
pub struct SBFrame {
pub raw: sys::SBFrameRef,
}
impl SBFrame {
pub fn wrap(raw: sys::SBFrameRef) -> SBFrame {
SBFrame { raw: raw }
}
pub fn maybe_wrap(raw: sys::SBFrameRef) -> Option<SBFrame> {
if unsafe { sys::SBFrameIsValid(raw) != 0 } {
Some(SBFrame { raw: raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBFrameIsValid(self.raw) != 0 }
}
pub fn frame_id(&self) -> u32 {
unsafe { sys::SBFrameGetFrameID(self.raw) }
}
pub fn cfa(&self) -> Option<lldb_addr_t> {
let cfa = unsafe { sys::SBFrameGetCFA(self.raw) };
if cfa != u64::max_value() {
Some(cfa)
} else {
None
}
}
pub fn pc(&self) -> lldb_addr_t {
unsafe { sys::SBFrameGetPC(self.raw) }
}
#[allow(missing_docs)]
pub fn set_pc(&self, new_pc: lldb_addr_t) -> bool {
unsafe { sys::SBFrameSetPC(self.raw, new_pc) != 0 }
}
pub fn sp(&self) -> lldb_addr_t {
unsafe { sys::SBFrameGetSP(self.raw) }
}
pub fn fp(&self) -> lldb_addr_t {
unsafe { sys::SBFrameGetFP(self.raw) }
}
pub fn pc_address(&self) -> SBAddress {
SBAddress::wrap(unsafe { sys::SBFrameGetPCAddress(self.raw) })
}
pub fn symbol_context(&self, resolve_scope: u32) -> SBSymbolContext {
SBSymbolContext::wrap(unsafe {
sys::SBFrameGetSymbolContext(self.raw, resolve_scope)
})
}
pub fn module(&self) -> SBModule {
SBModule::wrap(unsafe { sys::SBFrameGetModule(self.raw) })
}
pub fn compile_unit(&self) -> SBCompileUnit {
SBCompileUnit::wrap(unsafe { sys::SBFrameGetCompileUnit(self.raw) })
}
pub fn function(&self) -> SBFunction {
SBFunction::wrap(unsafe { sys::SBFrameGetFunction(self.raw) })
}
pub fn symbol(&self) -> SBSymbol {
SBSymbol::wrap(unsafe { sys::SBFrameGetSymbol(self.raw) })
}
pub fn block(&self) -> SBBlock {
SBBlock::wrap(unsafe { sys::SBFrameGetBlock(self.raw) })
}
pub fn function_name(&self) -> Option<&str> {
unsafe {
match CStr::from_ptr(sys::SBFrameGetFunctionName(self.raw)).to_str() {
Ok(s) => Some(s),
_ => None,
}
}
}
#[allow(missing_docs)]
pub fn display_function_name(&self) -> Option<&str> {
unsafe {
match CStr::from_ptr(sys::SBFrameGetDisplayFunctionName(self.raw)).to_str() {
Ok(s) => Some(s),
_ => None,
}
}
}
pub fn is_inlined(&self) -> bool {
unsafe { sys::SBFrameIsInlined(self.raw) != 0 }
}
pub fn evaluate_expression(&self, expression: &str, options: &SBExpressionOptions) -> SBValue {
let expression = CString::new(expression).unwrap();
SBValue::wrap(unsafe {
sys::SBFrameEvaluateExpression(self.raw, expression.as_ptr(), options.raw)
})
}
pub fn frame_block(&self) -> SBBlock {
SBBlock::wrap(unsafe { sys::SBFrameGetFrameBlock(self.raw) })
}
pub fn line_entry(&self) -> Option<SBLineEntry> {
SBLineEntry::maybe_wrap(unsafe { sys::SBFrameGetLineEntry(self.raw) })
}
pub fn thread(&self) -> SBThread {
SBThread::wrap(unsafe { sys::SBFrameGetThread(self.raw) })
}
pub fn disassemble(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBFrameDisassemble(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn variables(&self, options: &SBVariablesOptions) -> SBValueList {
SBValueList::wrap(unsafe { sys::SBFrameGetVariables(self.raw, options.raw) })
}
pub fn all_variables(&self) -> SBValueList {
let options = SBVariablesOptions::new();
options.set_include_arguments(true);
options.set_include_locals(true);
options.set_include_statics(true);
options.set_in_scope_only(true);
self.variables(&options)
}
pub fn arguments(&self) -> SBValueList {
let options = SBVariablesOptions::new();
options.set_include_arguments(true);
options.set_include_locals(false);
options.set_include_statics(false);
options.set_in_scope_only(false);
self.variables(&options)
}
pub fn locals(&self) -> SBValueList {
let options = SBVariablesOptions::new();
options.set_include_arguments(false);
options.set_include_locals(true);
options.set_include_statics(false);
options.set_in_scope_only(false);
self.variables(&options)
}
pub fn statics(&self) -> SBValueList {
let options = SBVariablesOptions::new();
options.set_include_arguments(false);
options.set_include_locals(false);
options.set_include_statics(true);
options.set_in_scope_only(false);
self.variables(&options)
}
pub fn registers(&self) -> SBValueList {
SBValueList::wrap(unsafe { sys::SBFrameGetRegisters(self.raw) })
}
pub fn find_register(&self, name: &str) -> Option<SBValue> {
let name = CString::new(name).unwrap();
SBValue::maybe_wrap(unsafe { sys::SBFrameFindRegister(self.raw, name.as_ptr()) })
}
pub fn parent_frame(&self) -> Option<SBFrame> {
let thread = self.thread();
let parent_idx = self.frame_id() + 1;
if parent_idx < unsafe { sys::SBThreadGetNumFrames(thread.raw) } {
SBFrame::maybe_wrap(unsafe {
sys::SBThreadGetFrameAtIndex(thread.raw, parent_idx)
})
} else {
None
}
}
}
impl fmt::Debug for SBFrame {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBFrameGetDescription(self.raw, stream.raw) };
write!(fmt, "SBFrame {{ {} }}", stream.data())
}
}
impl Drop for SBFrame {
fn drop(&mut self) {
unsafe { sys::DisposeSBFrame(self.raw) };
}
}
#[cfg(feature = "graphql")]
graphql_object!(SBFrame: super::debugger::SBDebugger | &self | {
field is_valid() -> bool {
self.is_valid()
}
field frame_id() -> i64 {
self.frame_id() as i64
}
field cfa() -> Option<i64> {
self.cfa().map(|i| i as i64)
}
field pc() -> i64 {
self.pc() as i64
}
field sp() -> i64 {
self.sp() as i64
}
field fp() -> i64 {
self.fp() as i64
}
field pc_address() -> SBAddress {
self.pc_address()
}
field module() -> SBModule {
self.module()
}
field compile_unit() -> SBCompileUnit {
self.compile_unit()
}
field function() -> SBFunction {
self.function()
}
field symbol() -> SBSymbol {
self.symbol()
}
field block() -> SBBlock {
self.block()
}
field function_name() -> Option<&str> {
self.function_name()
}
field display_function_name() -> Option<&str> {
self.display_function_name()
}
field is_inlined() -> bool {
self.is_inlined()
}
field frame_block() -> SBBlock {
self.frame_block()
}
field line_entry() -> Option<SBLineEntry> {
self.line_entry()
}
field thread() -> SBThread {
self.thread()
}
});