This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR python/10646. Add libstdc++ Python pretty-printers for -D_GLIBCXX_DEBUG cases.


http://sourceware.org/bugzilla/show_bug.cgi?id=10646

This patch adds Python pretty-printer support for the debug variants of various STL classes when the inferior is compiled with -D_GLIBCXX_DEBUG. There are four attachments. The first is the patch, the second is the test .cpp program; the third and fourth are the pretty-printer output files from the "normal" compilation, and the -D_GLIBCXX_DEBUG enabled compilation from within GDB. The two output forms, and the test program are submitted as supporting documentation and are not part of the overall patch.

I compiled the binaries as follows:

g++ -g3 -O0 -std=c++0x -D_GLIBCXX_DEBUG printer-test.cpp -o printer-test-dbg

and

g++ -g3 -O0 -std=c++0x printer-test.cpp -o printer-test

I then run each binary through a Python enabled GDB as follows:

/home/build/obj/gdb/gdb --quiet -ex "set verbose off" -ex "set pagination off" -ex "set confirm no" -ex "source printers.py" -ex "python gdb.pretty_printers = [lookup_function]" -ex "break 198" -ex "run" -ex "info locals" -ex "quit" --args printer-test-dbg > debug.out

/home/build/obj/gdb/gdb --quiet -ex "set verbose off" -ex "set pagination off" -ex "set confirm no" -ex "source printers.py" -ex "python gdb.pretty_printers = [lookup_function]" -ex "break 198" -ex "run" -ex "info locals" -ex "quit" --args printer-test > normal.out

The output from the -D_GLIBCXX_DEBUG enabled binary should now match the output from the binary compiled without it.

Note that some of the classes do not have debug variants and are not included in this patch. These are mainly the TR1, __gnu_cxx::slist and __gnu_cxx::slist iterator, shared, weak and unique pointer classes. Some of the debug variant iterators are wrapped in the encapsulating "__gnu_debug::_Safe_iterator" and are renamed, and some are just wrapped and not renamed with the __norm namespace. Some of the iterators have implementation details that required some small changes in the actual iterator printers.

Where appropriate, this patch now writes the class name for the given class as it was passed in via the printer, instead of returning a fixed string.

OK?

Regards

Phil

ChangeLog:

2009-09-30 Phil Muldoon <pmuldoon@redhat.com>

PR python/10646

    * python/libstdcxx/v6/printers.py (StdListPrinter):
    Add -D_GLIBCXX_DEBUG implementation changes. Receive typename from
    printer registration.
    (StdListIteratorPrinter): Likewise.
    (StdDebugIteratorPrinter): New printer.
    (build_libstdcxx_dictionary): Add -D_GLIBCXX_DEBUG registration
    entries.  Always pass a typename where the type can change.
    (StdSlistPrinter) Receive typename from printer registration.  Use
    in printer output.
    (StdBitsetPrinter): Likewise.
    (StdDequePrinter): Likewise.

Attachment: glibcxx_debug_printers.patch
Description: Text document

// Copyright (C) 2009 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <string>
#include <queue>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <memory>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <tr1/unordered_set>
#include <tr1/unordered_map>
#include <tr1/array>
#include <tr1/memory>
#include <ext/slist>

