Code::Blocks 10.05 本身对 STL 的调试做出了一定的支持:支持 std::string 和 std::vector 两个容器,并且 std::vector<std::string> 不能正确显示。这样在调试使用 STL 的程序时显然是不给力的,于是果断 Google 之,最终找到一个名叫 GDB Python pretty printers 的东西可以解决这个问题。
首先得把这玩意儿的脚本下载到本地:
sudo svn checkout svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python /opt/gdb/stlPrettyPrinter
然后配置 Code::Blocks:
点击 Settings->Compiler and debugger,对话框打开后选择 Debugger settings,在 Debugger initialization commands 文本框中填入下面的代码后点击 OK。
Debugger initialization commands 代码:
#
# .gdbinit : GDB Config file
#
# 3/2010 - Ichthyo: add python pretty printers for STL
python
import sys
sys.path.insert(0, '/opt/gdb/stlPrettyPrinter')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
最后还得取消 Code::Blocks 10.05 本身对 STL 的支持:
将 脚本文件 /usr/share/codeblocks/scripts/gdb_types.script 中函数 RegisterTypes 的 STL String 和 STL Vector 两部分代码注释掉。若不取消其本身对 STL 的支持,则当容器元素类型为 std::string 时,还是不能正确显示。