11

I have installed GDB 7.0 and python per the following instructions. In the same manual, there is a mention of this file stl-views-1.0.3.gdb. What confuses me is where it should be placed in order to enable pretty printing of stl containers. Would someone also explain to me all of this work?

Thanks

vehomzzz
  • 42,832
  • 72
  • 186
  • 216

3 Answers3

14

As far as I can tell, stl-views are the old way to examine STL containers, and are inferior to the new python support in almost every way.

You should use libstdcxx_printers python pretty-printers instead.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • What is the difference between libstdcxx_printers and stl-views then? – Nordlöw May 20 '11 at 10:24
  • The libstdcxx_printers are shipped and maintained as part of GCC, so they always match the version of the compiler you're using and know about changes to the container internals. The python printing is enabled automatically, is far more powerful and is more easily extended to your own types. – Jonathan Wakely Jun 12 '12 at 09:16
  • The instructions for getting libstdcxx pretty printers are at http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.gdb . – Evgeni Sergeev Jan 18 '14 at 07:45
10

in the gdb:

source {full_path}stl-views-1.0.3.gdb

now you'll have new commands, such as pvector, plist, pmap and more (replace {full_path} with the full path to the file.

You can also put the command source stl-views-1.0.3.gdb in ~/.gdbinit - and then you'll have it automatically every time you launch gdb.

Drakosha
  • 11,925
  • 4
  • 39
  • 52
  • 1
    Do I have to do it every time I load gdb? Can it be done by default? Shuold stl-views-1.0.3.gdb be located in the current working directory? – vehomzzz Mar 17 '10 at 14:58
  • 2
    Can't you just put it in your `~/.gdbinit`? – Cascabel Mar 17 '10 at 15:02
  • Can you elaborate? So I start gdb and I type that? I just get `No such file or directory.` – Kache Mar 17 '10 at 15:22
  • @Kache4 do you actually have the file? source stl-views-1.0.3.gdb is NOT a command, but rather a command followed by the file name, although you've probably figured this out by now. – vehomzzz Mar 17 '10 at 15:43
  • @Andrei: I guess not. `locate` doesn't find anything. Where can I get it? Quick Google search and search using Ubuntu synaptic didn't get me anything. – Kache Mar 17 '10 at 17:33
  • @Kache4: there's a link in the question itself – Drakosha Mar 17 '10 at 19:48
  • I agree with "Employed Russian". This is the old - pre gdb7 - way of doing things. See the related http://stackoverflow.com/questions/2492020/how-to-view-contents-of-stl-containers-using-gdb-7-x – nimrodm Jun 29 '10 at 18:37
  • @Drakosha Hi, assume `pvector` works, what if I have a data structure which has vectors inside a vector (vector >)? How can I print elements of the inner vectors? – Scott Yang Nov 12 '18 at 12:52
  • ah i see. for the situation I described above, the `pvector` command automatically prints the elements of the inner vectors. https://blog.csdn.net/cws1214/article/details/8500730 http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt – Scott Yang Nov 12 '18 at 13:04
0

FYI, these instructions dont work on Ubuntu lucid at least. See this bug i just filed

kert
  • 2,161
  • 21
  • 22