public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv2 2/2] gdb/python: add Type.signedness attribute
Date: Wed, 8 Dec 2021 08:35:57 -0500	[thread overview]
Message-ID: <d608bbef-3246-4aee-09c1-893e880b9209@polymtl.ca> (raw)
In-Reply-To: <20211208095657.GI123597@redhat.com>

On 2021-12-08 04:56, Andrew Burgess wrote:
> * 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.

Ah, from the sentence in the doc, I assumed that all three would return
NONE.

> 
> 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.

If I look at one of my executables, compiled with gcc 11:

0x00000069:   DW_TAG_base_type
                DW_AT_byte_size [DW_FORM_data1] (0x01)
                DW_AT_encoding [DW_FORM_data1]  (DW_ATE_signed_char)
                DW_AT_name [DW_FORM_strp]       ("char")

And if I build with -funsigned-char:

0x00000069:   DW_TAG_base_type
                DW_AT_byte_size [DW_FORM_data1] (0x01)
                DW_AT_encoding [DW_FORM_data1]  (DW_ATE_unsigned_char)
                DW_AT_name [DW_FORM_strp]       ("char")

Yet, the DWARF reader does:

  if (type->code () == TYPE_CODE_INT
      && name != nullptr
      && strcmp (name, "char") == 0)
    type->set_has_no_signedness (true);

I'd like to know the rationale for this, it doesn't make sense to me.
This is pretty much orthogonal to your patch though, your patch in
itself looks good to me.

Simon

  parent reply	other threads:[~2021-12-08 13:36 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
2021-12-08 10:19         ` [PATCHv3 " Andrew Burgess
2021-12-08 13:35         ` Simon Marchi [this message]
2021-12-08 16:56           ` [PATCHv2 " 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=d608bbef-3246-4aee-09c1-893e880b9209@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@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).