[Bug other/83161] New: Feature request: add a builtin for printing structs and classes

Hi-Angel at yandex dot ru gcc-bugzilla@gcc.gnu.org
Sat Nov 25 17:29:00 GMT 2017


            Bug ID: 83161
           Summary: Feature request: add a builtin for printing structs
                    and classes
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Hi-Angel at yandex dot ru
  Target Milestone: ---

It's very useful for debugging to pretty-print an entire struct. Typically
people firing up gdb for this, but sometimes it's hard, like on embedded
systems; and always is time-consuming.

This issue is popular enough that e.g. the new systems language Rust have this
functionality built-in.

Some relevant questions to show demand:
1. "Printing values of all fields in a C++ structure"
2. Someone attempting the same thing for linux kernel

Prior art: Haskell language have a very simple implementation: adding after
declaration of a type "derive Show" generates a code for returning a string
with human-readable description of its object. And if a programmer wants to
tweak representation of a specific type, they override "show" function.

So, I imagine a function "_gcc_show()", and 2 attributes — one to generate a
code for a struct/class, another to override a "_gcc_show()" for certain type —
would be more than enough.

More information about the Gcc-bugs mailing list