print
, p
: print the value of a variablelist
, l
: list the code lines around the current lineup
: move a frame up the stack tracedown
: move a frame down the stack tracebacktrace
, bt
, where
: list all the frames in the stack (e.g. from main all the way down through all the subroutine calls). In pdb
you get an arrow pointing to the current framenext
, n
: move to the next line of code, stepping over any subroutine callsstep
, s
: similar to next, but will step into subroutine calls (even ones you might not expect like vector::operator[]
, e.g. vector element access)continue
, c
: continue program execution until hitting the next breakpoint or until program execution finishes (whichever comes first)break
, b
: tell the debugger to halt execution at a given point. Can be at the beginning of a method call, e.g. break GroupDiffusion::computeQpResidual
, or a particular line of code, e.g. break Kernel.C:50
. For pdb
, if specifying breakpoints by file or function, they must be in sys.path
disable <breakpoint #>
: disable the supplied breakpointenable <breakpoint #>
: enable the supplied breakpointrun
, r
: run the program from the beginningfinish
: continue execution until the current frame or subroutine returns to the calling frame and print the returned valuereturn
: prematurely return from the current frame to the calling frame. Can optionally supply a value that you want the prematurely exiting frame to returninfo <subcommand>
: get info about a particular subcommand. Most common:info break
: get information about breakpoints
delete <breakpoint #>
, d <breapoint #>
: delete the supplied breakpoint
return
: like the gdb finish
command; continue execution until the current method returnsclear
: like gdb delete
ignore <breakpoint #> <count>
: ignore the specified breakpoint <count>
number of timesCompile with debug symbols:
g++ -g -o null_ptr null_ptr.cpp
Execute
./null_ptr
Segmentation fault (core dumped)
Let's pretend we don't know what the error is. One thing you can do is actually load in the core file:
gdb <path to executable> <path to core file>
If you're running recent versions of Ubuntu, you're probably not going to see a core file in the same place that you executed your program. The reason is outlined here. But you can fix that by executing
ulimit -c unlimited
Sorry, I don't know about OS X or other flavors of Linux. If you open the core file, you're directed to the error right away, including subroutine and line number:
Core was generated by `./null_ptr'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000400566 in foo () at null_ptr.cpp:4
4 *x = 3;
You can reproduce the segmentation fault again within gdb simply by executing run
. This will again terminate on the null pointer dereference.
gdb --args <program to run>
Some systems by default don't break on failed assertions (mine doesn't), meaning when the program fails, you can't inspect variables, etc. Solution is either
break abort
or
break exit
After failing assertion, examine backtrace with bt
and then move up the stack trace with up
into user land code. Note that after typing a command once, subsequent RET
without any input will execute that previous command. After a single p xsec_names[j]
, I know exactly what the problem is.
Fun tip: You can print the contents of a vector with the command:
print *(myVector._M_impl._M_start)@myVector.size()
This stems from the more generic command to print N elements of an array starting at pointer P:
print *(P)@N
where here the starting address of our vector is given by myVector._M_impl._M_start
break CoupledFissionEigenKernel::computeQpResidual
break CoupledFissionEigenKernel::computeQpResidual if _qp == 1 && _group == 1
p _qp
p _group
l
n
n
p _chi[_qp][_group]
p computeConcentration((*_group_fluxes[i]), _qp)
Can try stepping many times to get into computeConcentration
, but we'll discover all the std::vector::operator[]
calls. Would be easier to just set a new breakpoint and then continue
.
In [2]:
cd ~/projects/moose/modules/navier_stokes/tests/ins/lid_driven/gold
In [3]:
import yt
ds = yt.load("lid_driven_out.e", step=-1)
slc = yt.SlicePlot(ds, 'z', ('all', 'vel_y'))
In [4]:
%debug