Hi I was playing with bindings to Windows Debug API and made a small tracer for executables built with ghc. That fun turned into adventure into deciphering STG-structures. Unfortunately I just don't seem to be able decipher everything myself, and so I have few questions.
In case someone's interested, code is available [1]. It's very much work in progress and a toy, but I think the reading STG/RTS structures is pretty abstracted from specifics of mingw32 port of GHC. It's incomplete, but it does show sensible traces for single-threaded (haskell thread) apps. It probably only works against ghc 6.4.2. This is what I did up to now: * Use nm to get symbols, I deduct which are haskell symbols (pretty succesfully) and zdecode them. I know by name which symbols are (_static)_info, _srt and _closure. * I set breakpoints on _info-symbols as specified by regexp on commandline. * When debugged program is stopped on breakpoint I show a trace of Sp-stack by traversing from Sp. I deduct symbols, and if frames point "inside" symbol's region. Small values I interpret as special ints. After printing trace, the debugged program is allowed to continue. * I am stuck at decoding StgInfoTable and the "subtypes". I am stuck despite reading (but apparently I didn't understand) how GC walks the stack and other bits in ghc source, and reading relevant sounding docs pointed by wiki [2]. * Is it even possible to walk the stack in this manner? Kind of critical question :-) (I realise I can't deduct all functions correctly at the moment) * How do I know if pointer to InfoTable in stack is FunInfoTable? Or RetInfoTable? Thunks I suppose are identified by closure type's flags. (I identify _THU-flagged as ThunkInfoTable and FUN_-closures as FunInfoTable currently.) run-time-system.ps mentions, very useful sounding function/macro called isFUN, and friends, but I couldn't find them in ghc sources. * I can't see correlation between Sp-stack entries and arities/function types (as told by StgFunInfoTable.f.fun_type) and other entries in the stack. Should I? Please help, I could use pointers (even if they are: read docs again) or direct answers (if there's easy ones.) [1] darcs get http://tamelambda.net/darcs/tracer/ [2] http://cvs.haskell.org/trac/ghc/wiki/GhcPapers Best regards, Esa Here's a sample session (unfortunately, it currently prints lots of long lines) D:\source\haskell\tracer>tracer putStrLn loopy.exe Breakpoints matched by "putStrLn" : System.IO_putStrLn Tracing: System.IO_putStrLn SeInfo (Info False,"System.IO_putStrLn",4201884) 0 (Just (ItFun 4201884 (InfoTableHeader 7 CtFUN_STATIC [Ctf_HNF,Ctf_NS,Ctf_STA,Ctf_SRT] 0) 2 (SfaArg [True]))) SeUnresolvedHeap 12324964 SeInfo (Info False,"GHC.IOBase_bindIO",4205932) 46 (Just (ItFun 4205932 (InfoTableHeader 0 CtFUN_STATIC [Ctf_HNF,Ctf_NS,Ctf_STA,Ctf_SRT] 0) 3 (SfaArg [True,True]))) SeUnresolvedHeap 12324956 SeInfo (Info False,"GHC.TopHandler_runMainIO",4202476) 126 (Just (ItFun 4202476 (InfoTableHeader 7 CtFUN_STATIC [Ctf_H NF,Ctf_NS,Ctf_STA,Ctf_SRT] 0) 2 (SfaArg [True]))) SeInfo (Info False,"stg_catch_frame",4284236) 0 (Just (ItUnresolved 4284236 (InfoTableHeader 0 CtCATCH_FRAME [Ctf_BTM] 34))) SeOther 0 SeInfo (Closure,"GHC.TopHandler_topHandler",4387480) 0 Nothing SeInfo (Info False,"stg_noforceIO",4314344) 0 (Just (ItUnresolved 4314344 (InfoTableHeader 0 CtRET_SMALL [Ctf_BTM,Ctf_ SRT] 0))) SeInfo (Info False,"stg_stop_thread",4314204) 0 (Just (ItUnresolved 4314204 (InfoTableHeader 0 CtSTOP_FRAME [Ctf_BTM] 0))) Tracing: System.IO_putStrLn SeInfo (Info False,"System.IO_putStrLn",4201884) 0 (Just (ItFun 4201884 (InfoTableHeader 7 CtFUN_STATIC [Ctf_HNF,Ctf_NS,Ctf_STA,Ctf_SRT] 0) 2 (SfaArg [True]))) SeUnresolvedHeap 12326836 SeInfo (Info False,"GHC.TopHandler_runMainIO",4202476) 126 (Just (ItFun 4202476 (InfoTableHeader 7 CtFUN_STATIC [Ctf_HNF,Ctf_NS,Ctf_STA,Ctf_SRT] 0) 2 (SfaArg [True]))) SeInfo (Info False,"stg_catch_frame",4284236) 0 (Just (ItUnresolved 4284236 (InfoTableHeader 0 CtCATCH_FRAME [Ctf_BTM] 34))) SeOther 0 SeInfo (Closure,"GHC.TopHandler_topHandler",4387480) 0 Nothing SeInfo (Info False,"stg_noforceIO",4314344) 0 (Just (ItUnresolved 4314344 (InfoTableHeader 0 CtRET_SMALL [Ctf_BTM,Ctf_ SRT] 0))) SeInfo (Info False,"stg_stop_thread",4314204) 0 (Just (ItUnresolved 4314204 (InfoTableHeader 0 CtSTOP_FRAME [Ctf_BTM] 0))) Process ended. _______________________________________________ Cvs-ghc mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/cvs-ghc