int main ()
{

  /* STL Classes.  */
  std::string t_str ("Hello World");
  std::bitset<32> t_bitset;
  std::deque<int> t_deque;
  std::list<int> t_list;
  std::map<int, const char *> t_map;
  std::multimap<const char *, int> t_mmap;
  std::multiset<int> t_mset;
  std::priority_queue<int> t_pqueue;
  std::queue<int> t_queue;
  std::set<int> t_set;
  std::stack<int> t_stack;
  std::unique_ptr<char[]> t_uptr (new char[1]);
  std::vector<int> t_vector;
  std::shared_ptr<int> t_sptr (new int (2));
  std::weak_ptr<int> t_wptr (t_sptr);

  /* C++0x Classes.  */
  std::unordered_map<int, const char *> t_uomap;
  std::unordered_set<int> t_uoset;
  std::unordered_multimap<const char *, int> t_uommap;
  std::unordered_multiset<int> t_uomset;

  /* TR1.  */
  std::shared_ptr<int> t_tr1_sptr (new int (2));
  std::weak_ptr<int> t_tr1_wptr (t_tr1_sptr);
  std::tr1::unordered_map<int, const char *> t_tr1_uomap;
  std::tr1::unordered_set<int> t_tr1_uoset;
  std::tr1::unordered_multimap<const char *, int> t_tr1_uommap;
  std::tr1::unordered_multiset<int> t_tr1_uomset;

  /* Extensions.  */
  __gnu_cxx::slist<int> t_gnu_slist;
  __gnu_cxx::slist<int>::iterator t_gnu_siter;

  /* Iterators.  */
  std::list<int>::iterator t_liter;
  std::list<int>::const_iterator t_c_liter;
  std::map<int, const char *>::iterator t_rbiter;
  std::map<int, const char *>::const_iterator t_c_rbiter;
  std::deque<int>::iterator t_diter;
  std::deque<int>::const_iterator t_c_diter;
  std::vector<int>::iterator t_viter;
  std::vector<int>::const_iterator t_c_viter;

  /* Bitset.  */
  t_bitset[0] = 1;
  t_bitset[3] = 1;
  t_bitset[11] = 1;
  t_bitset[31] = 1;

  /* Deque.  */
  t_deque.push_back (3);
  t_deque.push_back (5);
  t_deque.push_front (1);
  
  /* List.  */
  t_list.push_back (6);
  t_list.push_back (8);
  t_list.push_front (2);

  /* Map.  */
  t_map[0] = "Zero";
  t_map[5] = "Five";
  t_map[10] = "Ten"; 

  /* Multi Map.  */
  t_mmap.insert (std::make_pair ("One", 1));
  t_mmap.insert (std::make_pair ("Ten", 10));
  t_mmap.insert (std::make_pair ("Five", 5));

  /* Multi Set.  */
  t_mset.insert (1);
  t_mset.insert (9);
  t_mset.insert (5);

  /* Priority Queue. */
  t_pqueue.push (8); 
  t_pqueue.push (0);
  t_pqueue.push (4);
  t_pqueue.push (3);

  /* Queue. */
  t_queue.push (3); 
  t_queue.push (4);
  t_queue.push (0);
  t_queue.push (8);

  /* Set.  */
  t_set.insert (5);
  t_set.insert (9);
  t_set.insert (1);

  /* Stack.  */
  t_stack.push (10);
  t_stack.push (8);
  t_stack.push (2);

  /* Unique_Ptr.  */
  t_uptr[0] = 'z';

  /* Vector.  */
  t_vector.push_back (9);
  t_vector.push_back (5);  

  /* Unordered Map.  */
  t_uomap[0] = "Zero";
  t_uomap[5] = "Five";
  t_uomap[10] = "Ten"; 

  /* Unordered Set.  */
  t_uoset.insert (5);
  t_uoset.insert (9);
  t_uoset.insert (1);

  /* Unordered Multi Map.  */
  t_uommap.insert (std::make_pair ("One", 1));
  t_uommap.insert (std::make_pair ("Ten", 10));
  t_uommap.insert (std::make_pair ("Five", 5));

  /* Unordered Multi Set.  */
  t_uomset.insert (1);
  t_uomset.insert (9);
  t_uomset.insert (5);

  /* Unordered TR1 Map.  */
  t_tr1_uomap[0] = "Zero";
  t_tr1_uomap[5] = "Five";
  t_tr1_uomap[10] = "Ten"; 

  /* Unordered TR1 Set.  */
  t_tr1_uoset.insert (5);
  t_tr1_uoset.insert (9);
  t_tr1_uoset.insert (1);

  /* Unordered TR1 Multi Map.  */
  t_tr1_uommap.insert (std::make_pair ("One", 1));
  t_tr1_uommap.insert (std::make_pair ("Ten", 10));
  t_tr1_uommap.insert (std::make_pair ("Five", 5));

  /* Unordered TR1 Multi Set.  */
  t_tr1_uomset.insert (1);
  t_tr1_uomset.insert (9);
  t_tr1_uomset.insert (5);

  /* __gnu_cxx::slist List.  */
  t_gnu_slist.push_front (6);
  t_gnu_slist.push_front (8);
  t_gnu_slist.push_front (2);
  
  /* Iterators.  */
  t_liter = t_list.begin ();
  t_c_liter = t_list.begin ();
  t_rbiter = t_map.begin ();
  t_c_rbiter = t_map.begin ();
  t_diter = t_deque.begin ();
  t_c_diter = t_deque.begin ();
  t_viter = t_vector.begin ();
  t_c_viter = t_vector.begin ();
  t_gnu_siter = t_gnu_slist.begin ();

  return 0; /* Break here.  */
}

Attachment: normal.out
Description: Text document

Attachment: debug.out
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]