I try to see how far I get with running an opam installed coqtop.byte under ocamldebug. Basically this works using ocamldebug-coq.run with a custom wrapper script to set the environment appropriate for opam. But I have issues loading the printers. I am doung "source db" and get :
(ocd) source db
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/ocaml/threads/threads.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/ocaml/str.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/zarith/zarith.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/coq/config/config.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/coq/clib/clib.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/ocaml/dynlink.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/coq/lib/lib.cma loaded
File /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/coq/gramlib/.pack/gramlib.cma loaded
Error during code loading: error while linking /Users/msoegtrop/.opam/_coq-platform_.2021.02.0/lib/coq/kernel/kernel.cma.
The external function `coq_uint63_to_float_byte' is not available
A few other printers have:
Reference to undefined global `Libnames'
Reference to undefined global `Names'
Am I doing something wrong?
You need to load the coqrun library before kernel
Sorry, the documentation in debugging.md is a bit to terse for my OCaml skill level.
I am doing the following:
I wrote a script:
#!/bin/sh
export OCAMLDEBUG="$(which ocamldebug)"
export COQTOP="$(coqc -where)"
export CAML_LD_LIBRARY_PATH=$CAML_LD_LIBRARY_PATH:$(coqc -where)/kernel/byterun
source ./ocamldebug-coq.run "$(which coqtop.byte)"
to get around the fact that I don't have the generated ocamldebug-coq
script in opam. Furthermore I have an .ocamlinit
file with
#use "topfind";;
Then I start Coq with these ocamldebug commands:
set arguments <my Q and R arguments>
set bigstep 10000000
set smallstep 1000000
run
This starts Coq. Then I drop to ocamltop with Drop.
. How would I load the coqrun library? I guess it is the one in /lib/coq/kernel/byterun/libcoqrun.a
? And I guess I should load it from my .ocamlinit
file? But I can't figure out the correct library name or my path is wrong - neither with topfind syntax nor with plain OCaml syntax. The topfind list command shows me many coq related libraries, e.g.
coq.lib (version: 8.13)
but nothing which looks like coqrun.
P.S.: I am on macOS
@Emilio Jesús Gallego Arias : can it be that the coq opam package simply does not install the coqrun library? I only have a file lib/coq/kernel/byterun/libcoqrun.a
and I guess this is nothing ocaml or ocamldebug could load.
You will never have more than that. libcoqrun.a
is a pure C library. There is no OCaml involved. What one is supposed to do is to pass option -dllib -lcoqrun
to force linking a C library (possibly with -dllpath
if the library is hidden somewhere). But I have no idea if those options are supported by ocaml
and ocamldebug
.
Well at least on Windows without opam there was also a dllcoqrun.dll
. On Mac with opam, the .a
file is the only file with coqrun
in the name. I will just build Coq and see if I can find it.
On Linux, similarly to Windows, you have libcoqrun.so
. So, perhaps, there is something botched for Mac's installation.
When I build Coq using the same method as opam does, I get a file named "dllcoqrun.so". I guess it should be named "libcoqrun.so" and that might be the reason why it doesn't get installed on Mac. I will see which name works and then file a bug.
No, sorry, dllcoqrun.so
is just fine. That is a historical artifact of the way OCaml shared libraries were built, but that is nonetheless the name expected by OCaml. (That said, that might still be the reason why it does not get installed.)
If I understand correctly, dllcoqrun.so
is not installed if the -custom
flag was used, which is the default on Windows and Darwin, unless -no-custom
was passed to configure
.
(Which makes sense I guess, since -custom
means that coqrun
was already statically linked to Coq binaries.)
Hmm, somehow I can't get this to work. I tried this in a fresg Coq 8.13.1 git folder:
git clean -d -f -X
./configure -local
make -j 16
make -j 16 byte
cd dev
./ocamldebug-coq coqtop.byte
then at the ocd prompt:
source db
which results in:
Error during code loading: error while linking /Users/msoegtrop/CoqGit/coq-ref/kernel/kernel.cma.
The external function `coq_uint63_to_float_byte' is not available
Hmm, but I think ocamldebug also needs this shared library in order to be able to load the printers.
But in my local installation the file is there ...
Does that change something if you pass the flags -custom
or -no-custom
to configure
?
Actually even without -no-custom coqtop.byte is not statically linked. It does not run if dllcoqrun is not in the path. Mysterious. This seems to be different from what opam does although I use the same options besides path spec options.
I am a bit lost here. The main information I am missing is how to tell ocamldebug to load a shared library needed by a printer. As far as I can tell this is not automatic and also kernel.cma doesn't seem to contain a reference to coqrun, but it does contain a reference to coq_uint63_to_float_byte which is defined in dllcoqrun.so.
If you run ocamlobjinfo kernel.cma
, it is supposed to tell you something like Extra dynamically-loaded libraries: -lcoqrun
. That is how OCaml knows the dependencies.
Basically, kernel.cma
is built with the command line ocamlc -dllib -lcoqrun -a -o kernel.cma
, which causes OCaml to indicate inside kernel.cma
that dllcoqrun.so
/ libcoqrun.a
is needed for execution / compilation.
Guillaume Melquiond said:
If you run
ocamlobjinfo kernel.cma
, it is supposed to tell you something likeExtra dynamically-loaded libraries: -lcoqrun
. That is how OCaml knows the dependencies.
I get this:
Extra dynamically-loaded libraries:
So I guess the Mac build is some strange hybrid between statically and dynamically linked. As I said, coqtop.byte
definitely does not run if it cannot find dllcoqrun.so
.
I will experiment with -custom and -no-custom.
@Guillaume Melquiond : with ./configure -local -no-custom
things do work. I get:
coq-ref$ ocamlobjinfo kernel/kernel.cma | head -n 10
:
Extra dynamically-loaded libraries: -lcoqrun
and the source db
in ocamldebug does work. Thanks for the support!
So should the macOS build be changed to use -no-custom?
No idea. I suppose there was some good reason to force -custom
on macOS.
Possibly with an emphasis on was
...
Does this only impacts byte code builds?
Yes, in -custom
mode, C libraries such as libcoqrun.a
are statically linked inside the binaries. So, it might have been used on Windows and Mac because the system was not able to find the libraries otherwise, so better stick them inside the executable files.
But since bytecode files are mostly used for debugging it doesn't make that much sense if the debugger doesn't work then.
Anyhow the -custom build seems to be a strange hybrid because the dllcoqrun.so is there and needed (also by coqtop.byte), but not referenced e.g. by kernel.cma.
I will also do a build with explicit -custom. Maybe this is yet something else ...
That is strange, in -custom
mode, libcoqrun.a
should directly be linked into coqtop.byte
and dllcoqrun.so
would thus not be needed.
I just tested it on Linux, ./configure -custom
properly causes libcoqrun.a
to be embedded.
@Guillaume Melquiond : sorry, my bad. I did a git clean -d -f -X
instead of a git clean -d -f -x
so something remained from the previous build.
In a proper clean -custom
build, coqtop.byte
does not depend on dllcoqrun.so
.
But there is still the problem that dllcoqrun.so
is actually there, kernel.cma
needs it to get coq_uint63_to_float_byte
but does not load it. So is this a link error in kernel.cma
- should it statically link libcoqrun.a
?
Btw.: does loading the debug printers in a -custom build work on linux?
The thing is, kernel.cma
should not need it, as libcoqrun.a
was embedded into coqtop.byte
:
$ objdump -x bin/coqtop.byte | grep coq_uint63_to_float_byte
0000000000035a70 g F .text 0000000000000016 coq_uint63_to_float_byte
But indeed, it does not work on Linux either:
(ocd) source db
...
File gramlib.cma loaded
Error during code loading: error while linking kernel.cma.
The external function `coq_uint63_to_float_byte' is not available
Hmm... According to the documentation of Ocamldebug, load_printer kernel.cma
does not give access to the modules of the debugged program. That is why it does not find the content of libcoqrun.a
.
Yes, ocamldebug needs its own copy of all functions used by the printers. With the -no-custom build this does work since kernel.cma references the shared library then.
Do you think this did ever work with -custom
or is this a new issue introduced by new dependencies in kernel.cma (the name of the missing function looks new ...).
Actually I don't know how the make-based build works, for the dune one, we generate an empty cma which triggers the loading of the so file with its linking flags, so I dunno, after the pr switching the ocaml build for dune this should work.
@Emilio Jesús Gallego Arias : ok, then I will wait with further investigations. For the time being I can live with a -no-custom
build.
Last updated: Sep 15 2024 at 13:02 UTC