Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved GDB support #5487

Closed
vicuna opened this issue Jan 20, 2012 · 4 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Jan 20, 2012

Original bug ID: 5487
Reporter: tgazagna
Status: closed (set by @xavierleroy on 2013-08-31T10:49:08Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.12.1
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Has duplicate: #5505
Related to: #4888 #5603
Monitored by: tgazagna mehdi @ygrek @mshinwell jm @hcarty

Bug description

I have been working recently on improving the support of GDB for native code, mainly on x86 linux architectures. This work integrates patches from ygrek (#5314), Till Varoqueaux (#4888) 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 information

The 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

File attachments

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 20, 2012

Comment author: @mshinwell

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.

@vicuna

This comment has been minimized.

Copy link
Author

commented Feb 14, 2012

Comment author: @xavierleroy

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.
@vicuna

This comment has been minimized.

Copy link
Author

commented Feb 20, 2012

Comment author: tgazagna

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).

@vicuna

This comment has been minimized.

Copy link
Author

commented Feb 21, 2012

Comment author: @xavierleroy

"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.