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] how to add a primitive to Pervasives?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: jehenrik <jehenrik@y...>
Subject: [Caml-list] how to add a primitive to Pervasives?
Hi, I tried to hack with the sources to be able to turn on stack 
backtracing in the toplevel.  I realize I'm breaking the "no consumer 
serviceable parts inside, breaking this seal will void warranty" 
sticker, but I'd be happy if someone could explain to me why my approach 
is not working.

Rather than being completely sure if it would work, I decided to try to 
just write this function and add it to Pervasives:

CAMLprim value start_backtrace_c()
   return Val_unit;

Judging by the function sys_exit, there are four other places that the 
function apparently must be added to show up:

% grep -c -r sys_exit * |grep -v :0
byterun/main.c:1				// no this one is special for sys_exit
byterun/win32.c:1				// this too

So I add them all, in the obvious ways:

% grep -c -r start_backtrace * |grep -v :0

During make, this causes various files like prim.c to be contain copies, 
and everything seems to work until linking ocamlc fails:

boot/ocamlrun boot/ocamlc -I boot  -o ocamlc utils/misc.cmo 
utils/tbl.cmo utils/config.cmo utils/clflags.cmo utils/terminfo.cmo 
utils/ccomp.cmo utils/warnings.cmo parsing/linenum.cmo 
parsing/location.cmo parsing/longident.cmo parsing/syntaxerr.cmo 
parsing/parser.cmo parsing/lexer.cmo parsing/parse.cmo 
parsing/printast.cmo typing/ident.cmo typing/path.cmo 
typing/primitive.cmo typing/types.cmo typing/btype.cmo typing/subst.cmo 
typing/predef.cmo typing/datarepr.cmo typing/env.cmo 
typing/typedtree.cmo typing/ctype.cmo typing/printtyp.cmo 
typing/includeclass.cmo typing/mtype.cmo typing/includecore.cmo 
typing/includemod.cmo typing/parmatch.cmo typing/typetexp.cmo 
typing/typecore.cmo typing/typedecl.cmo typing/typeclass.cmo 
typing/typemod.cmo bytecomp/lambda.cmo bytecomp/printlambda.cmo 
bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo 
bytecomp/translobj.cmo bytecomp/translcore.cmo bytecomp/translclass.cmo 
bytecomp/translmod.cmo bytecomp/simplif.cmo bytecomp/runtimedef.cmo 
bytecomp/meta.cmo bytecomp/instruct.cmo bytecomp/bytegen.cmo 
bytecomp/printinstr.cmo bytecomp/opcodes.cmo bytecomp/emitcode.cmo 
bytecomp/bytesections.cmo bytecomp/dll.cmo bytecomp/symtable.cmo 
bytecomp/bytelibrarian.cmo bytecomp/bytelink.cmo driver/errors.cmo 
driver/compile.cmo driver/main_args.cmo driver/main.cmo
Error while linking boot/stdlib.cma(Pervasives):
The external function `start_backtrace_c' is not available

I also tried something similar putting a directive and an external in 
toplevel/, this time modeling after the external symbol 
get_current_environment.  But I have the same problem, I don't 
understand how to cross over from the c symbol world to a caml 

boot/ocamlrun boot/ocamlc -I boot  -linkall -o ocaml.tmp 
toplevel/toplevellib.cma toplevel/topmain.cmo
Error while linking toplevel/toplevellib.cma(Topdirs):
The external function `init_backtrace' is not available
make: *** [ocaml] Error 2

Thanks again for tolerating my mucking around.

Jeff Henrikson

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