From patchwork Thu Jun 10 08:27:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 43807 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D9AF3AAA0B3 for ; Thu, 10 Jun 2021 08:27:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D9AF3AAA0B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623313634; bh=jTPJ52RIXDbr3/0ylU/QIyD8BR3BZGOkpNGUNeoQFd4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=jrzcxdKLqX0fnqi/yeuNSr5DkswCSIxk++GtoatBaE53EHjeIixkrRy+yWVEZJ0uV amzDyQ5OI15cqHCtIJz72vc0m9fCQ2AmOoBY4LCB7HzC3yFGC7ebtxoQuqpZPZvE2e SEf1qvPoyVJfrql3QaNIZn1LqvKNOaAC6vuztWSg= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id D64FA386103A for ; Thu, 10 Jun 2021 08:27:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D64FA386103A Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-2YYg52EVMDq2IKgP-2XWgg-1; Thu, 10 Jun 2021 04:27:08 -0400 X-MC-Unique: 2YYg52EVMDq2IKgP-2XWgg-1 Received: by mail-wm1-f69.google.com with SMTP id r4-20020a7bc0840000b02901b7cb5713ecso1023908wmh.1 for ; Thu, 10 Jun 2021 01:27:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:organization:date:message-id :user-agent:mime-version; bh=jTPJ52RIXDbr3/0ylU/QIyD8BR3BZGOkpNGUNeoQFd4=; b=c3x2ilGHWM9hUXJE8IutSg0j3VfafOW/taiifYnJpZL9G6I08KCYc/z8C2FfX1kqAZ rcUrA0s6y32HzGEd3PF2uxZK2TU7S71YYvhBle1m/JVYb3t45Dg2OjDecgCcS/U40Viu 7WY2IruMQNF6ZCYD5Pxv7mgxyzQsz10pdA34I2F6cQ1kbF1cfiib7Bo9Ie+2+C1Ivx0w wwDFyyCbNIQBk1zXn3p9yiod42Et9XwuA9+fzTAqLKDcaZqXtaAyiu8R37C293/3daxm bFJbgjkyRmN9EymJlX8D44gCvcmmqOrzRpdv+wq5lAcvThTJTd35x/2xplKCszGxsoJF nDeA== X-Gm-Message-State: AOAM530jO55wrs5VzEB/0H3IAejkh5ztOrt2P/bg1dHjBmk6w4OcA7zr ufrOZpFhLJhl0KVDUXGgP3Svc2tIfaUWZ4oCnEfqNIrWQMv9fKKrGEpAD/T728EnYBS1I0lqe+A 24iik+q6DP4GuIzY6tibcToL2vx9VL2MBpx6RQkOj6ZGlI9fawvU5kVrITxcodrwil6ab X-Received: by 2002:adf:fe4f:: with SMTP id m15mr4146313wrs.361.1623313626704; Thu, 10 Jun 2021 01:27:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh4WHpFn9qR0CyuFjayaOhz6J0uFd625Gwvrj4K+2MuzuUhbg2DUGz78k+OTRrPGj6Y+6HpA== X-Received: by 2002:adf:fe4f:: with SMTP id m15mr4146289wrs.361.1623313626443; Thu, 10 Jun 2021 01:27:06 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id o18sm8718459wmh.38.2021.06.10.01.27.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:27:05 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id C0C065800FF; Thu, 10 Jun 2021 10:27:04 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH, applied] Add environment::{get_type_id_from_pointer,get_canonical_type_from_type_id} Organization: Red Hat / France X-Operating-System: Fedora 35 X-URL: http://www.redhat.com Date: Thu, 10 Jun 2021 10:27:04 +0200 Message-ID: <87zgvy2kh3.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hello, When debugging self comparison issues, once the abixml file is read back into memory, I often want to get the type-id of an artifact that was read from abixml or get the canonical type of an artifact which type-id is known. Part of that information is indirectly present in the data member abigail::reader::reader_context::m_pointer_type_id_map after the .typeid file is loaded from file into memory. The problem is that the instance of abigail::reader::reader_context is transient as it's destroyed quickly after the abixml file is read. We want it to stay alive longer. So this patch moves that data member into abigail::environment instead, along with its accessors. The patch then adds the new member functions environment::{get_type_id_from_pointer,get_canonical_type_from_type_id} to get the type-id of an artifact de-serialized from abixml and the canonical type of an artifact for which we now the type-id string. * include/abg-ir.h (environment::{get_pointer_type_id_map, get_type_id_from_pointer, get_canonical_type_from_type_id}): Declare new member functions. * src/abg-ir.cc (environment::{get_pointer_type_id_map, get_type_id_from_pointer, get_canonical_type_from_type_id}): Define member functions. (environment::priv::pointer_type_id_map_): Move this data member here from ... * src/abg-reader.cc (read_context::m_pointer_type_id_map): ... here. (read_context::get_pointer_type_id_map): Remove this as it's now defined in environment::get_pointer_type_id_map. (read_context::maybe_check_abixml_canonical_type_stability): Adjust. (build_type): Likewise. Signed-off-by: Dodji Seketeli Applied to master. --- include/abg-ir.h | 9 ++++++ src/abg-ir.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++- src/abg-reader.cc | 36 +++++------------------- 3 files changed, 85 insertions(+), 30 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index e0638087..81984d6b 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -222,6 +222,15 @@ public: #ifdef WITH_DEBUG_SELF_COMPARISON unordered_map& get_type_id_canonical_type_map() const; + + unordered_map& + get_pointer_type_id_map(); + + string + get_type_id_from_pointer(uintptr_t ptr); + + uintptr_t + get_canonical_type_from_type_id(const char*); #endif friend class class_or_union; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index bd4c6543..0f909b3d 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -2871,6 +2871,9 @@ struct environment::priv // 'abidw --debug-abidiff '. It holds the set of mapping of // an abixml (canonical) type and its type-id. unordered_map type_id_canonical_type_map_; + // Likewise. It holds a map that associates the pointer to a type read from + // abixml and the type-id string it corresponds to. + unordered_map pointer_type_id_map_; #endif bool canonicalization_is_done_; bool do_on_the_fly_canonicalization_; @@ -3419,8 +3422,73 @@ environment::get_canonical_type(const char* name, unsigned index) unordered_map& environment::get_type_id_canonical_type_map() const {return priv_->type_id_canonical_type_map_;} -#endif +/// Getter of the map that associates the values of type pointers to +/// their type-id strings. +/// +/// Note that this map is populated at abixml reading time, (by +/// build_type()) when a given XML element representing a type is +/// read into a corresponding abigail::ir::type_base. +/// +/// This is used only for the purpose of debugging the +/// self-comparison process. That is, when invoking "abidw +/// --debug-abidiff". +/// +/// @return the map that associates the values of type pointers to +/// their type-id strings. +unordered_map& +environment::get_pointer_type_id_map() +{return priv_->pointer_type_id_map_;} + +/// Getter of the type-id that corresponds to the value of a pointer +/// to abigail::ir::type_base that was created from the abixml reader. +/// +/// That value is retrieved from the map returned from +/// environment::get_pointer_type_id_map(). +/// +/// That map is populated at abixml reading time, (by build_type()) +/// when a given XML element representing a type is read into a +/// corresponding abigail::ir::type_base. +/// +/// This is used only for the purpose of debugging the +/// self-comparison process. That is, when invoking "abidw +/// --debug-abidiff". +/// +/// @return the type-id strings that corresponds +string +environment::get_type_id_from_pointer(uintptr_t ptr) +{ + auto it = get_pointer_type_id_map().find(ptr); + if (it != get_pointer_type_id_map().end()) + return it->second; + return ""; +} + +/// Getter of the canonical type of the artifact designated by a +/// type-id. +/// +/// That type-id was generated by the abixml writer at the emitting +/// time of the abixml file. The corresponding canonical type was +/// stored in the map returned by +/// environment::get_type_id_canonical_type_map(). +/// +/// This is useful for debugging purposes, especially in the context +/// of the use of the command: +/// 'abidw --debug-abidiff '. +/// +/// @return the set of abixml type-id and the pointer value of the +/// (canonical) type it's associated to. +uintptr_t +environment::get_canonical_type_from_type_id(const char* type_id) +{ + if (!type_id) + return 0; + auto it = get_type_id_canonical_type_map().find(type_id); + if (it != get_type_id_canonical_type_map().end()) + return it->second; + return 0; +} +#endif // // diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 34136140..6d25b690 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -99,9 +99,6 @@ private: unordered_map > m_types_map; unordered_map > m_fn_tmpl_map; unordered_map > m_class_tmpl_map; -#ifdef WITH_DEBUG_SELF_COMPARISON - unordered_map m_pointer_type_id_map; -#endif vector m_types_to_canonicalize; string_xml_node_map m_id_xml_node_map; xml_node_decl_base_sptr_map m_xml_node_decl_map; @@ -384,25 +381,6 @@ public: return i->second; } -#ifdef WITH_DEBUG_SELF_COMPARISON - /// Getter of the map that associates the values of type pointers to - /// their type-id strings. - /// - /// Note that this map is populated at abixml reading time, (by - /// build_type()) when a given XML element representing a type is - /// read into a corresponding abigail::ir::type_base. - /// - /// This is used only for the purpose of debugging the - /// self-comparison process. That is, when invoking "abidw - /// --debug-abidiff". - /// - /// @return the map that associates the values of type pointers to - /// their type-id strings. - unordered_map& - get_pointer_type_id_map() - {return m_pointer_type_id_map;} -#endif - /// Return the current lexical scope. scope_decl* get_cur_scope() const @@ -844,12 +822,11 @@ public: // Let's get the type-id of this type as recorded in the // originating abixml file. - string type_id; - const auto i = - get_pointer_type_id_map().find(reinterpret_cast(t.get())); - if (i != get_pointer_type_id_map().end()) + string type_id = + m_env->get_type_id_from_pointer(reinterpret_cast(t.get())); + + if (!type_id.empty()) { - type_id = i->second; // Now let's get the canonical type that initially led to the // serialization of a type with this type-id, when the abixml // was being serialized. @@ -5711,12 +5688,13 @@ build_type(read_context& ctxt, } #ifdef WITH_DEBUG_SELF_COMPARISON - if (t && ctxt.get_environment()->self_comparison_debug_is_on()) + environment *env = ctxt.get_environment(); + if (t && env->self_comparison_debug_is_on()) { string type_id; if (read_type_id_string(node, type_id)) // Let's store the type-id of this type pointer. - ctxt.get_pointer_type_id_map()[reinterpret_cast(t.get())] = type_id; + env->get_pointer_type_id_map()[reinterpret_cast(t.get())] = type_id; } #endif