Re: whither stack traces?
Dave Herman <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
> Many of us on the list would _really_ like to see a working example of
> this !
I'm not positive this is quite right, but it worked enough for me to get
something:
open TextIO List
fun printStackTrace e =
let val ss = SMLofNJ.exnHistory e
val s = General.exnMessage e
val name = General.exnName e
val details = if s = name then "" else (" [" ^ s ^ "]")
in
print ("uncaught exception " ^ name ^ details ^ "\n");
case ss of
[] => ()
| (s::ss') => (
print (" raised at: " ^ s ^ "\n");
app (fn s' => print (" " ^
s' ^ "\n")) ss'
)
end
fun main(arg:string, args:string list) =
main'(arg, args) handle e => (printStackTrace e; 1)
I believe the only part of the continuation that exnHistory records is
the exception handlers that the `raise' passed through, so it's much
less detailed than a conventional backtrace. I'm not sure if this is the
same thing the REPL gives you.
For more detailed backtraces, I use the BackTrace module:
fun main(arg:string, args:string list) =
BackTrace.monitor(fn () => main'(arg, args))
I add $smlnj-tdp/plugins.cm to my CM file and build with:
ml-build -Ctdp.instrument=true \$smlnj-tdp/back-trace.cm foo.cm
Main.main foo.heap
Note that if you want to put the above in a Makefile, you have to use
make's convention for quoting dollar signs and double the dollar sign:
ml-build -Ctdp.instrument=true \$$smlnj-tdp/back-trace.cm foo.cm
Main.main foo.heap
Dave
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV