1 use super::prelude::*; 2 use crate::target::ext::tracepoints::Tracepoint; 3 4 #[derive(Debug)] 5 #[allow(clippy::upper_case_acronyms)] 6 pub enum QTDP<'a> { 7 Create(CreateTDP<'a>), 8 Extend(ExtendTDP<'a>), 9 } 10 11 #[derive(Debug)] 12 pub struct CreateTDP<'a> { 13 pub number: Tracepoint, 14 pub addr: &'a [u8], 15 pub enable: bool, 16 pub step: u64, 17 pub pass: u64, 18 pub unsupported_option: Option<u8>, 19 pub more: bool, 20 } 21 22 #[derive(Debug)] 23 pub struct ExtendTDP<'a> { 24 pub number: Tracepoint, 25 pub addr: &'a [u8], 26 pub actions: &'a mut [u8], 27 } 28 29 impl<'a> ParseCommand<'a> for QTDP<'a> { 30 #[inline(always)] from_packet(buf: PacketBuf<'a>) -> Option<Self>31 fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { 32 let body = buf.into_body(); 33 match body { 34 [b':', b'-', actions @ ..] => { 35 let mut params = actions.splitn_mut(4, |b| *b == b':'); 36 let number = Tracepoint(decode_hex(params.next()?).ok()?); 37 let addr = decode_hex_buf(params.next()?).ok()?; 38 let actions = params.next()?; 39 Some(QTDP::Extend(ExtendTDP { 40 number, 41 addr, 42 actions, 43 })) 44 } 45 [b':', tracepoint @ ..] => { 46 // Strip off the trailing '-' that indicates if there will be 47 // more packets after this 48 let (tracepoint, more) = match tracepoint { 49 [rest @ .., b'-'] => (rest, true), 50 x => (x, false), 51 }; 52 let mut params = tracepoint.splitn_mut(6, |b| *b == b':'); 53 let n = Tracepoint(decode_hex(params.next()?).ok()?); 54 let addr = decode_hex_buf(params.next()?).ok()?; 55 let ena = params.next()?; 56 let step = decode_hex(params.next()?).ok()?; 57 let pass_and_end = params.next()?; 58 let pass = decode_hex(pass_and_end).ok()?; 59 // TODO: parse `F` fast tracepoint options 60 // TODO: parse `X` tracepoint conditions 61 let options = params.next(); 62 let unsupported_option = match options { 63 Some([b'F', ..]) => { 64 /* TODO: fast tracepoints support */ 65 Some(b'F') 66 } 67 Some([b'S']) => { 68 /* TODO: static tracepoint support */ 69 Some(b'S') 70 } 71 Some([b'X', ..]) => { 72 /* TODO: trace conditions support */ 73 Some(b'X') 74 } 75 Some(_) => { 76 /* invalid option */ 77 return None; 78 } 79 None => None, 80 }; 81 Some(QTDP::Create(CreateTDP { 82 number: n, 83 addr, 84 enable: match ena { 85 [b'E'] => Some(true), 86 [b'D'] => Some(false), 87 _ => None, 88 }?, 89 step, 90 pass, 91 more, 92 unsupported_option, 93 })) 94 } 95 _ => None, 96 } 97 } 98 } 99