How to print armadillo matrix in gdb in complex cpp project?

402 Views Asked by At

I found a way to print armadillo matrix in gdb on this site . However, what happens if

#include <iostream>
#include <armadillo>


template<class Matrix>
void print_matrix(Matrix matrix) {
matrix.print(std::cout);
}

//provide explicit instantiations of the template function for 
//every matrix type you use somewhere in your program.
template void print_matrix<arma::mat>(arma::mat matrix);
template void print_matrix<arma::cx_mat>(arma::cx_mat matrix); 

is inside debug_armadillo.h file. How call function should be performed? I tried to type:

call 'debug_armadillo.h'::print_matrix<arma::Mat<float>>(C)

but the error I get is:

No symbol "print_matrix" in specified context. 
1

There are 1 best solutions below

6
On BEST ANSWER

How call function should be performed?

This call should work. Use Tab completion to autocomplete exact C++ type as suggested in https://stackoverflow.com/a/22766955/72178.

(gdb) call print_matrix<arma::Mat<float> >(C) 

No symbol "print_matrix" in specified context

Make sure that print_matrix function was actually generated in resulting binary. Try to grep demangled symbols, probably exact type differs a bit in template arguments from what you are trying to call:

nm -C your_binary | grep print_matrix