- ubuntu 14.04 LTS
- g++ 4.8.4
- gdb 7.7
- python 3.4
- Boost C++ Libraries 1.59.0
BoostライブラリのGDB PrettyPrinter が以下のレポジトリで公開されている。
ただし現在(2015/12/02)は一年近くメンテナンスされていない。
https://github.com/ruediger/Boost-Pretty-Printer
前述の環境では動かなかったため、フォークされたレポジトリを使用する。
https://github.com/mateidavid/Boost-Pretty-Printer/tree/merge-attempt
説明に沿って設定すれば基本的に問題なかった。
適用なディレクトリでレポジトリをクローンする。
$ git clone git@github.com:mateidavid/Boost-Pretty-Printer.git
~/.gdbinit
ファイルに以下の内容を追加するか、新規作成する。
PATH-TO-THE-REPO/Boost-Pretty-Printer
の部分は先ほどcloneしたディレクトリのパスを指定する。
python
import sys
sys.path.insert(0, 'PATH-TO-THE-REPO/Boost-Pretty-Printer')
import boost.latest ### see note on Entry Points below
boost.register_printers()
end
以下のcppファイルでブレークしp h
を実行した場合にboost::optionalの出力がわかりやすくなっている。
#include <string>
#include <boost/optional.hpp>
struct hoge {
std::string text;
int num;
};
int main() {
boost::optional<hoge> h = hoge();
h->text = "abcdefg";
h->num = 100;
return 0;
}
(gdb) p h
$1 = boost::optional<hoge> is initialized = {value = {text = {
static npos = <optimized out>,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
_M_p = 0x7ffff7dd93d8 <std::string::_Rep::_S_empty_rep_storage+24> ""}}, num = 0}}
作成日: 2015/12/02