From 560612d467cb21160961205aeac944771f2dcbde Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 9 Apr 2010 07:44:31 +0200 Subject: [PATCH] check out how to use the GDB Python pretty-printers Yes, it works with GDB 7.1 from Debian/Squeeze --- src/tool/try.cpp | 69 +++++++++++------------------------------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/src/tool/try.cpp b/src/tool/try.cpp index af6b66ae1..af04c66eb 100644 --- a/src/tool/try.cpp +++ b/src/tool/try.cpp @@ -15,6 +15,7 @@ // 6/09 - investigating how to build a mixin template providing an operator bool() // 12/9 - tracking down a strange "warning: type qualifiers ignored on function return type" // 1/10 - can we determine at compile time the presence of a certain function (for duck-typing)? +// 4/10 - pretty printing STL containers with python enabled GDB? //#include @@ -25,6 +26,7 @@ #include //#include +#include #include #include #include @@ -36,68 +38,27 @@ using std::cout; using std::endl; -struct A - { - int& funA (); - }; - -struct B - { - void funA(); - }; - - - typedef char Yes_t; - struct No_t { char padding[8]; }; - - - template - class Detector1 - { - template - struct Probe - { }; - - template - static Yes_t check(Probe*); - template - static No_t check(...); - - public: - static const bool value = (sizeof(Yes_t)==sizeof(check(0))); - }; - - - template - class Detector2 - { - template - struct Probe - { }; - - template - static Yes_t check(Probe*); - template - static No_t check(...); - - public: - static const bool value = (sizeof(Yes_t)==sizeof(check(0))); - }; - - int main (int, char**) { // NOBUG_INIT; - cout << "Detector1 = " << Detector1::value << endl; - cout << "Detector1 = " << Detector1::value << endl; + std::string str = "hullo wöld"; + std::vector vec (1000); - cout << "Detector2 = " << Detector2::value << endl; - cout << "Detector2 = " << Detector2::value << endl; + for (uint i = 0; i < vec.size(); ++i) + vec[i] = i; - cout << "\n.gulp.\n"; + cout << str << "\n.gulp.\n"; + + // Note: when selecting the string or the vector in the Eclipse variables view + // (or when issuing "print str" at the GDB prompt), the GDB python pretty-printer + // should be activated. Requires an python enabled GDB (>6.8.50). Debian/Lenny isn't enough, + // but compiling the GDB package from Debian/Squeeze (GDB-7.1) is straightforward. + // Moreover, you need to check out and install the python pretty-printers and + // you need to activate them through your ~/.gdbinit + // see http://sourceware.org/gdb/wiki/STLSupport return 0; }