1- use crate :: insn:: Class ;
21use crate :: event:: ExecModeType ;
3- use std :: convert :: TryFrom ;
2+ use crate :: insn :: Class ;
43use libipt_sys:: pt_block;
4+ use std:: convert:: TryFrom ;
55
66#[ cfg( test) ]
77mod test {
88 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} ;
1310
1411 #[ test]
1512 fn test_block_props ( ) {
@@ -25,18 +22,18 @@ mod test {
2522 size : 8 ,
2623 _bitfield_align_1 : [ ] ,
2724 _bitfield_1 : pt_block:: new_bitfield_1 ( 0 , 1 ) ,
28- __bindgen_padding_0 : Default :: default ( )
29- } ) ;
25+ __bindgen_padding_0 : Default :: default ( ) ,
26+ } ) ;
3027
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( ) ) ;
4037 }
4138
4239 #[ test]
@@ -53,46 +50,52 @@ mod test {
5350 size : 8 ,
5451 _bitfield_align_1 : [ ] ,
5552 _bitfield_1 : pt_block:: new_bitfield_1 ( 0 , 0 ) ,
56- __bindgen_padding_0 : Default :: default ( )
57- } ) ;
53+ __bindgen_padding_0 : Default :: default ( ) ,
54+ } ) ;
5855
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( ) ) ;
6865 }
6966}
7067
7168/// A block of instructions.
7269///
7370/// Instructions in this block are executed sequentially but are not necessarily
7471/// contiguous in memory. Users are expected to follow direct branches.
75- #[ derive( Clone , Copy ) ]
72+ #[ derive( Debug , Clone , Copy ) ]
7673pub struct Block ( pub ( super ) pt_block ) ;
7774impl Block {
7875 /// 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+ }
8079
8180 /// The IP of the last instruction in this block.
8281 ///
8382 /// 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+ }
8586
8687 /// The image section that contains the instructions in this block.
8788 ///
8889 /// A value of zero means that the section did not have an identifier.
8990 /// The section was not added via an image section cache or the memory
9091 /// 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+ }
9295
9396 /// The execution mode for all instructions in this block.
9497 pub fn mode ( & self ) -> ExecModeType {
95- ExecModeType :: try_from ( self . 0 . mode ) . unwrap ( )
98+ ExecModeType :: try_from ( self . 0 . mode as u32 ) . unwrap ( )
9699 }
97100
98101 /// The instruction class for the last instruction in this block.
@@ -101,11 +104,13 @@ impl Block {
101104 /// class is not available. The block decoder may choose to not provide
102105 /// the instruction class in some cases for performance reasons.
103106 pub fn class ( & self ) -> Class {
104- Class :: try_from ( self . 0 . iclass ) . unwrap ( )
107+ Class :: try_from ( self . 0 . iclass as u32 ) . unwrap ( )
105108 }
106109
107110 /// 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+ }
109114
110115 /// The raw bytes of the last instruction in this block in case the
111116 /// instruction does not fit entirely into this block's section.
@@ -119,7 +124,9 @@ impl Block {
119124 /// instructions in this block.
120125 ///
121126 /// - 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+ }
123130
124131 /// A collection of flags giving additional information about the
125132 /// instructions in this block.
@@ -131,5 +138,7 @@ impl Block {
131138 ///
132139 /// The raw bytes for the last instruction are provided in \@raw and
133140 /// 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+ }
135144}
0 commit comments