public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "jwakely.gcc at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug python/27510] New: Document gdb.Type string representations
Date: Thu, 04 Mar 2021 13:00:16 +0000	[thread overview]
Message-ID: <bug-27510-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=27510

            Bug ID: 27510
           Summary: Document gdb.Type string representations
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: jwakely.gcc at gmail dot com
  Target Milestone: ---

Re https://sourceware.org/gdb/current/onlinedocs/gdb/Types-In-Python.html

We've had numerous libstdc++ bugs in the python printers that are due to me
failing to use the right string representation of a type. I find it unclear
whether I should use gdb.Type.name (which isn't present in older GDB versions)
or gdb.Type.tag or str(gdb.Type). The docs do not really say what the various
strings contain, particularly for C++ class types, with possible cv-qualifiers
present.

The conversion to String is completely undocumented. On IRC I was told that
it's similar to whatis/r s, which seems to be true. I'm told that for some
combinations of GCC and GDB that string includes "class", which means it isn't
suitable as an argument to the gdb.lookup_type function. It doesn't drop
cv-qualifiers, e.g. 

(gdb) py print(gdb.lookup_type('int').const())
const int

The difference between gdb.Type.name and gdb.Type.tag is unclear, except that
gdb.Type.name doesn't exist in older GDB versions (which could be documented
too), and for non-class types (e.g. integer types and functions) there is no
tag e.g.

(gdb) py print(gdb.lookup_type('int').tag)
None
(gdb) py print(gdb.lookup_type('int').name)
int

As far as I can tell, both drop cv-qualifiers:

(gdb) py print(gdb.lookup_type('int').const().name)
int

They seem to be the same for class and enumeration types. But a typedef for a
class has a name but no tag, which makes sense, but could be stated explicitly.

Given:

int main()
{
  struct S {} s;
  using C = const S;
  C c = S();
  return 0;
}


I get this with GDB 9.1:

$ gdb -q -ex start  a.out
Reading symbols from a.out...
Temporary breakpoint 1 at 0x401106: file test.C, line 6.
Starting program: /tmp/a.out 

Temporary breakpoint 1, main () at test.C:6
6         return 0;
(gdb) py s = gdb.parse_and_eval('s'); c = gdb.parse_and_eval('c')
(gdb) py print(s.type)
S
(gdb) py print(s.type.tag)
S
(gdb) py print(s.type.name)
S
(gdb) py print(c.type)
C
(gdb) py print(c.type.tag)
None
(gdb) py print(c.type.name)
C
(gdb) py print(c.type.strip_typedefs())
const S
(gdb) py print(c.type.strip_typedefs().name)
S
(gdb) py print(c.type.strip_typedefs().tag)
S

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2021-03-04 13:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 13:00 jwakely.gcc at gmail dot com [this message]
2021-03-04 13:04 ` [Bug python/27510] " jwakely.gcc at gmail dot com
2021-03-04 13:06 ` hi-angel at yandex dot ru
2021-03-04 14:28 ` jwakely.gcc at gmail dot com
2021-03-05 13:50 ` ssbssa at sourceware dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-27510-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).