Cantera/Debugging Cantera: Difference between revisions
From charlesreid1
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
=Creating a Cantera Debug Build= | =Creating a Cantera Debug Build= | ||
==Cantera 1.x== | |||
If you're using Cantera 1.8.0, you can edit the [[Cantera Preconfig]] file and change these lines: | If you're using Cantera 1.8.0, you can edit the [[Cantera Preconfig]] file and change these lines: | ||
| Line 18: | Line 20: | ||
and then run <code>./preconfig && make && make install</code> to make a debug build of Cantera. | and then run <code>./preconfig && make && make install</code> to make a debug build of Cantera. | ||
==Cantera 2.x== | |||
You can create a debug build with scons by adding the <code>debug=yes</code> option to your scons build script. Here's mine, for Mac OS X 10.9 (Maverick?): | |||
<source lang="bash"> | |||
#!/bin/sh | |||
scons build \ | |||
f90_interface=n \ | |||
F90='gfortran ' \ | |||
F90FLAGS='-arch x86_64' \ | |||
cc_flags='-arch x86_64' \ | |||
cxx_flags='-arch x86_64' \ | |||
prefix=$HOME/codes/cantalysis/build \ | |||
python_package=full \ | |||
with_html_log_files=yes \ | |||
use_sundials=y \ | |||
sundials_include=$HOME/pkg/sundials/std/include \ | |||
sundials_libdir=$HOME/pkg/sundials/std/lib \ | |||
optimize=no \ | |||
debug=yes \ | |||
&& \ | |||
scons install | |||
</source> | |||
=Running Cantera through GDB= | =Running Cantera through GDB= | ||
Latest revision as of 22:14, 27 March 2014
Creating a Cantera Debug Build
Cantera 1.x
If you're using Cantera 1.8.0, you can edit the Cantera Preconfig file and change these lines:
CANTERA_CONFIG_PREFIX=${CANTERA_CONFIG_PREFIX:="/path/to/cantera/build"}
...
DEBUG_MODE=${DEBUG_MODE:='n'}
to this:
CANTERA_CONFIG_PREFIX=${CANTERA_CONFIG_PREFIX:="/path/to/cantera/dbg_build"}
...
DEBUG_MODE=${DEBUG_MODE:='y'}
and then run ./preconfig && make && make install to make a debug build of Cantera.
Cantera 2.x
You can create a debug build with scons by adding the debug=yes option to your scons build script. Here's mine, for Mac OS X 10.9 (Maverick?):
#!/bin/sh
scons build \
f90_interface=n \
F90='gfortran ' \
F90FLAGS='-arch x86_64' \
cc_flags='-arch x86_64' \
cxx_flags='-arch x86_64' \
prefix=$HOME/codes/cantalysis/build \
python_package=full \
with_html_log_files=yes \
use_sundials=y \
sundials_include=$HOME/pkg/sundials/std/include \
sundials_libdir=$HOME/pkg/sundials/std/lib \
optimize=no \
debug=yes \
&& \
scons install
Running Cantera through GDB
Once you've built a version of Cantera that includes debug symbols, you'll be able to run it through GDB and step through code, set breakpoints, and get stack traces at arbitrary points in the code. This is very useful for (a) learning how Cantera works, and (b) identifying where an exception or error is being thrown, in order to determine the cause.
Create Your Driver
Before you run anything, you'll need a driver - the main program that is using the Cantera library.
...
Compile Your Driver
...
Firing Up GDB
First things first, fire up GDB. What you'll be doing is running your executable (your driver) through gdb. You'll set some breakpoints, and jump into the Cantera code using some breakpoints.