From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: jdh30@jdh30.plus.com
Cc: "Andries Hekstra" <andries.hekstra@philips.com>,
"Richard Jones" <rich@annexia.org>,
caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Line number for index out of bounds
Date: Tue, 7 Mar 2006 10:39:52 +0100 [thread overview]
Message-ID: <cd67f63a0603070139v32f9861dh70728320ffd8b678@mail.gmail.com> (raw)
In-Reply-To: <200603061311.k26DBfgX015835@concorde.inria.fr>
On 3/6/06, Jonathan Harrop <jdh30@jdh30.plus.com> wrote:
> On Mon Mar 6 11:14 , Richard Jones <rich@annexia.org> sent:
> >* Surround every possible array index with a try ... with expression
>
> Perhaps you could write a camlp4 macro to wrap uses of a.(i) in a try ... with block that logs the
> line number?
>
Hi,
I have a little camlp4 extension that wraps every function definition
with a try...with block that logs the exception with the location and
re-raise it afterwards.
The code is quite short but it needs the camlp4 version that I am developing:
============================================================
value rec map_pwel =
let add_debug_expr e =
let _loc = Loc.make_absolute (MLast.loc_of_expr e) in
let msg = "Exception tracer at " ^ Loc.to_string _loc ^ " (%s)@." in
<:expr<
try $e$
with exc ->
do {
Format.eprintf $str:msg$ (Printexc.to_string exc);
raise exc
} >> in
let map_pwe (patt, owhen, expr) = (patt, owhen, add_debug_expr expr)
in List.map map_pwe
and map_expr =
fun
[ <:expr< fun [ $list:pwel$ ] >> as e ->
let _loc = MLast.loc_of_expr e in
<:expr< fun [ $list:map_pwel pwel$ ] >>
| x -> x ];
Pcaml.register_str_item_filter (MLast.Map.Expr.str_item map_expr);
=============================================================
You can use it like that:
$ cat test.ml
let a = Array.make 10 0
let f () = a.(11)
let g = f
let h = g
let main = h ()
$ ocamlc -pp 'camlp4o fi_exc_tracer.cmo' test.ml -o test
$ ./test
Exception tracer at File "/tmp/test.ml", line 2, characters 11-17
(Invalid_argument("index out of bounds"))
Fatal error: exception Invalid_argument("index out of bounds")
A tarball of this camlp4 version is available at
http://gallium.inria.fr/~pouillar/ocaml-3.10+dev2-and-camlp4-beta-r22414.tar.bz2,
but it's beta code so use it at your own risks and without any kind of
warranty.
Cheers,
--
Nicolas Pouillard
next prev parent reply other threads:[~2006-03-07 9:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-06 13:11 Jonathan Harrop
2006-03-07 9:39 ` Nicolas Pouillard [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-03-06 10:44 Andries Hekstra
2006-03-06 11:14 ` [Caml-list] " Richard Jones
2006-03-06 14:39 ` Markus Mottl
2006-03-06 19:08 ` Andries Hekstra
2006-03-06 19:53 ` Richard Jones
2006-03-12 10:17 ` Martin Jambon
2006-03-12 11:02 ` Richard Jones
2006-03-07 15:55 ` Alan Falloon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd67f63a0603070139v32f9861dh70728320ffd8b678@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=andries.hekstra@philips.com \
--cc=caml-list@yquem.inria.fr \
--cc=jdh30@jdh30.plus.com \
--cc=rich@annexia.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox