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] debugger?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-06-20 (03:12)
From: John Skaller <skaller@o...>
Subject: [Caml-list] debugger?
I have just converted my build system to optionally make
bytecode. When I run the program on one of the larger tests,
I get a stack overflow. The program runs correctly if
I set the stack to 800000 words but not 600000,
it works fine under the optimising compiler.
The test takes a few seconds for the optimising compiler,
and 10 times longer for the bytcode version.
[The other tests seem to run equally fast]

Looks like non-tail recursion in the lexer,
which is the only place there is a 'recursive'
enough data structure to cause a problem:
a list of tokens of the input file.

So I ran the test under the debugger, typed
backtrace when it crashed .. and got no

The time was 12Meg at the crash, so I goto'd
10Meg. Only 6 frames on the stack. No tail
recursion problem. No doubt we're in the
lexer though.

There IS one nasty point in the lexer.
The lexer returns a token list in
reverse order, however, each lexeme
returns a list of tokens in forward order,
so the new list is:

	rev h @ t

The lexer is recursive with respect to #include files.
[I'm replacing the above with rev_append ..]
So there are a few rather large 'rev's happening.
In the test case though, its the same include file
as the other tests ..

let pre_tokens_of_lexbuf buf state =
     let rec get lst =
       let ts = pre_flx_lex buf state in
       match ts with
       | [Flx_parse.ENDMARKER] -> lst
       | _ -> get (List.rev_append ts lst)
     in List.rev (get [])

(ocd) run
Loading program... done.
Stack overflow
Time : 12161027
Program exit.
(ocd) bt
(ocd) bt 20
(ocd) The program is running. Quit anyway ? (y or n) y
[skaller@pelican] ~/links/flx>ocamldebug -I src bin/flxg -Ilib test/rt01
	Objective Caml Debugger version 3.06+34 (2003-05-21)

(ocd) go 10000000
Loading program... done.
Time : 10000000 - pc : 290304 - module Flx_lex
48       Lexing.lexeme_end lexbuf<|a|> - buf_pos
(ocd) bt
#0  Pc : 290304  Flx_lex char 1167
#1  Pc : 278484  Flx_lex char 156528
#2  Pc : 295344  Flx_pretok char 5616
#3  Pc : 295588  Flx_pretok char 5758
#4  Pc : 295288  Flx_pretok char 6000
#5  Pc : 307460  Flx_parse_ctrl char 277
#6  Pc : 569696  Flxg char 2419
John Max Skaller,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: