OCaml language support for gdb

Mark Shinwell mshinwell@janestreet.com
Mon Oct 10 14:30:00 GMT 2016


Hello everyone,

I would like to contribute support for debugging OCaml code to the gdb
project.  OCaml is a hybrid functional/imperative language, suitable
for developing complex and reliable systems, that is rapidly gaining
traction in a variety of applications from academia to industry.
Native platform debugging support for such languages has traditionally
been poor.

I would welcome feedback from this list at a high level before moving
forward to propose patches.

The infrastructure I have been developing for OCaml debugging falls
into three parts:
1. Modifications to the OCaml compiler [1] to reduce loss of
information during optimisation and to emit DWARF-4 sections.
2. A debugger support library called libmonda [2].
3. Modifications to gdb [3] which mostly consist of a new language
implementation, ocaml-lang.c, currently only about 500 lines.

It is expected that the compiler modifications will be available in a
released version of OCaml around Spring 2017.

The ocaml-lang.c file in gdb defers basically all functionality to
libmonda, which is a shared library dynamically loaded into gdb as
required.  The library is written almost entirely in OCaml with a
small portion in C.  It is statically linked against both the OCaml
runtime code and the OCaml compiler library.  The majority of the
library is parameterised over the particular debugger being
used---currently there is only a gdb implementation, but others are
likely to follow (in particular for lldb; and also perhaps a
"debugger" which is actually implemented by a program introspecting
itself, for testing purposes).  In the case of libmonda for gdb, the
library calls back into gdb itself to perform tasks such as reading
target memory, etc.

libmonda takes care of the difficult problems of printing OCaml values
and types at runtime.  To do this it needs not only the DWARF
information fed through from the debugger, but also sidecar files
written by the compiler during the compilation process.  (We aim in
due course to provide submissions to the DWARF standards committee
with a view to improving DWARF support for this sort of language.)

I would hope that the maintenance burden of adding this additional
language to gdb is likely to be low.  I can certainly commit to
maintaining it for the foreseeable future.  It is the case at present
that various user interface-related operations do not function as well
as might be liked, and this might cause some small refactorings to
existing gdb code to be proposed.

It is also the case that there are likely to be rather a lot of rough
edges in the early versions of this, although these would only affect
the debugging of OCaml code.  I think that is to be expected, and have
confidence that users will be able to accept these when balanced
against the very significant step forward of being able to debug such
code in a reasonable manner.

The combination of licences involved in a gdb executable using this
new functionality, that is to say: gdb (GPLv3), libmonda (MIT) and the
OCaml core system (LGPLv2.1 + linking exception) deserves some
attention.  To the best of my knowledge the combination of GPLv3, MIT
and LGPLv2.1 "used as a library" is compatible (cf.
https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility).  However
the OCaml core system has an exception [4] which makes its license
slightly more permissive than the LGPLv2.1.  I presume that the FSF
would have to attest that this would be compatible with the GPLv3.
(If one of the gdb maintainers has a contact with whom I could enquire
about this, I would be grateful.)

I would be pleased if a maintainer could provide information on the
current requirements/forms regarding copyright assignment.  My
CodeSourcery one will be out of date now.  Much of this work has been
conducted on work time at my current employer, Jane Street, who would
need to be involved in such assignment.

I suspect there will be a lot of questions, so I'll leave it at that for now.

Mark Shinwell

[1] https://github.com/ocaml/ocaml/pull/574
[2] http://mshinwell.github.io/libmonda/
[3] https://github.com/mshinwell/gdb/tree/gdb-7.11
[4] https://github.com/ocaml/ocaml/blob/trunk/LICENSE



More information about the Gdb mailing list