This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Python pretty-printed output isn't pretty :-(
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Fri, 7 Nov 2008 15:02:11 -0800 (PST)
- Subject: Python pretty-printed output isn't pretty :-(
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1226098934; bh=hzFT8S9mEapuuL8jini6sVYC3Zk=;h=DomainKey-Signature:To:Cc:Subject:Message-Id:Date:From; b=EGRpRGjgUAq4OqwcQlucaObq1RDGaNTKOScQavjOCvch2EoPicsFYfVttJhVq/3lrhioqWO7iAtSrkZA1zXxAg==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=to:cc:subject:message-id:date:from;b=Iz9qvrDGswb7WDOt7m5Ro3L12QKcbp6huGpq18IJxcZRtHKHuUUurg1RtHJOh2DO43coadjWWffgpZSmUXP0lg==
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\
");