1
- use crate :: insn:: Class ;
2
1
use crate :: event:: ExecModeType ;
3
- use std :: convert :: TryFrom ;
2
+ use crate :: insn :: Class ;
4
3
use libipt_sys:: pt_block;
4
+ use std:: convert:: TryFrom ;
5
5
6
6
#[ cfg( test) ]
7
7
mod test {
8
8
use super :: * ;
9
- use libipt_sys:: {
10
- pt_exec_mode_ptem_32bit,
11
- pt_insn_class_ptic_error,
12
- } ;
9
+ use libipt_sys:: { pt_exec_mode_ptem_32bit, pt_insn_class_ptic_error} ;
13
10
14
11
#[ test]
15
12
fn test_block_props ( ) {
@@ -25,18 +22,18 @@ mod test {
25
22
size : 8 ,
26
23
_bitfield_align_1 : [ ] ,
27
24
_bitfield_1 : pt_block:: new_bitfield_1 ( 0 , 1 ) ,
28
- __bindgen_padding_0 : Default :: default ( )
29
- } ) ;
25
+ __bindgen_padding_0 : Default :: default ( ) ,
26
+ } ) ;
30
27
31
- assert_eq ! ( blk. ip( ) , 1 ) ;
32
- assert_eq ! ( blk. end_ip( ) , 2 ) ;
33
- assert_eq ! ( blk. isid( ) , 3 ) ;
34
- assert_eq ! ( blk. mode( ) , ExecModeType :: Bit32 ) ;
35
- assert_eq ! ( blk. class( ) , Class :: Error ) ;
36
- assert_eq ! ( blk. ninsn( ) , 4 ) ;
37
- assert_eq ! ( blk. raw( ) , & data[ ..8 ] ) ;
38
- assert ! ( blk. truncated( ) ) ;
39
- assert ! ( !blk. speculative( ) ) ;
28
+ assert_eq ! ( blk. ip( ) , 1 ) ;
29
+ assert_eq ! ( blk. end_ip( ) , 2 ) ;
30
+ assert_eq ! ( blk. isid( ) , 3 ) ;
31
+ assert_eq ! ( blk. mode( ) , ExecModeType :: Bit32 ) ;
32
+ assert_eq ! ( blk. class( ) , Class :: Error ) ;
33
+ assert_eq ! ( blk. ninsn( ) , 4 ) ;
34
+ assert_eq ! ( blk. raw( ) , & data[ ..8 ] ) ;
35
+ assert ! ( blk. truncated( ) ) ;
36
+ assert ! ( !blk. speculative( ) ) ;
40
37
}
41
38
42
39
#[ test]
@@ -53,18 +50,18 @@ mod test {
53
50
size : 8 ,
54
51
_bitfield_align_1 : [ ] ,
55
52
_bitfield_1 : pt_block:: new_bitfield_1 ( 0 , 0 ) ,
56
- __bindgen_padding_0 : Default :: default ( )
57
- } ) ;
53
+ __bindgen_padding_0 : Default :: default ( ) ,
54
+ } ) ;
58
55
59
- assert_eq ! ( blk. ip( ) , 1 ) ;
60
- assert_eq ! ( blk. end_ip( ) , 2 ) ;
61
- assert_eq ! ( blk. isid( ) , 3 ) ;
62
- assert_eq ! ( blk. mode( ) , ExecModeType :: Bit32 ) ;
63
- assert_eq ! ( blk. class( ) , Class :: Error ) ;
64
- assert_eq ! ( blk. ninsn( ) , 4 ) ;
65
- assert ! ( blk. raw( ) . len( ) > 0 ) ;
66
- assert ! ( !blk. truncated( ) ) ;
67
- assert ! ( !blk. speculative( ) ) ;
56
+ assert_eq ! ( blk. ip( ) , 1 ) ;
57
+ assert_eq ! ( blk. end_ip( ) , 2 ) ;
58
+ assert_eq ! ( blk. isid( ) , 3 ) ;
59
+ assert_eq ! ( blk. mode( ) , ExecModeType :: Bit32 ) ;
60
+ assert_eq ! ( blk. class( ) , Class :: Error ) ;
61
+ assert_eq ! ( blk. ninsn( ) , 4 ) ;
62
+ assert ! ( blk. raw( ) . len( ) > 0 ) ;
63
+ assert ! ( !blk. truncated( ) ) ;
64
+ assert ! ( !blk. speculative( ) ) ;
68
65
}
69
66
}
70
67
@@ -76,19 +73,25 @@ mod test {
76
73
pub struct Block ( pub ( super ) pt_block ) ;
77
74
impl Block {
78
75
/// The IP of the first instruction in this block.
79
- pub fn ip ( & self ) -> u64 { self . 0 . ip }
76
+ pub fn ip ( & self ) -> u64 {
77
+ self . 0 . ip
78
+ }
80
79
81
80
/// The IP of the last instruction in this block.
82
81
///
83
82
/// This can be used for error-detection.
84
- pub fn end_ip ( & self ) -> u64 { self . 0 . end_ip }
83
+ pub fn end_ip ( & self ) -> u64 {
84
+ self . 0 . end_ip
85
+ }
85
86
86
87
/// The image section that contains the instructions in this block.
87
88
///
88
89
/// A value of zero means that the section did not have an identifier.
89
90
/// The section was not added via an image section cache or the memory
90
91
/// was read via the read memory callback.
91
- pub fn isid ( & self ) -> i32 { self . 0 . isid }
92
+ pub fn isid ( & self ) -> i32 {
93
+ self . 0 . isid
94
+ }
92
95
93
96
/// The execution mode for all instructions in this block.
94
97
pub fn mode ( & self ) -> ExecModeType {
@@ -105,7 +108,9 @@ impl Block {
105
108
}
106
109
107
110
/// The number of instructions in this block.
108
- pub fn ninsn ( & self ) -> u16 { self . 0 . ninsn }
111
+ pub fn ninsn ( & self ) -> u16 {
112
+ self . 0 . ninsn
113
+ }
109
114
110
115
/// The raw bytes of the last instruction in this block in case the
111
116
/// instruction does not fit entirely into this block's section.
@@ -119,7 +124,9 @@ impl Block {
119
124
/// instructions in this block.
120
125
///
121
126
/// - all instructions in this block were executed speculatively.
122
- pub fn speculative ( & self ) -> bool { self . 0 . speculative ( ) > 0 }
127
+ pub fn speculative ( & self ) -> bool {
128
+ self . 0 . speculative ( ) > 0
129
+ }
123
130
124
131
/// A collection of flags giving additional information about the
125
132
/// instructions in this block.
@@ -131,5 +138,7 @@ impl Block {
131
138
///
132
139
/// The raw bytes for the last instruction are provided in \@raw and
133
140
/// its size in \@size in this case.
134
- pub fn truncated ( & self ) -> bool { self . 0 . truncated ( ) > 0 }
141
+ pub fn truncated ( & self ) -> bool {
142
+ self . 0 . truncated ( ) > 0
143
+ }
135
144
}
0 commit comments