This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

Python pretty-printed output isn't pretty :-(


Greetings,

Consider:

--- simple-stl2.cc ---
#include <map>
#include <string>

using namespace std;
struct Foo {
  map<int, string> mis;
  map<string, int> msi;
};

int main(int argc, char *argv[])
{
  Foo foo;
  for (int i = 0; i < argc; ++i) {
    foo.mis[i] = argv[i];
    foo.msi[argv[i]] = i;
  }
  return 0; // break here
}
--- simple-stl2.cc ---

With 'set print pretty on', the output of Tom's std::map pretty
printer looks nice:

(gdb) run foe fi fu fum
(gdb) p foo
$1 = {
  mis = std::map with 5 elements
        [0] = 0x406068 "/home/ppluzhnikov/src/tmp/simple-stl2"
        [1] = 0x406188 "foe"
        [2] = 0x406268 "fi"
        [3] = 0x406348 "fu"
        [4] = 0x406428 "fum", 
  msi = std::map with 5 elements
        [0x4060b8 "/home/ppluzhnikov/src/tmp/simple-stl2"] = 0
        [0x406298 "fi"] = 2
        [0x4061b8 "foe"] = 1
        [0x406378 "fu"] = 3
        [0x406458 "fum"] = 4
}

Not so with 'set print pretty off':
(gdb) set print pretty off
(gdb) p foo
$2 = {mis = std::map with 5 elements
            [0] = 0x406068 "/home/ppluzhnikov/src/tmp/simple-stl2"
            [1] = 0x406188 "foe"
            [2] = 0x406268 "fi"
            [3] = 0x406348 "fu"
            [4] = 0x406428 "fum", msi = std::map with 5 elements
                                        [0x4060b8 "/home/ppluzhnikov/src/tmp/simple-stl2"] = 0
                                        [0x406298 "fi"] = 2
                                        [0x4061b8 "foe"] = 1
                                        [0x406378 "fu"] = 3
                                        [0x406458 "fum"] = 4}

My attempt to fix this (attached at the end) didn't improve things
that much:

(gdb) p foo
$3 = {mis = 
std::map with 5 elements, [0] = 0x406068 "/home/ppluzhnikov/src/tmp/simple-stl2", [1] = 0x406188 "foe", [2] = 0x406268 "fi", [3] = 0x406348 "fu", [4] = 0x406428 "fum", msi = 
std::map with 5 elements, [0x4060b8 "/home/ppluzhnikov/src/tmp/simple-stl2"] = 0, [0x406298 "fi"] = 2, [0x4061b8 "foe"] = 1, [0x406378 "fu"] = 3, [0x406458 "fum"] = 4}
(gdb) 

I guess ideally I'd like to see somethig like:

  $3 = { mis = std::map with 5 elements = {[0] = 0x406068 "/home/ppluzhnikov/src/tmp/simple-stl2",
  [1] = 0x406188 "foe", [2] = 0x406268 "fi", [3] = 0x406348 "fu", [4] = 0x406428 "fum"}, 
  msi = std::map with 5 elements = {[0x4060b8 "/home/ppluzhnikov/src/tmp/simple-stl2"] = 0,
  [0x406298 "fi"] = 2, [0x4061b8 "foe"] = 1, [0x406378 "fu"] = 3, [0x406458 "fum"] = 4}}

But I don't see how Python pretty printer could cooperate with wrap_here().
It could pay attention to width though.

Comments?

--
Paul Pluzhnikov

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9f4448b..51a22cd 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1180,7 +1180,11 @@ def _format_children(obj):\n\
       i = i + 1\n\
       if max != None and i == max:\n\
        break\n\
-  return '\\n'.join(result)\n\
+  if gdb.get_parameter('print pretty'):\n\
+    separator = '\\n'\n\
+  else:\n\
+    separator = ', '\n\
+  return separator.join(result)\n\
 \n\
 gdb._format_children = _format_children\n\
 ");


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