-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document all sorts of C debugging tips
backport of cbb4bc3 Conflicts: doc/index.rst
- Loading branch information
Showing
6 changed files
with
209 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:orphan: | ||
|
||
.. _devdocs-index: | ||
|
||
##################################### | ||
Developing/debugging Julia's C code | ||
##################################### | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
backtraces | ||
debuggingtips |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
******************************************* | ||
Reporting and analyzing crashes (segfaults) | ||
******************************************* | ||
|
||
So you managed to break Julia. Congratulations! Collected here are some general procedures you can undergo for common symptoms encountered when something goes awry. Including the information from these debugging steps can greatly help the maintainers when tracking down a segfault or trying to figure out why your script is running slower than expected. | ||
|
||
If you've been directed to this page, find the symptom that best matches what you're experiencing and follow the instructions to generate the debugging information requested. Table of symptoms: | ||
|
||
* `Segfaults during bootstrap (sysimg.jl)`_ | ||
|
||
* `Segfaults when running a script`_ | ||
|
||
* `Errors during julia startup`_ | ||
|
||
.. _version info: | ||
|
||
Version/Environment info | ||
------------------------ | ||
|
||
No matter the error, we will always need to know what version of julia you are running. When julia first starts up, a header is printed out with a version number and date. If your version is ``0.2.0`` or higher, please include the output of ``versioninfo()`` in any report you create:: | ||
|
||
julia> versioninfo() | ||
Julia Version 0.3.3-pre+25 | ||
Commit 417b50a* (2014-11-03 11:32 UTC) | ||
Platform Info: | ||
System: Linux (x86_64-linux-gnu) | ||
CPU: Intel(R) Core(TM) i7 CPU L 640 @ 2.13GHz | ||
WORD_SIZE: 64 | ||
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem) | ||
LAPACK: libopenblas | ||
LIBM: libopenlibm | ||
LLVM: libLLVM-3.3 | ||
|
||
|
||
.. _Segfaults during bootstrap (sysimg.jl): | ||
|
||
Segfaults during bootstrap (sysimg.jl) | ||
-------------------------------------- | ||
|
||
Segfaults toward the end of the ``make`` process of building julia are a common symptom of something going wrong while julia is preparsing the corpus of code in the ``base/`` folder. Many factors can contribute toward this process dying unexpectedly, however it is as often as not due to an error in the C-code portion of julia, and as such must typically be debugged with a debug build inside of ``gdb``. Explicitly: | ||
|
||
Create a debug build of julia:: | ||
|
||
$ cd <julia_root> | ||
$ make debug | ||
|
||
Note that this process will likely fail with the same error as a normal ``make`` incantation, however this will create a debug executable that will offer ``gdb`` the debugging symbols needed to get accurate backtraces. Next, manually run the bootstrap process inside of ``gdb``:: | ||
|
||
$ cd base/ | ||
$ gdb -x ../contrib/debug_bootstrap.gdb | ||
|
||
This will start ``gdb``, attempt to run the bootstrap process using the debug build of julia, and print out a backtrace if (when) it segfaults. You may need to hit ``<enter>`` a few times to get the full backtrace. Create a gist_ with the backtrace, the `version info`_, and any other pertinent information you can think of and open a new issue_ on Github with a link to the gist. | ||
|
||
|
||
.. _Segfaults when running a script: | ||
|
||
Segfaults when running a script | ||
------------------------------- | ||
|
||
The procedure is very similar to `Segfaults during bootstrap (sysimg.jl)`_. Create a debug build of Julia, and run your script inside of a debugged julia process:: | ||
|
||
$ cd <julia_root> | ||
$ make debug | ||
$ gdb --args usr/bin/julia-debug-readline <path_to_your_script> | ||
|
||
Note that ``gdb`` will sit there, waiting for instructions. Type ``r`` to run the process, and ``bt`` to generate a backtrace once it segfaults:: | ||
|
||
(gdb) r | ||
Starting program: /home/sabae/src/julia/usr/bin/julia-debug-readline ./test.jl | ||
... | ||
(gdb) bt | ||
|
||
Create a gist_ with the backtrace, the `version info`_, and any other pertinent information you can think of and open a new issue_ on Github with a link to the gist. | ||
|
||
|
||
.. _Errors during julia startup: | ||
|
||
Errors during julia startup | ||
--------------------------- | ||
|
||
Occasionally errors occur during julia's startup process (especially when using binary distributions, as opposed to compiling from source) such as the following:: | ||
|
||
$ julia | ||
exec: error -5 | ||
|
||
These errors typically indicate something is not getting loaded properly very early on in the bootup phase, and our best bet in determining what's going wrong is to use external tools to audit the disk activity of the ``julia`` process: | ||
|
||
* On Linux, use ``strace``:: | ||
|
||
$ strace julia | ||
|
||
* On OSX, use ``dtruss``:: | ||
|
||
$ dtruss -f julia | ||
|
||
Create a gist_ with the ``strace``/ ``dtruss`` ouput, the `version info`_, and any other pertinent information and open a new issue_ on Github with a link to the gist. | ||
|
||
|
||
Glossary | ||
-------- | ||
|
||
A few terms have been used as shorthand in this guide: | ||
|
||
* ``<julia_root>`` refers to the root directory of the julia source tree; e.g. it should contain folders such as ``base``, ``deps``, ``src``, ``test``, etc..... | ||
|
||
.. _gist: http://gist.github.com | ||
.. _issue: https://github.com/JuliaLang/julia/issues?state=open |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
****************** | ||
gdb debugging tips | ||
****************** | ||
|
||
Displaying Julia variables | ||
-------------------------- | ||
|
||
Within ``gdb``, any ``jl_value_t*`` object ``obj`` can be displayed using | ||
:: | ||
|
||
(gdb) call jl_(obj) | ||
|
||
The object will be displayed in the julia session, not in the gdb session. | ||
This is a useful way to discover the types and values of objects being | ||
manipulated by Julia's C code. | ||
|
||
Similarly, if you're debugging some of julia's internals (e.g., | ||
``inference.jl``), you can print ``obj`` using | ||
:: | ||
|
||
ccall(:jl_, Void, (Any,), obj) | ||
|
||
This is a good way to circumvent problems that arise from the order in which julia's output streams are initialized. | ||
|
||
Inserting breakpoints for inspection from gdb | ||
--------------------------------------------- | ||
|
||
In your ``gdb`` session, set a breakpoint in ``jl_breakpoint`` like so:: | ||
|
||
(gdb) break jl_breakpoint | ||
|
||
Then within your Julia code, insert a call to ``jl_breakpoint`` by adding:: | ||
|
||
ccall(:jl_breakpoint, Void, ()) | ||
|
||
If you back up to the ``jl_apply`` frame, then you can display the arguments to the function using, e.g., | ||
:: | ||
|
||
(gdb) call jl_(args[0]) | ||
|
||
|
||
Inserting breakpoints upon certain conditions | ||
--------------------------------------------- | ||
|
||
Loading a particular file | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Let's say the file is ``sysimg.jl``:: | ||
|
||
(gdb) break jl_load if strcmp(fname, "sysimg.jl")==0 | ||
|
||
Calling a particular method | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:: | ||
|
||
(gdb) break jl_apply_generic if strcmp(F->name->name, "method_to_break")==0 | ||
|
||
Since this function is used for every call, you will make everything 1000x slower if you do this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:orphan: | ||
|
||
.. _devdocs-index: | ||
|
||
#################################### | ||
Documentation of Julia's Internals | ||
#################################### | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
cartesian | ||
meta | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tkelman
Contributor
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You're probably right about meta. If this line causes
make html
to fail, this line should be deleted from 0.3.