Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182-- | DWARF write support: binary and assembly text output.---- This is the top-level module for DWARF writing. It provides:---- * Binary output via 'writeSections' — produces @.debug_info@,-- @.debug_abbrev@, and @.debug_str@ sections as 'ByteString' values.---- * Assembly text output via 'writeAssembly' — produces complete DWARF-- as assembly text suitable for GNU as.---- For lower-level control, use the sub-modules directly.module Data.Dwarf.Write ( -- * Binary output WriteSections(..) , writeSections
-- * Binary output with relocations , WriteSectionsReloc(..) , writeSectionsReloc
-- * Split DWARF (.dwo) output , WriteDwoSections(..) , writeDwoSections , writeDwoSectionsWithExtras
-- * Assembly text output , writeAssembly
-- * Re-exports , module Data.Dwarf.Write.Abbrev , module Data.Dwarf.Write.Str , module Data.Dwarf.Write.Attr , module Data.Dwarf.Write.Die , module Data.Dwarf.Write.Unit , module Data.Dwarf.Write.Op , module Data.Dwarf.Write.Asm , module Data.Dwarf.Write.Reloc , module Data.Dwarf.Write.Frame , module Data.Dwarf.Write.EhFrame , module Data.Dwarf.Write.CuIndex , module Data.Dwarf.Write.Macro , module Data.Dwarf.Write.Macinfo , module Data.Dwarf.Write.Aranges , module Data.Dwarf.Write.Pubnames ) where
import Data.ByteString (ByteString)import Data.ByteString.Builder (Builder)
import Data.Dwarf.Encoding (Endianness, Encoding)import Data.Dwarf.Read.Unit (Unit(..))
import Data.Dwarf.Write.Abbrevimport Data.Dwarf.Write.Strimport Data.Dwarf.Write.Attrimport Data.Dwarf.Write.Dieimport Data.Dwarf.Write.Unitimport Data.Dwarf.Write.Opimport Data.Dwarf.Write.Asmimport Data.Dwarf.Write.Relocimport Data.Dwarf.Write.Frameimport Data.Dwarf.Write.EhFrameimport Data.Dwarf.Write.CuIndeximport Data.Dwarf.Write.Macroimport Data.Dwarf.Write.Macinfoimport Data.Dwarf.Write.Arangesimport Data.Dwarf.Write.Pubnames
-------------------------------------------------------------------------- Binary output------------------------------------------------------------------------
-- | The DWARF sections produced by 'writeSections'.data WriteSections = WriteSections { wsDebugInfo :: !ByteString -- ^ Serialised @.debug_info@ section. , wsDebugAbbrev :: !ByteString -- ^ Serialised @.debug_abbrev@ section. , wsDebugStr :: !ByteString -- ^ Serialised @.debug_str@ section (pooled strings). } deriving stock (Show)
-- | Produce all DWARF sections as ByteStrings from a list of units.---- Pools all 'ValString' attributes into a shared @.debug_str@ section,-- replacing them with 'ValStrOffset' ('DW_FORM_strp').---- Returns 'Nothing' if a DIE shape lookup fails.writeSections :: Endianness -> Encoding -> [Unit] -> Maybe WriteSectionswriteSections e enc units = do (info, abbrev, str) <- writeDebugInfoPooled e enc units Just WriteSections { wsDebugInfo = info , wsDebugAbbrev = abbrev , wsDebugStr = str }
-------------------------------------------------------------------------- Binary output with relocations------------------------------------------------------------------------
-- | The DWARF sections with relocation information.data WriteSectionsReloc = WriteSectionsReloc { wsrDebugInfo :: !ByteString -- ^ Serialised @.debug_info@ section. , wsrDebugAbbrev :: !ByteString -- ^ Serialised @.debug_abbrev@ section. , wsrDebugStr :: !ByteString -- ^ Serialised @.debug_str@ section (pooled strings). , wsrInfoRelocs :: ![Relocation] -- ^ Relocations for the @.debug_info@ section. } deriving stock (Show)
-- | Like 'writeSections' but also computes relocations for the-- @.debug_info@ section. Consumers embedding DWARF in relocatable-- object files need these entries for cross-section references.---- Returns 'Nothing' if a DIE shape lookup fails.writeSectionsReloc :: Endianness -> Encoding -> [Unit] -> Maybe WriteSectionsRelocwriteSectionsReloc e enc units = do (info, abbrev, str) <- writeDebugInfoPooled e enc units relocs <- computeInfoRelocations e enc units Just WriteSectionsReloc { wsrDebugInfo = info , wsrDebugAbbrev = abbrev , wsrDebugStr = str , wsrInfoRelocs = relocs }
-------------------------------------------------------------------------- Split DWARF (.dwo) output------------------------------------------------------------------------
-- | The DWARF sections produced by 'writeDwoSections' for a @.dwo@ file.data WriteDwoSections = WriteDwoSections { wdDebugInfoDwo :: !ByteString -- ^ Serialised @.debug_info.dwo@ section. , wdDebugAbbrevDwo :: !ByteString -- ^ Serialised @.debug_abbrev.dwo@ section. , wdDebugStrDwo :: !ByteString -- ^ Serialised @.debug_str.dwo@ section. , wdDebugStrOffsetsDwo :: !ByteString -- ^ Serialised @.debug_str_offsets.dwo@ section. , wdDebugLineDwo :: !(Maybe ByteString) -- ^ Optional @.debug_line.dwo@ section. , wdDebugRngListsDwo :: !(Maybe ByteString) -- ^ Optional @.debug_rnglists.dwo@ section. , wdDebugLocListsDwo :: !(Maybe ByteString) -- ^ Optional @.debug_loclists.dwo@ section. , wdDebugMacroDwo :: !(Maybe ByteString) -- ^ Optional @.debug_macro.dwo@ section. } deriving stock (Show)
-- | Produce all @.dwo@ sections as ByteStrings from a list of units.---- Pools all 'ValString' attributes into a shared @.debug_str.dwo@ section,-- replacing them with 'ValStrIndex' ('DW_FORM_strx'). Generates the-- corresponding @.debug_str_offsets.dwo@ table.---- Optional sections (@.debug_line.dwo@, @.debug_rnglists.dwo@,-- @.debug_loclists.dwo@) can be passed as pre-serialised 'ByteString's.-- Use the existing 'writeLineProgram', 'writeDebugRngLists', and-- 'writeDebugLocLists' to produce them.---- Returns 'Nothing' if a DIE shape lookup fails.writeDwoSections :: Endianness -> Encoding -> [Unit] -> Maybe WriteDwoSectionswriteDwoSections e enc units = writeDwoSectionsWithExtras e enc units Nothing Nothing Nothing Nothing
-- | Like 'writeDwoSections' but with optional extra sections.writeDwoSectionsWithExtras :: Endianness -> Encoding -> [Unit] -> Maybe ByteString -- ^ @.debug_line.dwo@ -> Maybe ByteString -- ^ @.debug_rnglists.dwo@ -> Maybe ByteString -- ^ @.debug_loclists.dwo@ -> Maybe ByteString -- ^ @.debug_macro.dwo@ -> Maybe WriteDwoSectionswriteDwoSectionsWithExtras e enc units mLine mRngLists mLocLists mMacro = do (info, abbrev, str, strOff) <- writeDebugInfoDwoPooled e enc units Just WriteDwoSections { wdDebugInfoDwo = info , wdDebugAbbrevDwo = abbrev , wdDebugStrDwo = str , wdDebugStrOffsetsDwo = strOff , wdDebugLineDwo = mLine , wdDebugRngListsDwo = mRngLists , wdDebugLocListsDwo = mLocLists , wdDebugMacroDwo = mMacro }
-------------------------------------------------------------------------- Assembly text output------------------------------------------------------------------------
-- | Produce complete DWARF as assembly text from a list of units.-- Returns 'Nothing' if a DIE shape lookup fails.writeAssembly :: AsmConfig -> [Unit] -> Maybe BuilderwriteAssembly = asmDebugInfo