Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005487OCamlOCaml generalpublic2012-01-20 11:232013-08-31 12:49
Reportertgazagna 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.12.1 
Target VersionFixed in Version3.13.0+dev 
Summary0005487: Improved GDB support
DescriptionI have been working recently on improving the support of GDB for native code, mainly on x86 linux architectures. This work integrates patches from ygrek (0005314), Till Varoqueaux (0004888) and myself. Currently, it target ocaml-3.12.1 only and it supports:

* more precise (and exact) stacktraces in gdb
* it's possible to create breakpoints on (almost) any line of a source file

So now it's possible to inspect crash dumps (and so should fix [2]), to debug multi-threaded native application in production (to find deadlocks) or to debug step-by-step a native application with C bindings. The patches also improve the accuracy of profiling tools.

Reading and writing OCaml values is not supported; however, it is possible to read OCaml values (when you know its address) using the mlvalues.py script from ygrek [1].

[1] http://ygrek.org.ua/p/code/mlvalues.py.html [^]
[2] http://blog.incubaid.com/tag/gdb/ [^]
Additional InformationThe patch is well tested on amd64 linux. OSX does not support CFI directives (and hence will generate incorrect stacktraces).

I can port the patch to SVN trunk if it has any chance to be integrated. Some initial port to trunk (but not totally complete) has been done at https://github.com/OCamlPro/ocaml-testing [^]
TagsNo tags attached.
Attached Filespatch file icon 0010-Emit-debug-information-for-each-instruction-on-amd64.patch [^] (700 bytes) 2012-01-20 11:23 [Show Content]
patch file icon 0001-Fix-dsplit-ocamlopt-option.patch [^] (924 bytes) 2012-01-20 11:25 [Show Content]
patch file icon 0002-lambda-display-location-when-g-and-dlambda.patch [^] (1,187 bytes) 2012-01-20 11:25 [Show Content]
patch file icon 0003-asmcomp-Clean-ups-in-debuginfo-API.patch [^] (9,175 bytes) 2012-01-20 11:25 [Show Content]
patch file icon 0004-clambda-simplfiy-Uclosure-node.patch [^] (8,805 bytes) 2012-01-20 11:25 [Show Content]
patch file icon 0005-clambda-add-dclambda-option.patch [^] (13,314 bytes) 2012-01-20 11:26 [Show Content]
patch file icon 0006-backtraces-add-CFI-directives-to-improve-backtraces.patch [^] (20,067 bytes) 2012-01-20 11:26 [Show Content]
patch file icon 0007-Add-location-to-function-definition-in-the-assembly-.patch [^] (13,215 bytes) 2012-01-20 11:26 [Show Content]
patch file icon 0008-clambda-use-a-record-to-hold-location.patch [^] (45,942 bytes) 2012-01-20 11:26 [Show Content]
patch file icon 0009-C-propagate-location-through-C.patch [^] (126,408 bytes) 2012-01-20 11:26 [Show Content]
gz file icon gdb-support.tar.gz [^] (16,663 bytes) 2012-02-20 17:56

- Relationships
has duplicate 0005505closedprotz Debugging information in native code 
related to 0004888closed Improve again x86/ELF for GNU debugging tools 
related to 0005603resolved ocamlopt generates wrong assembly file number with multiple files. 

-  Notes
(0006748)
shinwell (developer)
2012-01-20 11:41

I'm a strong supporter of having improved GDB support.

I think it's worth spending some time looking at how this works (or could be made to work) on various architectures. For example, does it work on ARM? I have a feeling that for Mac OS X you may be able to use CFI directives by assembling using clang, which I think will end up using the LLVM assembler, rather than gas.
(0006922)
xleroy (administrator)
2012-02-14 20:29

Just to record what was discussed today with Thomas and others:
- I'm very much in favor of adding .cfi directives to get meaningful stack backtraces under gdb and other tools. x86/ELF is the primary target, but suggestions on how to get it to work on other platforms (as suggested by Mark Shinwell) are welcome, of course.
- I'm OK with adding file name and line number info to OCaml functions: it's cheap and seems to be useful in conjunction with some profiling tools.
- I have reservations about adding file & line info to every node of Clambda / Cmm / Mach intermediate code, because it really messes up pattern-matchings in Cmmgen and other parts of the compiler. Before we do this, maybe we should discuss alternate, lighter ways of recording and propagating this kind of annotations.
(0006948)
tgazagna (reporter)
2012-02-20 18:00

I've uploaded an archive which contains the 8 first patches rebased on trunk.

I've also added a one-line patch to add location information on function calls and exception raising (so it is less precise that the 9th and 10th patches, but way shorter :-)

And also, I've ported the file/loc patch on i386 as well. I don't have an i386 machine to test it, but the patch looks simple (2 lines in amscomp/i386/emit.mlp).
(0006953)
xleroy (administrator)
2012-02-21 18:48

"Rebased" patch committed in SVN trunk (rev 12179). Thanks!

Re: testing on i386, it can be done rather easily on a Linux/x86-64 installation by forcing compilation in 32-bit mode:
    ./configure -cc "gcc -m32" -as "as --32" -aspp "gcc -m32 -c"
All you need is to install a few "i386" system libraries, e.g. libc6-dev-i386 for Ubuntu.

- Issue History
Date Modified Username Field Change
2012-01-20 11:23 tgazagna New Issue
2012-01-20 11:23 tgazagna File Added: 0010-Emit-debug-information-for-each-instruction-on-amd64.patch
2012-01-20 11:25 tgazagna File Added: 0001-Fix-dsplit-ocamlopt-option.patch
2012-01-20 11:25 tgazagna File Added: 0002-lambda-display-location-when-g-and-dlambda.patch
2012-01-20 11:25 tgazagna File Added: 0003-asmcomp-Clean-ups-in-debuginfo-API.patch
2012-01-20 11:25 tgazagna File Added: 0004-clambda-simplfiy-Uclosure-node.patch
2012-01-20 11:26 tgazagna File Added: 0005-clambda-add-dclambda-option.patch
2012-01-20 11:26 tgazagna File Added: 0006-backtraces-add-CFI-directives-to-improve-backtraces.patch
2012-01-20 11:26 tgazagna File Added: 0007-Add-location-to-function-definition-in-the-assembly-.patch
2012-01-20 11:26 tgazagna File Added: 0008-clambda-use-a-record-to-hold-location.patch
2012-01-20 11:26 tgazagna File Added: 0009-C-propagate-location-through-C.patch
2012-01-20 11:41 shinwell Note Added: 0006748
2012-02-14 17:26 protz Relationship added has duplicate 0005505
2012-02-14 20:29 xleroy Note Added: 0006922
2012-02-14 20:29 xleroy Status new => acknowledged
2012-02-20 17:56 tgazagna File Added: gdb-support.tar.gz
2012-02-20 18:00 tgazagna Note Added: 0006948
2012-02-21 18:48 xleroy Note Added: 0006953
2012-02-21 18:48 xleroy Status acknowledged => resolved
2012-02-21 18:48 xleroy Resolution open => fixed
2012-02-21 18:48 xleroy Fixed in Version => 3.13.0+dev
2012-03-14 17:55 xleroy Relationship added related to 0004888
2012-05-02 14:38 doligez Relationship added related to 0005603
2013-08-31 12:49 xleroy Status resolved => closed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker