From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5F240BBBB for ; Sun, 12 Mar 2006 11:20:02 +0100 (CET) Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com [66.111.4.28]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k2CAK12c020344 for ; Sun, 12 Mar 2006 11:20:01 +0100 Received: from frontend1.internal (mysql-sessions.internal [10.202.2.149]) by frontend1.messagingengine.com (Postfix) with ESMTP id 7A1BED3BE56; Sun, 12 Mar 2006 05:19:56 -0500 (EST) Received: from frontend2.messagingengine.com ([10.202.2.151]) by frontend1.internal (MEProxy); Sun, 12 Mar 2006 05:19:56 -0500 X-Sasl-enc: cxyvCymUMz46Bc1Og4LvSTPdbNDZ+OWGPyuB3g1hnUGl 1142158793 Received: from [172.16.13.137] (burnham.ljcrf.edu [192.231.106.2]) by frontend2.messagingengine.com (Postfix) with ESMTP id 9862158BF62; Sun, 12 Mar 2006 05:19:52 -0500 (EST) Date: Sun, 12 Mar 2006 02:17:37 -0800 (PST) From: Martin Jambon X-X-Sender: martin@droopy To: Andries Hekstra Cc: Richard Jones , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Line number for index out of bounds In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 4413F5D1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; arrays:01 ocaml:01 syntax:01 syntax:01 arrays:01 bigarrays:01 ocaml:01 bytecode:01 stack:01 stack:01 eindhoven:01 workarounds:01 bytecode:01 assertion:01 ocamlopt:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 On Mon, 6 Mar 2006, Andries Hekstra wrote: > Dear Richard, > > Thanks for your email. I indeed use native code as I need the speed. My > program is 3500 lines, and includes multi-dimensional arrays, to putting > try's everywhere by hand is out of the question. I would then have to > write a metaprogram that adds such try commands to an existing OCaml > program and outputs a longer program with the try's with the asserts. If > possible I would like to postpone that and try your other option. I finally finished to implement a syntax extension that I once started to write, and gave up because of the difficulty. The result is a horribly long syntax extension, but it should work well with strings, arrays and bigarrays for both read and write accesses. The syntax uses "#" instead of ".", but you can change this, if you don't want to change your program. There is also an option which allows you to restore the native mode. It's all there: http://martin.jambon.free.fr/ocaml.html#bounds I tried it on a real program of my own which uses lots of arrays: my program runs 2-3 times slower than before, but this is due to a short piece of code. If I use regular array accesses in this portion of code, it works just as fast as before. Well, that was not an easy syntax extension, but I'm satisfied with the result. I hope you'll like it! Martin > Due to this crashing business I go on a business trip to Asia without any > ready simulation results for one week. > >> * Use bytecode, and before running the program set the environment >> variable OCAMLRUNPARAM=b which will print a stack trace. > > If I would use this week of the trip to try this suggestion you made, how > will the stack trace give me the line number? > > Best regards, > > Andries > > ------------------------------------------------------------------------ > Dr. Ir. Andries P. Hekstra > Philips Research > High Tech Campus 27 (WL-1-4.15) > 5656 AG Eindhoven > Tel./Fax/Secr. +31 40 27 42048/42566/44051 > * Good open source break software for computer users : > http://www.workrave.org > > > > > > > > > Richard Jones > 06-03-2006 12:14 > > To > Andries Hekstra/EHV/RESEARCH/PHILIPS@PHILIPS > cc > caml-list@yquem.inria.fr > Subject > Re: [Caml-list] Line number for index out of bounds > Classification > > > > > > > > On Mon, Mar 06, 2006 at 11:44:31AM +0100, Andries Hekstra wrote: >> Invalid_argument("index out of bounds") > [...] >> Of course, I am very curious in which line number of the program this >> exception occurs. >> Is there any way to get hold of this line number? > > This is a real problem with OCaml - it's impossible to get stack > traces of where an exception happens with native code. I'm assuming > you're using native code. I commonly have cases where a program dies > with "exception: Not_found" because I forgot to enclose some List.find > with an appropriate try ... with clause, or made some wrong > assumption. Tracking these down is time-consuming. > > Possible workarounds: > > * Use bytecode, and before running the program set the environment > variable OCAMLRUNPARAM=b which will print a stack trace. > > * Surround every possible array index with a try ... with expression > like this: > > try > (* code which accesses the array *) > with > Invalid_argument "index out of bounds" -> assert false > > The "assert false" will print the line and character number of the > assertion. > > * Hack ocamlopt to be able to print exceptions properly :-) > > Rich. > > -- > Richard Jones, CTO Merjis Ltd. > Merjis - web marketing and technology - http://merjis.com > Team Notepad - intranets and extranets for business - > http://team-notepad.com > > -- Martin Jambon, PhD http://martin.jambon.free.fr Edit http://wikiomics.org, bioinformatics wiki