
Is there a way to compile the RTS so that the names of data constructors are retained?
My memory from a long, long time ago is that we had a debugging mode which used libbfd to get symbol names and some GHC-demangling code to turn those back into names like the user typed in.
Yes, we still have that code, but it doesn't get much use - gdb can map addresses back to symbol names. I think I always intended to beef this up using a proper hash table for the address->symbol mapping, but never got around to it. Alternatively, if you compile for profiling, then info tables contain some extra information including the constructor name for contructors.
It looks like Printer.c has some hooks for printing data structures, is it feasible to make a primitive that allows Haskell code to call into this? I'm thinking in particular of calling something like printClosure() from Haskell code.
If it's a global symbol, you should be able to access it form the ffi.
If you want to traverse data structures the way you can using the HugsInternals library, you might want to tweak the code a little to provide a similar semantics/ API. Basically, all you have to do is take the C code and split it into handy bits.
This is a nice idea - we'll be happy to incorporate the changes. Cheers, Simon

If it's a global symbol, you should be able to access it form the ffi.
If you want to traverse data structures the way you can using the HugsInternals library, you might want to tweak the code a little to provide a similar semantics/ API. Basically, all you have to do is take the C code and split it into handy bits.
This is a nice idea - we'll be happy to incorporate the changes.
Hi, I'm on to it. Let's presume for the moment that I will solve a simpler problem, before I get the full task done. Say, for argument's sake, that I want to make the function printObj() available in Haskell, where: void printObj (StgClosure *obj); (as defined in and exported from rts/Printer.c) In Haskell I want to reflect this as: printObj :: a -> IO () Alistair mentioned that I could use the FFI to access some C code in the RTS. My intuition would have been to go about adding a primop as described in /ghc/compiler/prelude/primops.txt (ie without calling through the FFI). My trouble is I can't find any examples that are greatly similar to what I want to do. My question is: should I implement it through the FFI or as a primitive ala primops.txt? Perhaps they amount to much the same thing. Cheers, Bernie.

My question is: should I implement it through the FFI or as a primitive ala primops.txt? Perhaps they amount to much the same thing.
I'd make it a primop if there were some really unusual strictness issues involved or, if I wanted to eliminate all overhead, as in integer addition or if the operation did strange things to the state of the abstract machine (like pushing an exception-handler frame). I'd use the ffi for anything else. Here, there is a strange strictness issue (you don't want printObj to evaluat its argument) but SimonM's suggestion that you really want to use a stable pointer gets round this. What you'll need is a little wrapper function which will convert the stableptr into an StgClosure* void printObj_wrapper(StablePtr x) { printObj(derefStablePtr(x)); } (I'm sure the names of types and functions doesn't match those in header files - but hopefully the ones you want are easy to find.) -- Alastair Reid
participants (3)
-
Alastair David Reid
-
Bernard James POPE
-
Simon Marlow