如何在复杂的 cpp 项目中打印 gdb 中的犰狳矩阵?

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

我在 this site 上找到了一种在 gdb 中打印犰狳矩阵的方法。但是,如果

会发生什么
#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); 

在 debug_armadillo.h 文件中。 call函数应该如何执行?我试着输入:

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

但我得到的错误是:

No symbol "print_matrix" in specified context. 

How call function should be performed?

这个调用应该有效。按照 .

中的建议,使用 Tab 补全自动补全准确的 C++ 类型
(gdb) call print_matrix<arma::Mat<float> >(C) 

No symbol "print_matrix" in specified context

确保 print_matrix 函数实际上是在生成的二进制文件中生成的。尝试 grep demangled 符号,模板参数中的确切类型可能与您尝试调用的内容略有不同:

nm -C your_binary | grep print_matrix