0

In gdb currently I can print the contents of a container, such as std::list, which contains a structure type. This type, however, is quite large and I need only values of some selected fields in every item from the container. So, let's say, I have a structure that contains about 100 fields and I have 3 items in the container and need to display the type field. So:

(gdb) p items

will display lots of noise, while

(gdb) p items[0].type

won't work with std::list, moreover, with list I can easily display the value of only the first item (other require lots of spaghetti with typecasts, fields reaching etc.), while I need someting, say:

(gdb-maybe) p {foreach i: items} i.type

which would display every item just like the container printer does normally, except that the displayed values will only contain the type field.

Is there any way to achieve anything like this, or maybe some method to provide such a solution using a script?

Ethouris
  • 1,791
  • 13
  • 18
  • How about writing a function that prints the values, then call that function from GDB and pass in the list. – super Feb 08 '22 at 12:44
  • Yeah, that could be the method to do it, but it should be defined already in the code before I start debugging, not to be used at the moment when I have reached the contents of one of thousands of structures and come to an idea that it would be nice to display just one field across the whole container. – Ethouris Feb 08 '22 at 14:14
  • How about `py for c in gdb.default_visualizer(gdb.parse_and_eval('items')).children(): print(c[1]['type'])`? – ssbssa Feb 09 '22 at 12:25

0 Answers0