From patchwork Mon Dec 11 05:24:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 24849 Received: (qmail 88749 invoked by alias); 11 Dec 2017 05:25:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 88272 invoked by uid 89); 11 Dec 2017 05:24:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Xavier, xavier, primitive X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Dec 2017 05:24:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EB03F116CC4; Mon, 11 Dec 2017 00:24:38 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id W5pW5bQ2RAIY; Mon, 11 Dec 2017 00:24:38 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id DA9B0116CC2; Mon, 11 Dec 2017 00:24:38 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id D6D95487; Mon, 11 Dec 2017 00:24:38 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Xavier Roirand Subject: [pushed/Ada] change tagged types base_address computation Date: Mon, 11 Dec 2017 00:24:32 -0500 Message-Id: <1512969872-118580-1-git-send-email-brobecker@adacore.com> MIME-Version: 1.0 From: Xavier Roirand Hello, There was a difference between C++ dispatch table and Ada's in the way the Offset_To_Top field is used to determined the base address of an object: * in C++ it is a negative offset, so converting abstract interface to deriving object requires adding this offset to “this”; * in Ada, it was a positive offset, so the same conversion required subtracting the offset value. So in ada, the base address for a tagged type was computed using this formula: base_address = value_address (obj) - offset_to_top; The offset_to_top value was previously set to 0 or a positive value. With recent version of AdaCore's GNAT compiler, the offset has been changed to match C++, which means it's set to zero or a negative value As a result, the new formula has to be: base_address = value_address (obj) + offset_to_top; Because we want to support old code compiled before GNAT compiler change done in 19.0w (20171023-64) with this version and future versions of gdb, then we change the sign of the offset_to_top if required. Required here means if offset_to_top is positive since it indicates that the code has been compiled with an old GNAT compiler. This patch changes the formula as described above. Also, one side-effect of offset_to_top now being negative is that we now have to worry about the sign when we read its value from the inferior. Up to now, we have been reading its value using the data address builtin type. But since addresses are not always signed, we now need to make sure we use the proper type (type Storage_Offset from System.Storage_Elements). Ideally, we would be looking this type up from the inferior, and then use that type. However, it is not guaranteed that this type always be described in the debugging information, so this patch just builds our own, adding it to Ada's list of primitive types. gdb/ChangeLog: * ada-lang.c (ada_tag_value_at_base_address): Change the way tagged type base address is computed. (enum ada_primitive_types) : New enumerate. (ada_language_arch_info): Set the ada_primitive_type_storage_offset element of lai->primitive_type_vector. Tested on x86_64-linux. Fixes the following tests when using the newer version of the compiler. gdb.ada/iwide.exp: print My_Drawable gdb.ada/iwide.exp: print d_access.all gdb.ada/iwide.exp: print dp_access.all gdb.ada/mi_interface.exp: create ggg1 varobj (unexpected output) gdb.ada/mi_interface.exp: list ggg1's children (unexpected output) gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint) (unexpected output) gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint) Pushed to master. Thank you, diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1d38113..1c67e41 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2017-12-11 Xavier Roirand + Joel Brobecker + + * ada-lang.c (ada_tag_value_at_base_address): Change the way + tagged type base address is computed. + (enum ada_primitive_types) : + New enumerate. + (ada_language_arch_info): Set the ada_primitive_type_storage_offset + element of lai->primitive_type_vector. + 2017-12-08 Pedro Alves * dwarf2read.c (mock_mapped_index): Reimplement as an extension of diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d6f7ef4..9e637eb 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6761,7 +6761,8 @@ ada_tag_value_at_base_address (struct value *obj) if (is_ada95_tag (tag)) return obj; - ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; + ptr_type = language_lookup_primitive_type + (language_def (language_ada), target_gdbarch(), "storage_offset"); ptr_type = lookup_pointer_type (ptr_type); val = value_cast (ptr_type, tag); if (!val) @@ -6795,7 +6796,18 @@ ada_tag_value_at_base_address (struct value *obj) if (offset_to_top == -1) return obj; - base_address = value_address (obj) - offset_to_top; + /* OFFSET_TO_TOP used to be a positive value to be subtracted + from the base address. This was however incompatible with + C++ dispatch table: C++ uses a *negative* value to *add* + to the base address. Ada's convention has therefore been + changed in GNAT 19.0w 20171023: since then, C++ and Ada + use the same convention. Here, we support both cases by + checking the sign of OFFSET_TO_TOP. */ + + if (offset_to_top > 0) + offset_to_top = -offset_to_top; + + base_address = value_address (obj) + offset_to_top; tag = value_tag_from_contents_and_address (obj_type, NULL, base_address); /* Make sure that we have a proper tag at the new address. @@ -13866,6 +13878,7 @@ enum ada_primitive_types { ada_primitive_type_natural, ada_primitive_type_positive, ada_primitive_type_system_address, + ada_primitive_type_storage_offset, nr_ada_primitive_types }; @@ -13918,6 +13931,18 @@ ada_language_arch_info (struct gdbarch *gdbarch, TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address]) = "system__address"; + /* Create the equivalent of the System.Storage_Elements.Storage_Offset + type. This is a signed integral type whose size is the same as + the size of addresses. */ + { + unsigned int addr_length = TYPE_LENGTH + (lai->primitive_type_vector [ada_primitive_type_system_address]); + + lai->primitive_type_vector [ada_primitive_type_storage_offset] + = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0, + "storage_offset"); + } + lai->bool_type_symbol = NULL; lai->bool_type_default = builtin->builtin_bool; }