public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Add extensions to dwarf2.def
Date: Tue, 09 Jun 2015 10:27:00 -0000	[thread overview]
Message-ID: <5576BB25.50203@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1442 bytes --]

Hello,

I'm currently working on migrating debugging information for Ada from 
GNAT encodings to standard DWARF. At the moment, I have worked on two 
topics that I believe are not (completely) supported in standard DWARF:

   - fixed point types with arbitrary scale factors;
   - scalar types with biased representations.

My goal is to submit an issue on dwarfstd.org in an attempt to introduce 
these extensions to the next DWARF standard. Before that, though, I 
would like to make sure that these extensions actually fit the need by 
having them supported both in GCC and GDB.

The two attached patches make these extensions "public" so that no other 
vendor-specific tags/attributes conflict with them in the future. I 
cannot submit the patches that actually use these right now because I 
need first to port them from the 4.9 branch onto mainline (I hope I will 
be able to do this on early July).

May I commit them?

I also attached two documents that describe how to use these 
extensions. I guess this should go to the wiki just like for 
DW_AT_GNAT_descriptive_type 
(https://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type). I will do this 
if the patches are integrated.

Thank you in advance!

include/
         * dwarf2.def (DW_TAG_GNU_rational_constant): New tag.
         (DW_AT_GNU_numerator, DW_AT_GNU_denominator): New attributes.

include/
         * dwarf2.def (DW_AT_GNU_bias): New attribute.

-- 
Pierre-Marie de Rodat

[-- Attachment #2: gcc-DW_TAG_GNU_rational_constant.txt --]
[-- Type: text/plain, Size: 2545 bytes --]

== Introduction ==

Ada makes it possible to define fixed point types. In order to specify how
these will be represented at runtime, the compiler selects a size in bytes and
a "scale factor", which is a strictly positive rational number.  Assuming type
T is associated with the S scale factor, then values V will be represented at
runtime by R so that V = S * R.


== Fixed points in DWARF today ==

Since DWARFv3, there are several ways to describe fixed point types, all of
these require to use DW_TAG_base_type DIEs.  The encoding must be
DW_ATE_signed_fixed or DW_ATE_unsigned_fixed and the scale factor must be
encoded using one of the following attributes:

* DW_AT_decimal_scale, which makes it possible to represent scale factors of
  the form 10**N (with N any signed integer).

* DW_AT_binary_scale, which makes it possible to represent scale factors of
  the form 2**N (with N any signed integer).

* DW_AT_small, which is a reference to a DW_TAG_constant entry providing the
  scale factor itself.


== Limitations ==

While DW_AT_small enables one to describe any scale factor the two other
attributes could, there are still some scale factors that are not encodable as
of today.

In Ada, it is possible to define fixed point types with scale factors such as
1/3.  For instance:

    type T is delta 0.1 range 0.0 .. 1.0
       with Small => 1.0/3.0;

Trying to represent 1/3 with a DW_TAG_constant leads to a chicken an egg problem
today: the constant is encoded in the DW_AT_const_value attribute, which must
be "the actual constant value [...] represented as it would be on the target
architecture". 1/3 can be represented on the target architecture, but only with
a fixed point type... whose scalar factor is 1/3, or 1/30, etc.


== Proposed extension ==

One new tag and two new attributes are proposed to solve this problem:

* DW_TAG_GNU_rational_constant, whose purpose is to describe any rational
  constant.  It must have exactly two attributes:

* DW_AT_GNU_numerator and DW_AT_GNU_denominator, whose forms are any constant
  form (DW_FORM_*data*) and which represent an integer (unsigned, unless the
  form represents a signed one).

The rational constant represented by DW_TAG_GNU_rational_constant is N/D where:

* N is the integer represented by the DW_AT_GNU_numerator attribute;
* D is the integer represented by the DW_AT_GNU_denominator attribute;

With this new tag, it is possible to represent arbitrary rational scale factors
for fixed point types, enabling one to describe all possible Ada fixed point
types.

[-- Attachment #3: gcc-DW_AT_GNU_bias.txt --]
[-- Type: text/plain, Size: 1323 bytes --]

== Introduction ==

In Ada, it is possible for a scalar type to have a biased representation in
some contexts.  For instance:

    type Small_Type is range 50 .. 57;

    type Record_Type is record
       A, B : Small_Type;
    end record;
    for Record_Type use record
       A at 0 range 0 .. 2;
       B at 0 range 3 .. 5;
    end record;

In Record_Type, the A and B fields will be represented on 3 bits each.  This is
possible because they have a biased representation:

* the 000 bit pattern represents 50;
* the 001 one represents 51;
* etc.

So in this example, the representation for A and B have a bias of 50. The
general principle is that given some type T, a bias B and a value V, the
runtime representation for V is:

   V - B

There is no way to describe this representation in DWARF today.


== Proposed extension ==

One new attribute is proposed to lift this limitation: DW_AT_GNU_bias, whose
form is any constant form and which represents an integer (unsigned, unless the
form represents a signed one).  This attribute can appear on
DW_TAG_subrange_type DIEs. The corresponding subrange and only this one must be
decoded using the bias.

 The bias is not inheritted in subranges that reference this one so that bias
processing is consistent with bounds processing (DW_AT_lower_bound,
DW_AT_upper_bound).

[-- Attachment #4: 0001-DWARF2-add-extensions-to-handle-fixed-point-types.patch --]
[-- Type: text/x-diff, Size: 1582 bytes --]

From d1db222b4ad482901eb574b93a1a6a00b6711aeb Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Tue, 9 Jun 2015 10:31:50 +0200
Subject: [PATCH 1/2] DWARF2: add extensions to handle fixed point types

include/
	* dwarf2.def (DW_TAG_GNU_rational_constant): New tag.
	(DW_AT_GNU_numerator, DW_AT_GNU_denominator): New attributes.
---
 include/dwarf2.def | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/dwarf2.def b/include/dwarf2.def
index ea8127c..0634d6e 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -169,6 +169,9 @@ DW_TAG (DW_TAG_GNU_formal_parameter_pack, 0x4108)
    are properly part of DWARF 5.  */
 DW_TAG (DW_TAG_GNU_call_site, 0x4109)
 DW_TAG (DW_TAG_GNU_call_site_parameter, 0x410a)
+/* Rational constant extension.
+   See https://gcc.gnu.org/wiki/DW_TAG_GNU_rational_constant .  */
+DW_TAG (DW_TAG_GNU_rational_constant, 0x410b)
 /* Extensions for UPC.  See: http://dwarfstd.org/doc/DWARF4.pdf.  */
 DW_TAG (DW_TAG_upc_shared_type, 0x8765)
 DW_TAG (DW_TAG_upc_strict_type, 0x8766)
@@ -406,6 +409,10 @@ DW_AT (DW_AT_VMS_rtnbeg_pd_address, 0x2201)
    See http://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type .  */
 DW_AT (DW_AT_use_GNAT_descriptive_type, 0x2301)
 DW_AT (DW_AT_GNAT_descriptive_type, 0x2302)
+/* Rational constant extension.
+   See https://gcc.gnu.org/wiki/DW_TAG_GNU_rational_constant .  */
+DW_TAG (DW_AT_GNU_numerator, 0x2303)
+DW_TAG (DW_AT_GNU_denominator, 0x2304)
 /* UPC extension.  */
 DW_AT (DW_AT_upc_threads_scaled, 0x3210)
 /* PGI (STMicroelectronics) extensions.  */
-- 
2.3.6


[-- Attachment #5: 0002-DWARF2-add-extensions-to-handle-biased-types.patch --]
[-- Type: text/x-diff, Size: 929 bytes --]

From bb4667b65090d5c61710abb3f328a591cfa60ee9 Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Tue, 9 Jun 2015 10:31:50 +0200
Subject: [PATCH 2/2] DWARF2: add extensions to handle biased types

include/
	* dwarf2.def (DW_AT_GNU_bias): New attribute.
---
 include/dwarf2.def | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/dwarf2.def b/include/dwarf2.def
index 0634d6e..212ea54 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -413,6 +413,9 @@ DW_AT (DW_AT_GNAT_descriptive_type, 0x2302)
    See https://gcc.gnu.org/wiki/DW_TAG_GNU_rational_constant .  */
 DW_TAG (DW_AT_GNU_numerator, 0x2303)
 DW_TAG (DW_AT_GNU_denominator, 0x2304)
+/* Biased integer extension.
+   See https://gcc.gnu.org/wiki/DW_AT_GNU_bias .  */
+DW_TAG (DW_AT_GNU_bias, 0x2305)
 /* UPC extension.  */
 DW_AT (DW_AT_upc_threads_scaled, 0x3210)
 /* PGI (STMicroelectronics) extensions.  */
-- 
2.3.6


             reply	other threads:[~2015-06-09 10:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09 10:27 Pierre-Marie de Rodat [this message]
2015-08-13 19:02 ` Cary Coutant
2015-08-14  9:55   ` Pierre-Marie de Rodat
2015-08-18  8:45     ` Pedro Alves
2015-08-18  9:37       ` Manuel López-Ibáñez
2015-08-18 10:25         ` Pierre-Marie de Rodat
2015-08-18 12:16           ` Pedro Alves
2015-08-18 12:39             ` Pierre-Marie de Rodat
2015-08-18 12:49               ` Manuel López-Ibáñez
2015-08-18 13:11                 ` Pierre-Marie de Rodat

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=5576BB25.50203@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.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).