﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Clear-随笔分类-C++</title><link>http://www.cppblog.com/newclear/category/11910.html</link><description>记忆中的闪光，总会蒙尘。</description><language>zh-cn</language><lastBuildDate>Sun, 28 Oct 2012 21:36:02 GMT</lastBuildDate><pubDate>Sun, 28 Oct 2012 21:36:02 GMT</pubDate><ttl>60</ttl><item><title>GDB在Mac下的调试信息</title><link>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Sun, 28 Oct 2012 15:47:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/193994.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/193994.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/193994.html</trackback:ping><description><![CDATA[上次说了GDB的pretty printer，这次来说说调试程序的问题。<br /><br />在Linux或者Windows下面，写好代码，g++编译，连接，调试，一切很顺畅。<br /><br />但是在Mac下面，有点小问题。<br /><br />我们如果是直接编译生成可执行文件：<br />g++ test.cpp -g -o test<br />ok，我们用GDB调试，没有问题。<br />但是如果我们分两步，编译和连接分开的话：<br />g++ test.cpp -g -c -o test.o<br />g++ -o test test.o<br />这次我们gdb test再调试，会发现GDB找不到调试符号信息！<br /><br />两次生成有什么不同呢？<br />一次编译生成的test，旁边有一个test.dSYM，而单独连接的test，没有这个。<br /><br />test.dSYM就是调试符号信息。<br />要想生成这个东西，也简单，运行dsymutil就可以了：<br />dsymutil test<br />再然后，就可以用GDB顺利调试了。<br /><br />g++直接生成可执行文件的时候，会帮我们调用一次dsymutil，但是单独连接的时候却不会做这个，这就是造成差别的原因。<img src ="http://www.cppblog.com/newclear/aggbug/193994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-10-28 23:47 <a href="http://www.cppblog.com/newclear/archive/2012/10/28/193994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mac 下使用GDB的pretty printer</title><link>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Mon, 24 Sep 2012 15:15:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/191889.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/191889.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/191889.html</trackback:ping><description><![CDATA[<p>GDB 从7.x版本开始就支持pretty printer</p>
<p>可是一直以来都没有见到这个东西起作用，最近就研究了一下。</p>
<p>我的环境是Mac Mountain Lion + macports，GCC 4.7，GDB 7.5</p>
<p>首先，按照</p>
<p><a href="http://sourceware.org/gdb/wiki/STLSupport">http://sourceware.org/gdb/wiki/STLSupport</a><br /></p>
<p>下载checkout STL的pretty printer。</p>
<p>设置好.gdbinit以后，运行告知已经注册，不能重复注册。</p>
<p>$locate printers.py</p>
<p>发现在/opt/local/share/gcc-4.7/gcc-4.7.1/python/libstdcxx/v6已经有一份现成的了。</p>
<p>好吧，我们就使用现有的好了。</p>
<p>写个程序，调试，print，怎么回事？还是不成？</p>
<p>头晕了好久，好在python的源码是可以随便看随便改的，于是在printers.py里面改来改去，调试了半天，发现：</p>
<p>这个printers.py注册了好多stl类型的printer，打印出来有以下这些：</p>
<p>std::__cxx1998::__7::unordered_multiset<br /></p>
<p>std::tr1::unordered_multiset</p>
<p>std::unordered_set</p>
<p>std::tr1::unordered_multimap</p>
<p>std::tr1::__7::weak_ptr</p>
<p>std::__7::bitset</p>
<p>std::__cxx1998::multiset</p>
<p>std::bitset</p>
<p>std::forward_list</p>
<p>std::__7::forward_list</p>
<p>std::__cxx1998::forward_list</p>
<p>std::__7::_Rb_tree_iterator</p>
<p>std::__7::list</p>
<p>std::__debug::unordered_multimap</p>
<p>__gnu_cxx::slist</p>
<p>std::__7::priority_queue</p>
<p>std::__debug::map</p>
<p>std::_List_const_iterator</p>
<p>std::__debug::unordered_map</p>
<p>__gnu_cxx::_Slist_iterator</p>
<p>std::set</p>
<p>std::__cxx1998::__7::_Deque_const_iterator</p>
<p>std::__7::_List_const_iterator</p>
<p>std::__7::multiset</p>
<p>std::shared_ptr</p>
<p>std::__7::queue</p>
<p>std::__cxx1998::_List_iterator</p>
<p>std::tr1::unordered_map</p>
<p>std::__7::vector</p>
<p>std::__debug::queue</p>
<p>std::__norm::_Deque_const_iterator</p>
<p>std::__7::unordered_set</p>
<p>std::__norm::_Deque_iterator</p>
<p>std::__cxx1998::_Deque_iterator</p>
<p>__gnu_cxx::__7::_Slist_iterator</p>
<p>std::__cxx1998::list</p>
<p>std::__cxx1998::__7::list</p>
<p>std::unordered_multimap</p>
<p>std::__cxx1998::unordered_multiset</p>
<p>std::__cxx1998::__7::_List_iterator</p>
<p>std::__7::map</p>
<p>std::__debug::vector</p>
<p>std::tr1::__7::unordered_set</p>
<p>std::__7::basic_string</p>
<p>std::weak_ptr</p>
<p>std::__7::set</p>
<p>std::__7::unordered_multiset</p>
<p>__gnu_cxx::__7::__normal_iterator</p>
<p>std::__cxx1998::__7::vector</p>
<p>std::unordered_map</p>
<p>std::list</p>
<p>std::tr1::__7::unordered_map</p>
<p>std::__7::unordered_multimap</p>
<p>std::vector</p>
<p>std::tr1::unordered_set</p>
<p>std::_List_iterator</p>
<p>std::__7::_Deque_iterator</p>
<p>std::__cxx1998::map</p>
<p>std::__cxx1998::bitset</p>
<p>std::__7::weak_ptr</p>
<p>std::__cxx1998::vector</p>
<p>std::__cxx1998::unordered_set</p>
<p>std::priority_queue</p>
<p>__gnu_cxx::__7::slist</p>
<p>std::__7::_Rb_tree_const_iterator</p>
<p>std::_Deque_const_iterator</p>
<p>std::__7::deque</p>
<p>std::__cxx1998::set</p>
<p>std::__cxx1998::__7::bitset</p>
<p>__gnu_debug::_Safe_iterator</p>
<p>std::tr1::__7::unordered_multimap</p>
<p>__gnu_cxx::__normal_iterator</p>
<p>std::__cxx1998::__7::multiset</p>
<p>std::__cxx1998::__7::unordered_map</p>
<p>std::__debug::unique_ptr</p>
<p>std::__cxx1998::_List_const_iterator</p>
<p>std::_Deque_iterator</p>
<p>std::tr1::__7::unordered_multiset</p>
<p>std::unordered_multiset</p>
<p>std::__cxx1998::__7::unordered_multimap</p>
<p>std::__debug::multiset</p>
<p>std::tr1::weak_ptr</p>
<p>std::__cxx1998::_Deque_const_iterator</p>
<p>std::__cxx1998::unordered_map</p>
<p>std::__7::unique_ptr</p>
<p>std::__debug::list</p>
<p>std::__debug::unordered_multiset</p>
<p>std::__cxx1998::deque</p>
<p>std::_Rb_tree_const_iterator</p>
<p>std::__debug::bitset</p>
<p>std::queue</p>
<p>std::tr1::__7::shared_ptr</p>
<p>std::__debug::unordered_set</p>
<p>std::tr1::shared_ptr</p>
<p>std::__cxx1998::__7::_List_const_iterator</p>
<p>std::__cxx1998::__7::_Deque_iterator</p>
<p>std::__cxx1998::__7::map</p>
<p>std::__7::stack</p>
<p>std::unique_ptr</p>
<p>std::__cxx1998::__7::deque</p>
<p>std::map</p>
<p>std::__7::multimap</p>
<p>std::stack</p>
<p>std::__debug::stack</p>
<p>std::_Rb_tree_iterator</p>
<p>std::multimap</p>
<p>std::__norm::_List_const_iterator</p>
<p>std::__debug::multimap</p>
<p>std::__norm::_List_iterator</p>
<p>std::deque</p>
<p>std::tuple</p>
<p>std::__cxx1998::unordered_multimap</p>
<p>std::basic_string</p>
<p>std::__7::tuple</p>
<p>std::__debug::deque</p>
<p>std::__debug::priority_queue</p>
<p>std::__7::_Deque_const_iterator</p>
<p>std::__7::shared_ptr</p>
<p>std::__cxx1998::__7::multimap</p>
<p>std::__debug::forward_list</p>
<p>std::__7::unordered_map</p>
<p>std::__debug::set</p>
<p>std::__cxx1998::__7::unordered_set</p>
<p>std::__cxx1998::__7::set</p>
<p>std::__7::_List_iterator</p>
<p>std::__cxx1998::multimap</p>
<p>std::__cxx1998::__7::forward_list</p>
<p>std::multiset:</p>
<p>然后，我们的一个简单的string类型，传入到python的lookup里面查找，找不到？</p>
<p>最后发现，string类型传入python以后的basename是basic_string，没有前面的namespace！</p>
<p>于是，在Printer类的add_version函数里面，增加一行</p>
<p>self.add(name, function)<br /></p>
<p>保存，重新打开GDB，调试程序，OK了：</p>
<p>(gdb) p s</p>
<p>$1 = "great"</p>
<p>(gdb) p v</p>
<p>$2 = vector of length 5, capacity 8 = {"a1", "a2", "a2", "a3", "a4"}</p>

<div class="posttagsblock"><a href="http://technorati.com/tag/Mac" rel="tag">Mac</a>, <a href="http://technorati.com/tag/GDB" rel="tag">GDB</a></div><img src ="http://www.cppblog.com/newclear/aggbug/191889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-09-24 23:15 <a href="http://www.cppblog.com/newclear/archive/2012/09/24/191889.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>