Skip to main content

iptr_edge_analyzer/
diagnose.rs

1//! Module handling diagnostic information.
2
3use crate::{EdgeAnalyzer, HandleControlFlow, ReadMemory};
4
5/// Diagnostic information for [`EdgeAnalyzer`].
6///
7/// This struct can be retrieved from [`EdgeAnalyzer::diagnose`]
8pub struct DiagnosticInformation {
9    /// Size of CFG graph, i.e., number of nodes
10    pub cfg_size: usize,
11    /// Size of trailing bits cache, i.e., number of entries
12    #[cfg(feature = "cache")]
13    pub cache_trailing_bits_size: usize,
14    /// Size of 8bit cache, i.e., number of entries
15    #[cfg(feature = "cache")]
16    pub cache8_size: usize,
17    /// Size of 32bit cache, i.e., number of entries
18    #[cfg(feature = "cache")]
19    pub cache32_size: usize,
20    /// Count of trailing bits cache hit
21    #[cfg(all(feature = "cache", feature = "more_diagnose"))]
22    pub cache_trailing_bits_hit_count: usize,
23    /// Count of 8bit cache hit
24    #[cfg(all(feature = "cache", feature = "more_diagnose"))]
25    pub cache_8bit_hit_count: usize,
26    /// Count of 32bit cache hit
27    #[cfg(all(feature = "cache", feature = "more_diagnose"))]
28    pub cache_32bit_hit_count: usize,
29    /// Count of missed cache hit, i.e., directly CFG resolution
30    #[cfg(all(feature = "cache", feature = "more_diagnose"))]
31    pub cache_missed_bit_count: usize,
32}
33
34impl<H: HandleControlFlow, R: ReadMemory> EdgeAnalyzer<H, R> {
35    /// Get diagnostic information
36    #[must_use]
37    pub fn diagnose(&self) -> DiagnosticInformation {
38        let cfg_size = self.static_analyzer.cfg_size();
39        #[cfg(feature = "cache")]
40        let (cache_trailing_bits_size, cache8_size, cache32_size) = self.cache_manager.cache_size();
41
42        DiagnosticInformation {
43            cfg_size,
44            #[cfg(feature = "cache")]
45            cache_trailing_bits_size,
46            #[cfg(feature = "cache")]
47            cache8_size,
48            #[cfg(feature = "cache")]
49            cache32_size,
50            #[cfg(all(feature = "cache", feature = "more_diagnose"))]
51            cache_32bit_hit_count: self.cache_32bit_hit_count,
52            #[cfg(all(feature = "cache", feature = "more_diagnose"))]
53            cache_8bit_hit_count: self.cache_8bit_hit_count,
54            #[cfg(all(feature = "cache", feature = "more_diagnose"))]
55            cache_trailing_bits_hit_count: self.cache_trailing_bits_hit_count,
56            #[cfg(all(feature = "cache", feature = "more_diagnose"))]
57            cache_missed_bit_count: self.cache_missed_bit_count,
58        }
59    }
60}