Understanding the `ocamldebug` code base

I’m trying to understand the code base of ocamldebug which is bundled with the ocaml compiler.

The first step to understanding any code base is to get ocamllsp working on it!

Now it is possible to use ocamllsp with the ocaml compiler codebase by following ocaml/HACKING.adoc at trunk · ocaml/ocaml · GitHub . I was able to do:

dune build @libs in the the ocaml compiler code base successfully.

Now ocamllsp is working for the main parts of the compiler.

But, it seems ocamldebug codebase is an exception to this. It is not dune buildable so ocamllsp support is not there.

In fact if you look at the debugger/dune file it says:

; mshinwell: Disabled for now -- otherlibs/dynlink/dune needs fixing first.

Is there a way I can get ocamllsp to work for the ocamldebug code base?

1 Like

@mshinwell The comment above has you name on it – would appreciate if you could suggest any workaround…

Have you tried copying all the files in the debugger directory (+ genprintval.ml* from the toplevel directory) into a separate directory, and sticking a standard dune file in it ? The debugger is relatively independent, it depends on compiler-libs.common, unix and dynlink but you should be able to build it from the installed versions of the libraries. I assume that ocaml-lsp would work as expected in this situation.
Don’t forget to declare it as a bytecode-only project; ocamldebug isn’t supposed to be compiled to a native executable.

I had only printed a small excerpt of the dune file above to indicate it was all commented out. Here is the full dune file ( debugger/dune ):

;*                                                                        *
;*                                 OCaml                                  *
;*                                                                        *
;*                     Thomas Refis, Jane Street Europe                   *
;*                                                                        *
;*   Copyright 2018 Jane Street Group LLC                                 *
;*                                                                        *
;*   All rights reserved.  This file is distributed under the terms of    *
;*   the GNU Lesser General Public License version 2.1, with the          *
;*   special exception on linking described in the file LICENSE.          *
;*                                                                        *

; mshinwell: Disabled for now -- otherlibs/dynlink/dune needs fixing first.

;(ocamllex lexer)
;(ocamlyacc parser)
; (name main)
; (modes byte)
; (flags (:standard -w -9))
; (modules_without_implementation parser_aux)
; (libraries ocamlcommon ocamltoplevel runtime stdlib unix))
;(rule (copy main.exe ocamldebug.byte))

Simply removing ; does not work…

I wasn’t suggesting to reuse the dune file. You should write a new, standard dune file.
If you absolutely want to start from the existing file, I assume that you simply need to remove the rule stanza and replace the libraries with the installed versions (compiler-libs.common, unix, dynlink). But I’m far from an expert on dune.

Thanks for your help so far. Yes you were not suggesting removal of the comments. You were suggesting a different strategy – though I think that might be even more complicated than just messing around with the current dune file in-situ.

I was able to make more progress by changing the lex and parser related dune lines:

+(ocamllex debugger_lexer)
+(ocamlyacc debugger_parser)
-(ocamllex lexer)
-(ocamlyacc parser)

These filenames have been renamed (the dune file has bit rotted a bit here) so this rule change makes sense here.

Now I get a single error which I don’t know how to solve…

File "dune", line 178, characters 7-11:
178 |  (name main)
Error: No rule found for runtime/dllruntime_stubs.so
1 Like

I’m not sure if it will work, but try using the contents of the dune file from here.

@mshinwell Thanks! I used the file you linked to…

Sadly, this does not work. Unfortunately I’m not a dune expert…

$ dune exec ./debugger/main.bc
        make runtime/libcamlrun.a (exit 2)
(cd _build/default/runtime && /usr/bin/make libcamlrun.a COMPUTE_DEPS=false)
make: *** No rule to make target 'sak.c', needed by 'sak.o'.  Stop.
File "debugger/dune", line 19, characters 8-12:
19 |   (name main)
Error: No rule found for stdlib/camlheader
File "debugger/dune", line 25, characters 51-67:
25 |   (libraries ocamlcommon ocamltoplevel stdlib unix dynlink_internal))
Error: Library "dynlink_internal" not found.
Hint: try:
  dune external-lib-deps --missing ./debugger/main.bc