-- | DWARF encoding parameters: endianness, format (32/64-bit), and -- the combined 'Encoding' record used throughout parsing. module Data.Dwarf.Encoding ( -- * Endianness Endianness(..) -- * DWARF format , Format(..) , formatWordSize , formatInitialLengthSize -- * Combined encoding parameters , Encoding(..) ) where import Data.Word (Word8) ------------------------------------------------------------------------ -- Endianness ------------------------------------------------------------------------ -- | Byte order for multi-byte values. data Endianness = LittleEndian | BigEndian deriving stock (Eq, Ord, Show) ------------------------------------------------------------------------ -- DWARF format (32-bit vs 64-bit) ------------------------------------------------------------------------ -- | DWARF uses two formats which affect the size of section offsets -- and the initial length field. The vast majority of DWARF data uses -- 'Dwarf32'; 'Dwarf64' exists for debug information exceeding 4 GiB. data Format = Dwarf32 -- ^ 4-byte section offsets | Dwarf64 -- ^ 8-byte section offsets deriving stock (Eq, Ord, Show) -- | Size in bytes of a section offset in this format. -- -- >>> formatWordSize Dwarf32 -- 4 -- >>> formatWordSize Dwarf64 -- 8 formatWordSize :: Format -> Word8 formatWordSize Dwarf32 = 4 formatWordSize Dwarf64 = 8 -- | Size in bytes of the initial length field (including the 64-bit sentinel). -- -- >>> formatInitialLengthSize Dwarf32 -- 4 -- >>> formatInitialLengthSize Dwarf64 -- 12 formatInitialLengthSize :: Format -> Word8 formatInitialLengthSize Dwarf32 = 4 formatInitialLengthSize Dwarf64 = 12 ------------------------------------------------------------------------ -- Combined encoding parameters ------------------------------------------------------------------------ -- | The three parameters that together determine how to decode most -- DWARF structures: the DWARF version, the target address size, and -- the 32/64-bit format. data Encoding = Encoding { encodingVersion :: {-# UNPACK #-} !Int -- ^ DWARF version (2, 3, 4, or 5). , encodingAddressSize :: {-# UNPACK #-} !Word8 -- ^ Size of a target address in bytes (typically 4 or 8). , encodingFormat :: !Format -- ^ 32-bit or 64-bit DWARF format. } deriving stock (Eq, Show)