This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++ pretty-printers vs. inspecting objects
- From: Avi Kivity <avi at cloudius-systems dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 27 Jul 2015 11:54:59 +0300
- Subject: Re: libstdc++ pretty-printers vs. inspecting objects
- Authentication-results: sourceware.org; auth=none
- References: <55B4F76C dot 20904 at cloudius-systems dot com> <CAH6eHdSXwhTn=yrk7rjfcvP7w0D926yY2NFrtWhCkVCm2aZjiw at mail dot gmail dot com>
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.