Re: More on FreeBSD/amd64
Hi Ian, On Mar 29, 2007, at 8:36 PM, Ian Lynagh wrote:
Hmm, oh well.
OK, so we know that the wrong value is being passed to newPinnedByteArray#, right? There aren't many calls to that:
libraries/base/Foreign/Marshal/Alloc.hs libraries/base/GHC/ForeignPtr.hs (4 calls) libraries/base/GHC/Handle.hs
so the easiest way forward is probably to print something unique, and the size passed, in each one and try to work backwards towards the source. e.g.
mallocPlainForeignPtrBytes (I# size) = IO $ \s -> case newPinnedByteArray# size s of { (# s, mbarr# #) ->
=>
mallocPlainForeignPtrBytes i@(I# size) = do print ('A', i) IO $ \s -> case newPinnedByteArray# size s of { (# s, mbarr# #) ->
(it might be worth printing something after the existing IO action as well, just to avoid confusion as to what is happening.
Is there a version of "print" I can use for debugging these libraries? Just adding "print" causes a cycle in module dependencies. I can now start gdb instruction stepping close to the crash and it looks as if the trouble comes from mallocForeignPtr. I'm trying to find out what calls that now. Best Wishes, Greg
Hi Gregory, On Sun, Apr 01, 2007 at 03:40:11PM -0400, Gregory Wright wrote:
mallocPlainForeignPtrBytes i@(I# size) = do print ('A', i) IO $ \s -> case newPinnedByteArray# size s of { (# s, mbarr# #) ->
(it might be worth printing something after the existing IO action as well, just to avoid confusion as to what is happening.
Is there a version of "print" I can use for debugging these libraries? Just adding "print" causes a cycle in module dependencies.
Ah, remove the #if/#endif around the definition of "puts", its export, and the GHC.Pack import in libraries/base/GHC/Handle.hs Thanks Ian
Hi Ian, On Apr 1, 2007, at 3:57 PM, Ian Lynagh wrote:
Hi Gregory,
Is there a version of "print" I can use for debugging these libraries? Just adding "print" causes a cycle in module dependencies.
Ah, remove the #if/#endif around the definition of "puts", its export, and the GHC.Pack import in libraries/base/GHC/Handle.hs
No such luck. I even copied "puts" into libraries/base/GHC/
ForeignPtr.hs
but I still get I cycle because I need withCString to define "puts":
Module imports form a cycle for modules:
GHC.ForeignPtr
imports: GHC.Show GHC.Err GHC.Ptr GHC.IOBase GHC.Base GHC.List
Foreign.Storable Foreign.Ptr Foreign.C Control.Monad
Foreign.C imports: Foreign.C.Error Foreign.C.String Foreign.C.Types
Foreign.C.Error
imports: GHC.Base GHC.Num GHC.IOBase Data.Maybe
Foreign.Marshal.Error Foreign.C.String Foreign.C.Types
Foreign.Ptr
Foreign.Storable GHC.IOBase
Foreign.C.String
imports: GHC.Base GHC.IOBase GHC.Num GHC.Real GHC.List Data.Word
Foreign.Storable Foreign.Ptr Foreign.C.Types
Foreign.Marshal.Array
Foreign.C.Types
Data.Typeable
imports: GHC.Arr GHC.Stable GHC.ForeignPtr GHC.Ptr GHC.STRef GHC.ST
GHC.IOBase GHC.IOBase GHC.Real GHC.Float GHC.Num
GHC.Err GHC.Show
GHC.Base Data.List Data.Word Data.Int Data.Either
Data.Maybe
Data.HashTable
Foreign.Marshal.Array
imports: GHC.Base GHC.Err GHC.List GHC.Num GHC.IOBase
Foreign.Marshal.Utils Foreign.Marshal.Alloc
Foreign.Storable
Foreign.Ptr Control.Monad
Foreign.Marshal.Utils
imports: GHC.Base GHC.Num GHC.Real GHC.IOBase Foreign.Marshal.Alloc
Foreign.C.Types Foreign.Storable Foreign.Ptr Data.Maybe
Foreign.Marshal.Alloc
imports: GHC.Num GHC.Base GHC.Err GHC.Ptr GHC.Real GHC.IOBase
Foreign.ForeignPtr Foreign.Storable Foreign.C.Types
Foreign.Ptr
Data.Maybe
Foreign.ForeignPtr
imports: GHC.ForeignPtr GHC.Err GHC.Num GHC.IOBase GHC.Base
Foreign.Storable Foreign.Ptr
<
On Sun, Apr 01, 2007 at 06:10:25PM -0400, Gregory Wright wrote:
Ah, remove the #if/#endif around the definition of "puts", its export, and the GHC.Pack import in libraries/base/GHC/Handle.hs
No such luck. I even copied "puts" into libraries/base/GHC/ ForeignPtr.hs but I still get I cycle because I need withCString to define "puts":
Oh, the 6.4.2 definition is different to the 6.6 definition. Does the 6.6 one work with 6.4.2?: puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (fromIntegral (length s)) return () (packCString# come from GHC.Pack) Thanks Ian
Hi Ian, On Apr 1, 2007, at 6:22 PM, Ian Lynagh wrote:
On Sun, Apr 01, 2007 at 06:10:25PM -0400, Gregory Wright wrote:
Ah, remove the #if/#endif around the definition of "puts", its export, and the GHC.Pack import in libraries/base/GHC/Handle.hs
No such luck. I even copied "puts" into libraries/base/GHC/ ForeignPtr.hs but I still get I cycle because I need withCString to define "puts":
Oh, the 6.4.2 definition is different to the 6.6 definition.
Does the 6.6 one work with 6.4.2?:
puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (fromIntegral (length s)) return ()
(packCString# come from GHC.Pack)
Still doesn't work. If I include the definition of write_rawBuffer just above puts (I can't import GHC.Handle because of the dependency loop) and dangerously change CInt to Int in the signature (can't import Foreign.C.Types for the same reason) I still get an error message saying that "fromInteger" is out of scope. This is what I have added to libraries/base/GHC/ForeignPtr.hs: import GHC.List ( null ) import GHC.Base import GHC.IOBase import GHC.List ( length ) import GHC.Pack -- this is new import GHC.Ptr ( Ptr(..) ) import GHC.Err import GHC.Show foreign import ccall unsafe "__hscore_PrelHandle_write" write_rawBuffer :: Int -> RawBuffer -> Int -> Int -> IO Int puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (length s) return () I'm wondering if I should just give up on trying to print anything out from this deep in the libraries and go back to looking at the debugger trace. My guess is still that a FreeBSD libc function is getting called and somehow storing a 32 bit value in a 64 bit location, with junk in the high order word. As always, hints and firm whacks on the side of the head will be appreciated. Best Wishes, Greg
Hello Gregory, Monday, April 2, 2007, 7:57:49 PM, you wrote:
puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (fromIntegral (length s)) return ()
(packCString# come from GHC.Pack)
you may try to call C function with a result of (packCString# s) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
Hi Gregory, On Mon, Apr 02, 2007 at 11:57:49AM -0400, Gregory Wright wrote:
On Apr 1, 2007, at 6:22 PM, Ian Lynagh wrote:
Does the 6.6 one work with 6.4.2?:
puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (fromIntegral (length s)) return ()
(packCString# come from GHC.Pack)
Still doesn't work. If I include the definition of write_rawBuffer just above puts (I can't import GHC.Handle because of the dependency loop) and dangerously change CInt to Int in the signature (can't import Foreign.C.Types for the same reason)
Hmm, the foreign import types already look wrong, in both 6.4.2 and the HEAD. For now I recommend changing the definition in include/HsBase.h to only take and return HsInt, and to do the casting on the C side. include/HsBase.h: # ----------------------------- INLINE HsInt __hscore_PrelHandle_write( HsInt fd, HsAddr ptr, HsInt off, HsInt sz ) { return write(fd,(char *)ptr + off, (int)sz); } # ----------------------------- GHC/ForeignPtr.hs: # ----------------------------- import GHC.List import GHC.Pack import GHC.Num puts :: String -> IO () puts s = do write_rawBuffer 1 (unsafeCoerce# (packCString# s)) 0 (length s) return () # ----------------------------- You'll also need to fix the types of the imports in GHC.Handle (there are two of them), and their uses. I successfully built 6.4.2 with these changes. [some hours pass] Actually, HsBase.h contains many type mismatches (I've just pushed a patch to the HEAD), and I think there are more lurking in the base package. I'll probably resume my hunt tomorrow. It's probably not worth debugging further with 6.4 unless we first backport these fixes; it's not particularly unlikely that one of them is the root cause of the bug, after all. Thanks Ian
participants (3)
-
Bulat Ziganshin -
Gregory Wright -
Ian Lynagh