On 07/26/2015 10:45 PM, Jonathan Wakely wrote:
On 26 July 2015 at 16:06, Avi Kivity wrote:
libstdc++ pretty-printers are a life-saver when inspecting containers.
However, they also hide information: the type of the element being inspected
(can often be inferred by the user) and the address of the element (which
cannot).
Is there a way to add this information to the pretty-printers output?
In principle we can add anything, the difficulty is figuring out how
to present it clearly without cluttering or obscuring the output.
Suggestions for improving the printers are very welcome.
Well, with gdb support, I can go wild:
(gdb) print /addresses $container
$5 = std::map<std::string, myvalue> with 5 elements {
(std::pair<const std::string, myvalue>*)0x46374672 { "foo":
whatever },
...
}
(the address printout is designed for easy cut'n'paste)
or even
(gdb) print $container
$5 = std::map<std::string, myvalue> with 5 elements {
$6 = { "foo": whatever },
$7 = { "bar": another one },
...
}
(gdb) print &$6
$8 = (std::pair<const std::string, myvalue>*)0x46374672
Without gdb support, we could have a user-defined flag to toggle address
printing
(gdb) glibcxx set print addresses on
(gdb) print $container
$5 = std::map<std::string, myvalue> with 5 elements {
(std::pair<const std::string, myvalue>*)0x46374672 { "foo":
whatever },
...
}
xmethods for operator[] would also help, but these would require the
user to write xmethods for user-defined constructors if used as a
container key.
I realize this is a lot of work, but as it is, debugging modern C++
programs is quite a headache with g++/gdb. gdb won't even load binaries
compiled with -O0, and with -O2, you're either in the maze that is
libstdc++, or you see nice output from the prettyprinters but you can't
inspect the data further.