From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv2 2/2] gdb/python: add Type.signedness attribute
Date: Wed, 8 Dec 2021 09:56:57 +0000 [thread overview]
Message-ID: <20211208095657.GI123597@redhat.com> (raw)
In-Reply-To: <ed3df399-035a-a116-767d-245a156a28c7@polymtl.ca>
* Simon Marchi <simon.marchi@polymtl.ca> [2021-12-07 22:13:40 -0500]:
> > +@vindex TYPE_SIGNEDNESS_NONE
> > +@item gdb.TYPE_SIGNEDNESS_NONE
> > +This type is considered neither signed, or unsigned. This applies to
> > +all non-scalar types (e.g.@: c language structs), but can sometimes be
> > +the value return for scalar type, one example of where this can be
> > +seen is in C++, where @code{char}, @code{signed char}, and
> > +@code{unsigned char} are all considered distinct types.
>
> I'm curious, why would type `unsigned char` not return
> gdb.TYPE_SIGNEDNESS_UNSIGNED? I see the corresponding code in
> gdbtypes.c, with the m_flag_nosign flag, so I understand that you would
> implementation the Python binding based on that, but I am wondering
> about the historical reason.
Sorry, but I don't understand the question. I'm assuming you actually
meant to ask a slightly different question, but, just for clarity,
I'll answer your actual question first. I added these declarations to
gdb.python/py-type.c:
unsigned char global_unsigned_char;
char global_char;
signed char global_signed_char;
And these tests to gdb.python/py-type.exp:
gdb_test "python print (gdb.parse_and_eval ('global_unsigned_char').type.signedness == gdb.TYPE_SIGNEDNESS_UNSIGNED)" "True"
gdb_test "python print (gdb.parse_and_eval ('global_char').type.signedness == gdb.TYPE_SIGNEDNESS_NONE)" "True"
gdb_test "python print (gdb.parse_and_eval ('global_signed_char').type.signedness == gdb.TYPE_SIGNEDNESS_SIGNED)" "True"
So you can see that `unsigned char` does return
gdb.TYPE_SIGNEDNESS_UNSIGNED.
If your question is why would `char` not return UNSIGNED, then it
appears that plain char is not defined as unsigned in the standard.
This appears to be described in 6.2.5/15 of the C language draft that
I have to hand:
"The three types char, signed char, and unsigned char are
collectively called the character types. The implementation shall
define char to have the same range, representation, and behavior as
either signed char or unsigned char.)"
But I guess the problem is that whether char is signed or unsigned is
not encoded into the DWARF.
I'll update the Python documentation to talk about C/C++ rather than
just C++ w.r.t. this state.
Hope that helps,
Andrew
next prev parent reply other threads:[~2021-12-08 9:57 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 16:06 [PATCH 0/2] Add new gdb.Type.signedness attribute Andrew Burgess
2021-12-03 16:06 ` [PATCH 1/2] gdb: use ARRAY_SIZE for iterating over an array Andrew Burgess
2021-12-03 21:02 ` Tom Tromey
2021-12-03 16:06 ` [PATCH 2/2] gdb/python: add Type.signedness attribute Andrew Burgess
2021-12-03 21:05 ` Tom Tromey
2021-12-06 14:08 ` [PATCHv2 0/2] Add new gdb.Type.signedness attribute Andrew Burgess
2021-12-06 14:08 ` [PATCHv2 1/2] gdb: use a range based for loop when iterating over an array Andrew Burgess
2022-02-24 16:40 ` Andrew Burgess
2021-12-06 14:08 ` [PATCHv2 2/2] gdb/python: add Type.signedness attribute Andrew Burgess
2021-12-08 3:13 ` Simon Marchi
2021-12-08 9:56 ` Andrew Burgess [this message]
2021-12-08 10:19 ` [PATCHv3 " Andrew Burgess
2021-12-08 13:35 ` [PATCHv2 " Simon Marchi
2021-12-08 16:56 ` Tom Tromey
2021-12-09 12:34 ` Andrew Burgess
2021-12-07 19:26 ` [PATCHv2 0/2] Add new gdb.Type.signedness attribute Tom Tromey
2022-02-25 13:55 ` [PATCHv3 0/3] Add Type.is_scalar and Type.is_signed properties Andrew Burgess
2022-02-25 13:55 ` [PATCHv3 1/3] gdb/python: add Type.is_scalar property Andrew Burgess
2022-02-25 14:11 ` Eli Zaretskii
2022-02-25 13:55 ` [PATCHv3 2/3] gdb/python: add Type.is_signed property Andrew Burgess
2022-02-25 14:12 ` Eli Zaretskii
2022-02-25 13:55 ` [PATCHv3 3/3] gdb/testsuite: add new test for comparing char types in Python Andrew Burgess
[not found] ` <cover.1645788436.git.aburgess__7628.6948680476$1645797489$gmane$org@redhat.com>
2022-02-25 17:08 ` [PATCHv3 0/3] Add Type.is_scalar and Type.is_signed properties Tom Tromey
2022-03-07 19:43 ` Andrew Burgess
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=20211208095657.GI123597@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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).