Debian Codegraph @

third_party/rust/macho-unwind-info/src/raw/compressed_function.rs

raw
1 use crate::num_display::HexNum;
2 use std::fmt::Debug;
3
4 /// Allows accessing the two packed values from a "compressed" function entry.
5 #[derive(Clone, Copy, PartialEq, Eq)]
6 pub struct CompressedFunctionEntry(pub u32);
7
8 /// Entries are a u32 that contains two packed values (from high to low):
9 /// * 8 bits: opcode index
10 /// * 24 bits: function address
11 impl CompressedFunctionEntry {
12 /// Wrap the u32.
13 pub fn new(value: u32) -> Self {
14 Self(value)
15 }
16
17 /// The opcode index.
18 /// * 0..global_opcodes_len => index into global palette
19 /// * global_opcodes_len..255 => index into local palette
20 /// (subtract global_opcodes_len to get the real local index)
21 pub fn opcode_index(&self) -> u8 {
22 (self.0 >> 24) as u8
23 }
24
25 /// The function address, relative to the page's first_address.
26 pub fn relative_address(&self) -> u32 {
27 self.0 & 0xffffff
28 }
29 }
30
31 impl From<u32> for CompressedFunctionEntry {
32 fn from(entry: u32) -> CompressedFunctionEntry {
33 CompressedFunctionEntry::new(entry)
34 }
35 }
36
37 impl Debug for CompressedFunctionEntry {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 f.debug_struct("CompressedFunctionEntry")
40 .field("opcode_index", &HexNum(self.opcode_index()))
41 .field("relative_address", &HexNum(self.relative_address()))
42 .finish()
43 }
44 }