I\'m using gdb to debug my c++ program. I\'m using the armadillo numerical library to define my matrices. I have an armadillo matrix defined like so:
mat A =
For those using QtCreator, you can inspect the values from your IDE by extending GDB with Python Debugging Helpers (maybe other IDEs support this feature too).
Place the following script in, for example, ~/debugHelpers.py
#!/usr/bin/python
import gdb # gdb.Value()
import dumper # dumper.Children()
def qdump__arma__Mat(d, value):
array = value["mem"]
cols = value["n_cols"]
rows = value["n_rows"]
maxDisplayItems = 50
innerType = d.templateArgument(value.type, 0)
p = gdb.Value(array.cast(innerType.pointer()))
d.putItemCount(cols)
d.putNumChild(cols)
if d.isExpanded():
numDisplayItems = min(maxDisplayItems, cols)
with dumper.Children(d, numChild=cols,
maxNumChild=numDisplayItems,
childType="",
addrBase=p,
addrStep=p.dereference().__sizeof__):
for i in range(0, int(numDisplayItems)):
with dumper.Children(d):
d.putItemCount(rows)
d.putNumChild(rows)
if d.isExpanded():
numDisplayItems = min(maxDisplayItems, rows)
with dumper.Children(d, numChild=rows,
maxNumChild=numDisplayItems,
childType=innerType,
addrBase=p,
addrStep=p.dereference().__sizeof__):
for j in range(0, int(numDisplayItems)):
d.putSubItem(j, p.dereference())
p += 1
And call it adding this line to your ~/.gdbinit:
python exec(open('//debugHelpers.py').read())
or add it from your IDE; in QtCreator use Tools > Options > Debugger > GDB (tab) > Extra Debugging Helpers (near the bottom).
This particular script will return the matrix arranged by columns (natural memory arrangement in my architecture):

Sources: Writing Debug Visualizers for GDB / QtCreator 2.8