Commit f85db756 authored by Peter Wortmann's avatar Peter Wortmann Committed by Austin Seipp

Some Dwarf generation fixes

- Make abbrev offset absolute on Non-Mac systems
- Add another termination byte at the end of the abbrev section
  (readelf complains)
- Scope combination was wrong for the simpler cases
- Shouldn't have a "global/" in front of all scopes
parent 4c02b6f5
......@@ -660,6 +660,8 @@ instance Ord CmmTickScope where
instance Outputable CmmTickScope where
ppr GlobalScope = text "global"
ppr (SubScope us GlobalScope)
= ppr us
ppr (SubScope us s) = ppr s <> char '/' <> ppr us
ppr combined = parens $ hcat $ punctuate (char '+') $
map (hcat . punctuate (char '/') . map ppr . reverse) $
......@@ -675,10 +677,11 @@ isTickSubScope = cmp
cmp s (CombinedScope s1' s2') = cmp s s1' || cmp s s2'
cmp (SubScope u s) s'@(SubScope u' _) = u == u' || cmp s s'
-- | Combine two tick scopes. This smart constructor will catch cases
-- where one tick scope is a sub-scope of the other already.
-- | Combine two tick scopes. The new scope should be sub-scope of
-- both parameters. We simplfy automatically if one tick scope is a
-- sub-scope of the other already.
combineTickScopes :: CmmTickScope -> CmmTickScope -> CmmTickScope
combineTickScopes s1 s2
| s1 `isTickSubScope` s2 = s2
| s2 `isTickSubScope` s1 = s1
| s1 `isTickSubScope` s2 = s1
| s2 `isTickSubScope` s1 = s2
| otherwise = CombinedScope s1 s2
......@@ -83,8 +83,8 @@ compileUnitHeader unitU = sdocWithPlatform $ \plat ->
in vcat [ ptext (sLit "\t.long ") <> length -- compilation unit size
, ppr cuLabel <> colon
, ptext (sLit "\t.word 3") -- DWARF version
, pprDwWord (ptext dwarfAbbrevLabel <> char '-' <>
ptext dwarfAbbrevLabel) -- pointer to our abbrevs
, pprDwWord (sectionOffset dwarfAbbrevLabel dwarfAbbrevLabel)
-- abbrevs offset
, ptext (sLit "\t.byte ") <> ppr (platformWordSize plat) -- word size
]
......
......@@ -14,6 +14,7 @@ module Dwarf.Types
, pprLEBWord
, pprLEBInt
, wordAlign
, sectionOffset
)
where
......@@ -94,7 +95,9 @@ pprAbbrevDecls haveDebugLine =
[ (dW_AT_name, dW_FORM_string)
, (dW_AT_low_pc, dW_FORM_addr)
, (dW_AT_high_pc, dW_FORM_addr)
]
] $$
pprByte 0
-- | Generate assembly for DWARF data
pprDwarfInfo :: Bool -> DwarfInfo -> SDoc
pprDwarfInfo haveSrc d
......@@ -113,7 +116,7 @@ pprDwarfInfoOpen haveSrc (DwarfCompileUnit _ name producer compDir lineLbl) =
$$ pprData4 dW_LANG_Haskell
$$ pprString compDir
$$ if haveSrc
then pprData4' (ptext lineLbl <> char '-' <> ptext dwarfLineLabel)
then pprData4' (sectionOffset lineLbl dwarfLineLabel)
else empty
pprDwarfInfoOpen _ (DwarfSubprogram _ name label) = sdocWithDynFlags $ \df ->
pprAbbrev DwAbbrSubprogram
......@@ -416,3 +419,14 @@ pprString = pprString' . hcat . map escape
char (intToDigit (ch `div` 64)) <>
char (intToDigit ((ch `div` 8) `mod` 8)) <>
char (intToDigit (ch `mod` 8))
-- | Generate an offset into another section. This is tricky because
-- this is handled differently depending on platform: Mac Os expects
-- us to calculate the offset using assembler arithmetic. Meanwhile,
-- GNU tools expect us to just reference the target directly, and will
-- figure out on their own that we actually need an offset.
sectionOffset :: LitString -> LitString -> SDoc
sectionOffset target section = sdocWithPlatform $ \plat ->
case platformOS plat of
OSDarwin -> ptext target <> char '-' <> ptext section
_other -> ptext target
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment