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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
use super::prelude::*;
use crate::arch::Arch;
use crate::internal::BeBytes;
use crate::protocol::commands::_QTDPsrc::QTDPsrc;
use crate::protocol::commands::_qTBuffer::qTBuffer;
use crate::protocol::commands::ext::Tracepoints;
use crate::protocol::commands::prelude::decode_hex;
use crate::protocol::commands::prelude::decode_hex_buf;
use crate::protocol::commands::_QTDP::CreateTDP;
use crate::protocol::commands::_QTDP::ExtendTDP;
use crate::protocol::commands::_QTDP::QTDP;
use crate::protocol::ResponseWriterError;
use crate::target::ext::tracepoints::ExperimentExplanation;
use crate::target::ext::tracepoints::ExperimentStatus;
use crate::target::ext::tracepoints::FrameDescription;
use crate::target::ext::tracepoints::FrameRequest;
use crate::target::ext::tracepoints::NewTracepoint;
use crate::target::ext::tracepoints::SourceTracepoint;
use crate::target::ext::tracepoints::Tracepoint;
use crate::target::ext::tracepoints::TracepointAction;
use crate::target::ext::tracepoints::TracepointEnumerateCursor;
use crate::target::ext::tracepoints::TracepointEnumerateStep;
use crate::target::ext::tracepoints::TracepointSourceType;
use crate::target::ext::tracepoints::TracepointStatus;
use managed::ManagedSlice;
use num_traits::PrimInt;
impl<U: BeBytes> NewTracepoint<U> {
/// Parse from a raw CreateTDP packet.
fn from_tdp(ctdp: CreateTDP<'_>) -> Option<(Self, bool)> {
Some((
Self {
number: ctdp.number,
addr: U::from_be_bytes(ctdp.addr)?,
enabled: ctdp.enable,
pass_count: ctdp.pass,
step_count: ctdp.step,
},
ctdp.more,
))
}
}
impl<U: crate::internal::BeBytes + num_traits::Zero + PrimInt> NewTracepoint<U> {
/// Write this as a qTfP/qTsP response
pub(crate) fn write<T: Target, C: Connection>(
&self,
res: &mut ResponseWriter<'_, C>,
) -> Result<(), Error<T::Error, C::Error>> {
res.write_str("T")?;
res.write_num(self.number.0)?;
res.write_str(":")?;
res.write_num(self.addr)?;
res.write_str(":")?;
res.write_str(if self.enabled { "E" } else { "D" })?;
res.write_str(":")?;
res.write_num(self.step_count)?;
res.write_str(":")?;
res.write_num(self.pass_count)?;
Ok(())
}
}
/// A list of actions that a tracepoint should be extended with.
#[derive(Debug)]
pub(crate) struct ExtendTracepoint<'a, U> {
/// The tracepoint that is having actions appended to its definition.
pub number: Tracepoint,
/// The PC address of the tracepoint that is being extended.
/// This is currently unused information sent as part of the packet by GDB,
/// but may be required for implementing while-stepping actions later.
#[allow(dead_code)]
pub addr: U,
/// The unparsed action data.
pub data: ManagedSlice<'a, u8>,
}
impl<'a, U: BeBytes> ExtendTracepoint<'a, U> {
/// Parse from a raw ExtendTDP packet.
fn from_tdp(dtdp: ExtendTDP<'a>) -> Option<Self> {
Some(Self {
number: dtdp.number,
addr: U::from_be_bytes(dtdp.addr)?,
data: ManagedSlice::Borrowed(dtdp.actions),
})
}
/// Parse the actions that should be added to the definition of this
/// tracepoint, calling `f` on each action.
///
/// Returns `Err` if parsing of actions failed, or hit unsupported actions.
/// Return `Ok(more)` on success, where more indicates if more actions are
/// expect in later packets. If the actions weren't from a GDB packet, more
/// is None.
pub(crate) fn actions<T, C>(
mut self,
f: impl FnMut(&TracepointAction<'_, U>),
) -> Result<Option<bool>, Error<T, C>> {
Self::parse_raw_actions(&mut self.data, f)
}
fn parse_raw_actions<T, C>(
actions: &mut [u8],
mut f: impl FnMut(&TracepointAction<'_, U>),
) -> Result<Option<bool>, Error<T, C>> {
let (actions, more) = match actions {
[rest @ .., b'-'] => (rest, true),
x => (x, false),
};
// TODO: There's no "packet unsupported", so for now we stub out unimplemented
// functionality by reporting the commands malformed instead.
use crate::protocol::PacketParseError::MalformedCommand;
let mut unparsed: Option<&mut [u8]> = Some(actions);
loop {
match unparsed {
Some([b'S', ..]) => {
// TODO: how can gdbstub even implement this? it changes how
// future packets should be interpreted, but as a trait we
// can't keep a flag around for that (unless we specifically
// have a `mark_while_stepping` callback for the target to
// keep track future tracepoint_extends should be treated different).
// If we go that route we also would need to return two vectors
// here, "normal" actions and "while stepping" actions...but
// "normals" actions may still be "while stepping" actions,
// just continued from the previous packet, which we forgot
// about!
//
// We use 'W' to indicate "while-stepping", since we're already
// using 'S' elsewhere for static tracepoints.
return Err(Error::TracepointFeatureUnimplemented(b'W'));
}
Some([b'R', mask @ ..]) => {
let mask_end = mask
.iter()
.enumerate()
.find(|(_i, b)| matches!(b, b'S' | b'R' | b'M' | b'X'));
// We may or may not have another action after our mask
let mask = if let Some(mask_end) = mask_end {
let (mask_bytes, next) = mask.split_at_mut(mask_end.0);
unparsed = Some(next);
decode_hex_buf(mask_bytes).or(Err(Error::PacketParse(MalformedCommand)))?
} else {
unparsed = None;
decode_hex_buf(mask).or(Err(Error::PacketParse(MalformedCommand)))?
};
(f)(&TracepointAction::Registers {
mask: ManagedSlice::Borrowed(mask),
});
}
Some([b'M', _mem_args @ ..]) => {
// Unimplemented: even simple actions like `collect *(int*)0x0`
// are actually assembled as `X` bytecode actions
return Err(Error::TracepointFeatureUnimplemented(b'M'));
}
Some([b'X', eval_args @ ..]) => {
let mut len_end = eval_args.splitn_mut(2, |b| *b == b',');
let (len_bytes, rem) = (
len_end.next().ok_or(Error::PacketParse(MalformedCommand))?,
len_end.next().ok_or(Error::PacketParse(MalformedCommand))?,
);
let len: usize =
decode_hex(len_bytes).or(Err(Error::PacketParse(MalformedCommand)))?;
if rem.len() < len * 2 {
return Err(Error::PacketParse(MalformedCommand));
}
let (expr_bytes, next_bytes) = rem.split_at_mut(len * 2);
let expr =
decode_hex_buf(expr_bytes).or(Err(Error::PacketParse(MalformedCommand)))?;
(f)(&TracepointAction::Expression {
expr: ManagedSlice::Borrowed(expr),
});
unparsed = Some(next_bytes);
}
Some([]) | None => {
break;
}
_ => return Err(Error::PacketParse(MalformedCommand)),
}
}
Ok(Some(more))
}
}
impl<'a, U: BeBytes> SourceTracepoint<'a, U> {
/// Parse from a raw CreateTDP packet.
fn from_src(src: QTDPsrc<'a>) -> Option<Self> {
Some(Self {
number: src.number,
addr: U::from_be_bytes(src.addr)?,
kind: src.kind,
start: src.start,
slen: src.slen,
bytes: ManagedSlice::Borrowed(src.bytes),
})
}
}
impl<U: crate::internal::BeBytes + num_traits::Zero + PrimInt> SourceTracepoint<'_, U> {
/// Write this as a qTfP/qTsP response
pub(crate) fn write<T: Target, C: Connection>(
&self,
res: &mut ResponseWriter<'_, C>,
) -> Result<(), Error<T::Error, C::Error>> {
res.write_str("Z")?;
res.write_num(self.number.0)?;
res.write_str(":")?;
res.write_num(self.addr)?;
res.write_str(":")?;
res.write_str(match self.kind {
TracepointSourceType::At => "at",
TracepointSourceType::Cond => "cond",
TracepointSourceType::Cmd => "cmd",
})?;
res.write_str(":")?;
// We use the start and slen from the SourceTracepoint instead of
// start=0 slen=bytes.len() because, although we can assume GDB to be able
// to handle arbitrary sized packets, the target implementation might still
// be giving us chunked source (such as if it's parroting the chunked source
// that GDB initially gave us).
res.write_num(self.start)?;
res.write_str(":")?;
res.write_num(self.slen)?;
res.write_str(":")?;
res.write_hex_buf(self.bytes.as_ref())?;
Ok(())
}
}
impl<U: crate::internal::BeBytes + num_traits::Zero + PrimInt> TracepointAction<'_, U> {
/// Write this as a qTfP/qTsP response
pub(crate) fn write<T: Target, C: Connection>(
&self,
tp: Tracepoint,
addr: U,
res: &mut ResponseWriter<'_, C>,
) -> Result<(), Error<T::Error, C::Error>> {
res.write_str("A")?;
res.write_num(tp.0)?;
res.write_str(":")?;
res.write_num(addr)?;
res.write_str(":")?;
match self {
TracepointAction::Registers { mask } => {
res.write_str("R")?;
res.write_hex_buf(mask)?;
}
TracepointAction::Memory {
basereg,
offset,
length,
} => {
res.write_str("M")?;
match basereg {
Some(r) => res.write_num(*r),
None => res.write_str("-1"),
}?;
res.write_str(",")?;
res.write_num(*offset)?;
res.write_str(",")?;
res.write_num(*length)?;
}
TracepointAction::Expression { expr } => {
res.write_str("X")?;
res.write_num(expr.len())?;
res.write_str(",")?;
res.write_hex_buf(expr)?;
}
}
Ok(())
}
}
impl ExperimentStatus<'_> {
pub(crate) fn write<C: Connection>(
&self,
res: &mut ResponseWriter<'_, C>,
) -> Result<(), ResponseWriterError<C::Error>> {
use crate::target::ext::tracepoints::ExperimentStatus::*;
if let Running = self {
return res.write_str("T1");
}
// We're stopped for some reason, and may have an explanation for why
res.write_str("T0")?;
match self {
Running => { /* unreachable */ }
NotRunning => { /* no information */ }
NotRun => res.write_str(";tnotrun:0")?,
Stop(ref t) => match t {
Some(text) => {
res.write_str(";tstop:")?;
res.write_hex_buf(text)?;
res.write_str(":0")?;
}
None => res.write_str(";tstop:0")?,
},
Full => res.write_str(";tfull:0")?,
Disconnected => res.write_str(";tdisconnected:0")?,
PassCount(tpnum) => {
res.write_str(";tpasscount:")?;
res.write_num(tpnum.0)?;
}
Error(text, tpnum) => {
res.write_str(";terror:")?;
res.write_hex_buf(text)?;
res.write_str(":")?;
res.write_num(tpnum.0)?;
}
Unknown => res.write_str(";tunknown:0")?,
}
Ok(())
}
}
impl ExperimentExplanation<'_> {
pub(crate) fn write<T: Target, C: Connection>(
&self,
res: &mut ResponseWriter<'_, C>,
) -> Result<(), Error<T::Error, C::Error>> {
use ExperimentExplanation::*;
match self {
Frames(u) => {
res.write_str("tframes:")?;
res.write_num(*u)?;
}
Created(u) => {
res.write_str("tcreated:")?;
res.write_num(*u)?;
}
Size(u) => {
res.write_str("tsize:")?;
res.write_num(*u)?;
}
Free(u) => {
res.write_str("tfree:")?;
res.write_num(*u)?;
}
Circular(u) => {
res.write_str("circular:")?;
res.write_num(if *u { 1 } else { 0 })?;
}
DisconnectedTracing(dis) => match dis {
true => res.write_str("disconn:1")?,
false => res.write_str("disconn:0")?,
},
Other(body) => res.write_str(body.as_ref())?,
};
Ok(())
}
}
impl<'a, U: crate::internal::BeBytes> From<FrameRequest<&'a mut [u8]>> for Option<FrameRequest<U>> {
fn from(s: FrameRequest<&'a mut [u8]>) -> Self {
Some(match s {
FrameRequest::Select(u) => FrameRequest::Select(u),
FrameRequest::AtPC(u) => FrameRequest::AtPC(U::from_be_bytes(u)?),
FrameRequest::Hit(tp) => FrameRequest::Hit(tp),
FrameRequest::Between(s, e) => {
FrameRequest::Between(U::from_be_bytes(s)?, U::from_be_bytes(e)?)
}
FrameRequest::Outside(s, e) => {
FrameRequest::Outside(U::from_be_bytes(s)?, U::from_be_bytes(e)?)
}
})
}
}
impl<T: Target, C: Connection> GdbStubImpl<T, C> {
pub(crate) fn handle_tracepoints(
&mut self,
res: &mut ResponseWriter<'_, C>,
target: &mut T,
command: Tracepoints<'_>,
) -> Result<HandlerStatus, Error<T::Error, C::Error>> {
let ops = match target.support_tracepoints() {
Some(ops) => ops,
None => return Ok(HandlerStatus::Handled),
};
crate::__dead_code_marker!("tracepoints", "impl");
match command {
Tracepoints::QTinit(_) => {
ops.tracepoints_init().handle_error()?;
// GDB documentation doesn't say it, but this requires "OK" in order
// to signify we support tracepoints.
return Ok(HandlerStatus::NeedsOk);
}
Tracepoints::qTStatus(_) => {
let mut err: Option<Error<T::Error, C::Error>> = None;
let mut has_status = false;
ops.trace_experiment_status(&mut |status: ExperimentStatus<'_>| {
// If the target implementation calls us multiple times, then
// we would erroneously serialize an invalid response. Guard
// against it in the simplest way.
if has_status {
return;
}
if let Err(e) = status.write(res) {
err = Some(e.into())
} else {
has_status = true;
}
})
.handle_error()?;
if has_status {
// Only bother trying to get info if we also have a status
ops.trace_experiment_info(&mut |explanation: ExperimentExplanation<'_>| {
if let Err(e) = res
.write_str(";")
.map_err(|e| e.into())
.and_then(|()| explanation.write::<T, C>(res))
{
err = Some(e)
}
})
.handle_error()?;
}
if let Some(e) = err {
return Err(e);
}
}
Tracepoints::qTP(qtp) => {
let addr = <T::Arch as Arch>::Usize::from_be_bytes(qtp.addr)
.ok_or(Error::TargetMismatch)?;
let TracepointStatus {
hit_count,
bytes_used,
} = ops.tracepoint_status(qtp.tracepoint, addr).handle_error()?;
res.write_str("V")?;
res.write_num(hit_count)?;
res.write_str(":")?;
res.write_num(bytes_used)?;
}
Tracepoints::QTDP(q) => {
match q {
QTDP::Create(ctdp) => {
if let Some(feat) = ctdp.unsupported_option {
// We have some options we don't know how to process, so bail out.
return Err(Error::TracepointFeatureUnimplemented(feat));
}
let (new_tracepoint, more) =
NewTracepoint::<<T::Arch as Arch>::Usize>::from_tdp(ctdp)
.ok_or(Error::TargetMismatch)?;
let tp = new_tracepoint.number;
ops.tracepoint_create_begin(new_tracepoint).handle_error()?;
if !more {
ops.tracepoint_create_complete(tp).handle_error()?;
}
}
QTDP::Extend(dtdp) => {
let extend_tracepoint =
ExtendTracepoint::<<T::Arch as Arch>::Usize>::from_tdp(dtdp)
.ok_or(Error::TargetMismatch)?;
let tp = extend_tracepoint.number;
let mut err: Option<Error<T::Error, C::Error>> = None;
let more = extend_tracepoint.actions(|action| {
if let Err(e) =
ops.tracepoint_create_continue(tp, action).handle_error()
{
err = Some(e)
}
});
if let Some(e) = err {
return Err(e);
}
match more {
Ok(Some(true)) => {
// We expect additional QTDP packets, so don't
// complete it yet.
}
Ok(None) | Ok(Some(false)) => {
ops.tracepoint_create_complete(tp).handle_error()?;
}
Err(e) => {
return Err(e);
}
}
}
};
// TODO: support qRelocInsn?
return Ok(HandlerStatus::NeedsOk);
}
Tracepoints::QTDPsrc(src) => {
if let Some(supports_sources) = ops.support_tracepoint_source() {
let source = SourceTracepoint::<<T::Arch as Arch>::Usize>::from_src(src)
.ok_or(Error::TargetMismatch)?;
supports_sources
.tracepoint_attach_source(source)
.handle_error()?;
// Documentation doesn't mention this, but it needs OK
return Ok(HandlerStatus::NeedsOk);
}
}
Tracepoints::qTBuffer(buf) => {
let qTBuffer { offset, length } = buf;
let mut wrote: Result<bool, Error<T::Error, C::Error>> = Ok(false);
ops.trace_buffer_request(offset, length, &mut |data| {
if let Err(e) = res.write_hex_buf(data) {
wrote = Err(e.into())
} else {
wrote = Ok(true)
}
})
.handle_error()?;
if !wrote? {
res.write_str("l")?;
}
}
Tracepoints::QTBuffer(conf) => {
ops.trace_buffer_configure(conf.0).handle_error()?;
// Documentation doesn't mention this, but it needs OK
return Ok(HandlerStatus::NeedsOk);
}
Tracepoints::QTStart(_) => {
ops.trace_experiment_start().handle_error()?;
// Documentation doesn't mention this, but it needs OK
// TODO: qRelocInsn reply support?
return Ok(HandlerStatus::NeedsOk);
}
Tracepoints::QTStop(_) => {
ops.trace_experiment_stop().handle_error()?;
// Documentation doesn't mention this, but it needs OK
return Ok(HandlerStatus::NeedsOk);
}
Tracepoints::QTFrame(req) => {
let parsed_qtframe: Option<FrameRequest<<T::Arch as Arch>::Usize>> = req.0.into();
let parsed_req = parsed_qtframe.ok_or(Error::TargetMismatch)?;
let mut err: Result<_, Error<T::Error, C::Error>> = Ok(());
let mut any_results = false;
ops.select_frame(parsed_req, &mut |desc| {
let e = (|| -> Result<_, _> {
match desc {
FrameDescription::FrameNumber(n) => {
res.write_str("F")?;
res.write_num(n)?;
any_results = true;
}
FrameDescription::Hit(tdp) => {
res.write_str("T")?;
res.write_num(tdp.0)?;
}
}
Ok(())
})();
if let Err(e) = e {
err = Err(e)
}
})
.handle_error()?;
if !any_results {
res.write_str("F-1")?;
}
}
// The GDB protocol for this is very weird: it sends this first packet
// to initialize a state machine on our stub, and then sends the subsequent
// packets N times in order to drive the state machine to the end in
// order to ask for all our tracepoints and their actions. gdbstub
// uses a target allocated state machine that it drives in response
// to these packets, so that it can provide a nice typed API.
Tracepoints::qTfP(_) => {
// Reset our state machine
let state = ops.tracepoint_enumerate_state();
state.cursor = None;
let mut err: Option<Error<T::Error, C::Error>> = None;
let mut started = None;
let step = ops
.tracepoint_enumerate_start(None, &mut |ctp| {
// We need to know what tracepoint to begin stepping, since the
// target will just tell us there's TracepointEnumerateStep::More
// otherwise.
started = Some((ctp.number, ctp.addr));
let e = ctp.write::<T, C>(res);
if let Err(e) = e {
err = Some(e)
}
})
.handle_error()?;
if let Some(e) = err {
return Err(e);
}
if let Some((tp, addr)) = started {
ops.tracepoint_enumerate_state().cursor =
Some(TracepointEnumerateCursor::New { tp, addr });
}
self.handle_tracepoint_state_machine_step(target, step)?;
}
Tracepoints::qTsP(_) => {
let state = ops.tracepoint_enumerate_state();
let mut err: Option<Error<T::Error, C::Error>> = None;
let step = match state.cursor {
None => {
// If we don't have a cursor, than the last
// packet responded
// with a TracepointEnumerateStep::Done. We don't have
// anything else to report.
None
}
Some(TracepointEnumerateCursor::New { tp, .. }) => {
// If we don't have any progress, the last packet was
// a Next(tp) and we need to start reporting a new tracepoint
Some(
ops.tracepoint_enumerate_start(Some(tp), &mut |ctp| {
let e = ctp.write::<T, C>(res);
if let Err(e) = e {
err = Some(e)
}
})
.handle_error()?,
)
}
Some(TracepointEnumerateCursor::Action { tp, addr, step }) => {
// Otherwise we should be continuing the advance the current tracepoint.
Some(
ops.tracepoint_enumerate_action(tp, step, &mut |action| {
let e = action.write::<T, C>(tp, addr, res);
if let Err(e) = e {
err = Some(e)
}
})
.handle_error()?,
)
}
Some(TracepointEnumerateCursor::Source { tp, step, .. }) => {
if let Some(supports_sources) = ops.support_tracepoint_source() {
Some(
supports_sources
.tracepoint_enumerate_source(tp, step, &mut |src| {
let e = src.write::<T, C>(res);
if let Err(e) = e {
err = Some(e)
}
})
.handle_error()?,
)
} else {
// If the target doesn't support tracepoint sources but told
// us to enumerate one anyways, then the target has an error.
return Err(Error::TracepointUnsupportedSourceEnumeration);
}
}
};
if let Some(e) = err {
return Err(e);
}
if let Some(step) = step {
self.handle_tracepoint_state_machine_step(target, step)?;
}
}
// Likewise, the same type of driven state machine is used for trace
// state variables
Tracepoints::qTfV(_) => {
// TODO: State variables
}
Tracepoints::qTsV(_) => {
// TODO: State variables
}
};
Ok(HandlerStatus::Handled)
}
fn handle_tracepoint_state_machine_step(
&mut self,
target: &mut T,
step: TracepointEnumerateStep<<T::Arch as Arch>::Usize>,
) -> Result<(), Error<T::Error, C::Error>> {
let ops = match target.support_tracepoints() {
Some(ops) => ops,
None => return Ok(()),
};
let state = ops.tracepoint_enumerate_state();
let next = match (state.cursor.as_ref(), step) {
(None, _) => None,
(Some(_), TracepointEnumerateStep::Done) => None,
// Transition to enumerating actions
(
Some(&TracepointEnumerateCursor::New { tp, addr }),
TracepointEnumerateStep::Action,
) => Some(TracepointEnumerateCursor::Action { tp, addr, step: 0 }),
(
Some(&TracepointEnumerateCursor::Source { tp, addr, .. }),
TracepointEnumerateStep::Action,
) => Some(TracepointEnumerateCursor::Action { tp, addr, step: 0 }),
(
Some(&TracepointEnumerateCursor::Action { tp, addr, step }),
TracepointEnumerateStep::Action,
) => Some(TracepointEnumerateCursor::Action {
tp,
addr,
step: step + 1,
}),
// Transition to enumerating sources
(
Some(
&TracepointEnumerateCursor::New { tp, addr }
| &TracepointEnumerateCursor::Action { tp, addr, .. },
),
TracepointEnumerateStep::Source,
) => Some(TracepointEnumerateCursor::Source { tp, addr, step: 0 }),
(
Some(&TracepointEnumerateCursor::Source { tp, addr, step }),
TracepointEnumerateStep::Source,
) => Some(TracepointEnumerateCursor::Source {
tp,
addr,
step: step + 1,
}),
// Transition to the next tracepoint
(Some(_), TracepointEnumerateStep::Next { tp, addr }) => {
Some(TracepointEnumerateCursor::New { tp, addr })
}
};
state.cursor = next;
Ok(())
}
}