Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] A few questions regarding the compiler
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] A few questions regarding the compiler
14 Nov 2001 14:20:37 +0100, David Mentre <> pisze:

> Maybe I have missed something but the point of raising an exception and
> getting its location has already been discussed on the list:
> (look also at the thread)
> To generate a backtrace, just do an "assert(false)" with the environment
> variable OCAMLRUNPARAM set to "b=1" (without quotes, see man ocamlrun).

I know, but the backtrace is just dumped to stderr just before the
program dies. I would like the program itself to have access to its
own backtrace, so it can do something with it instead of displaying
it in the default format and dying.

I can wrap each top-level value binding which can fail in a 'try
... with exn -> my_handler exn' (i.e. I let my compiler generate such
code), where my_handler does some magic to access the backtrace and
translates it to something readable. I'll now try to do it myself
basing on backtrace.c, but I don't understand yet how it works.

A more convenient way would be to call some magic hook which will
install my_handler for unhandled exceptions instead of the builtin
fatal_uncaught_exception, so I would save those 'try ...' for each
binding. Looking at the code I guess that it's now impossible, calling
fatal_uncaught_exception is just hardwired in appropriate places.

> Yes. Somebody has written a tool to convert a trace in source position:

This is an external tool which reads original sources and the
backtrace. I want to customize the backtrace itself. Especially as
OCaml sources is only an intermediate step between my language and
executable - they should not be required to be available for producing
a proper backtrace. I will set up my own translation of OCaml positions
to original source positions and embed it in the program.

 __("<  Marcin Kowalczyk *

Bug reports:  FAQ:
To unsubscribe, mail  Archives: