From patchwork Wed Apr 26 12:11:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 68300 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 006FE385840F for ; Wed, 26 Apr 2023 12:12:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 006FE385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682511138; bh=eK8W6BdncQAVU1GjXmaYZfhn/KM/VgRG0a5ZIA8KRCI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=WwhWxhLgFK/NA1KZBENYo42PsFd3wcmQ3YVxu6t8/gxc11ZsLtXn8r45ingwgunNr LnLJ0TuS+MNtOr2GKfZIva97c38xKeY1pR7KrENE3F3d0JJBubO8GUwbPj+iQsuahc 0U6id5S9qbuSN1onqMtkNSMV4H9kFw6ykRWdXF34= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2257E3858C2C for ; Wed, 26 Apr 2023 12:11:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2257E3858C2C Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-MQ0qDerFMtO6HALi_TQCGQ-1; Wed, 26 Apr 2023 08:11:41 -0400 X-MC-Unique: MQ0qDerFMtO6HALi_TQCGQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f0a65d5a1dso37212361cf.2 for ; Wed, 26 Apr 2023 05:11:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682511101; x=1685103101; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eK8W6BdncQAVU1GjXmaYZfhn/KM/VgRG0a5ZIA8KRCI=; b=eL1aT1TH+Jsn4Oe8BFRE6NPEHzW+QbYx0TAGzfst9dmp1QdUDMK6WLyaqKpzfMV9RZ 5TqE8grpqk7ZJsvBMOs5FExj0Hl0IYV5tW70VSaheL9wJCTtXY1p3VDNmT2vcWKgSZpC PYsym0nxiyp4rVn3mBxChSLsnQTajvGfLltqZBR7eZ4kl+C3pDC55G+nplpC9kasbWgm D2UNDgdYAtSOZdN3goYteIER0NYhYNBIKhxYpYpu+tqmApvP9roYyv1kbBRe7TNpFNxp CLi8qCvbXyd/FoZpgMqvTOvdDVcVND2lVKjG5W5NHUaa7UVRG8623RtRoX1EvRtvrPtm vYTg== X-Gm-Message-State: AAQBX9fiIbbBAsMsyu7NOWSs1Ge+EXFCVMFaUA+pT9PVf03FfmQ01Tdo xvWCtiRlyAF1iuBtD6xKLIXV4oRZvePABU0uKraCfp/zmfiuLG9HVkuun/JjO+XbNO4rS6LItvO zh/MNFWR/TfXQBUmHxQ+92Nt31i9+u8eARwg5LNjJFnkM1wEKqoJlpOjy916oF6x8c7/AlP/AF6 fc X-Received: by 2002:a05:622a:1747:b0:3bf:d8b6:4ca1 with SMTP id l7-20020a05622a174700b003bfd8b64ca1mr33779834qtk.28.1682511100804; Wed, 26 Apr 2023 05:11:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ZlMNb6AkNv2+evU+l0WpsZa4j8Tc6ah832i5DVRe/D1uRTT7USVRtgZpJdWPsTJdHfNCmj7Q== X-Received: by 2002:a05:622a:1747:b0:3bf:d8b6:4ca1 with SMTP id l7-20020a05622a174700b003bfd8b64ca1mr33779789qtk.28.1682511100363; Wed, 26 Apr 2023 05:11:40 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id z26-20020ac87cba000000b003eb136bec50sm5215655qtv.66.2023.04.26.05.11.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 05:11:39 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id DAEF6B5078; Wed, 26 Apr 2023 14:11:37 +0200 (CEST) To: libabigail@sourceware.org Subject: [PATCH, applied] ir: Improve debugging type_base::get_canonical_type_for Organization: Red Hat / France X-Operating-System: CentOS Stream release 9 X-URL: http://www.redhat.com Date: Wed, 26 Apr 2023 14:11:37 +0200 Message-ID: <87a5yu972e.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, This patch factorizes an interesting part of type_base::get_canonical_type_for into a new function called compare_canonical_type_against_candidate. The user can now invoke it from the prompt of the debugger to compare a candidate canonical type against an actual canonical to study why the comparison fails (by setting a breakpoint in notify_equality_failed when the pre-processor macro WITH_DEBUG_SELF_COMPARISON is defined. This is priceless to debug why canonical type comparison that should succeed actually fails. * src/abg-ir.cc (compare_types_during_canonicalization): Adjust this to make it take const type_base& rather than const type_base_sptr. (compare_canonical_type_against_candidate): Factorize this out of ... (type_base::get_canonical_type_for): ... here. Signed-off-by: Dodji Seketeli --- src/abg-ir.cc | 160 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 124 insertions(+), 36 deletions(-) diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 087baacb..67f1a6bc 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -14395,11 +14395,11 @@ types_defined_same_linux_kernel_corpus_public(const type_base& t1, /// @return true iff @p canonical_type equals @p candidate_type. /// static bool -compare_types_during_canonicalization(const type_base_sptr& canonical_type, - const type_base_sptr& candidate_type) +compare_types_during_canonicalization(const type_base& canonical_type, + const type_base& candidate_type) { #ifdef WITH_DEBUG_TYPE_CANONICALIZATION - const environment&env = canonical_type->get_environment(); + const environment& env = canonical_type.get_environment(); if (env.debug_type_canonicalization_is_on()) { bool canonical_equality = false, structural_equality = false; @@ -14410,7 +14410,7 @@ compare_types_during_canonicalization(const type_base_sptr& canonical_type, if (canonical_equality != structural_equality) { std::cerr << "structural & canonical equality different for type: " - << canonical_type->get_pretty_representation(true, true) + << canonical_type.get_pretty_representation(true, true) << std::endl; ABG_ASSERT_NOT_REACHED; } @@ -14420,6 +14420,125 @@ compare_types_during_canonicalization(const type_base_sptr& canonical_type, return canonical_type == candidate_type; } +/// Compare a canonical type against a candidate canonical type. +/// +/// This is ultimately a sub-routine of the +/// type_base::get_canonical_type_for(). +/// +/// The goal of this function is to ease debugging because it can be +/// called from within type_base::get_canonical_type_for() from the +/// prompt of the debugger (with some breakpoint appropriately set) to +/// debug the comparison that happens during type canonicalization, +/// between a candidate type being canonicalized, and an existing +/// canonical type that is registered in the system, in as returned by +/// environment::get_canonical_types() +/// +/// @param canonical_type the canonical type to consider. +/// +/// @param candidate_type the candidate type that is being +/// canonicalized, and thus compared to @p canonical_type. +/// +/// @return true iff @p canonical_type compares equal to @p +/// candidate_type. +static bool +compare_canonical_type_against_candidate(const type_base& canonical_type, + const type_base& candidate_type) +{ + environment& env = const_cast(canonical_type.get_environment()); + + // Before the "*it == it" comparison below is done, let's + // perform on-the-fly-canonicalization. For C types, let's + // consider that an unresolved struct declaration 'struct S' + // is different from a definition 'struct S'. This is + // because normally, at this point all the declarations of + // struct S that are compatible with the definition of + // struct S have already been resolved to that definition, + // during the DWARF parsing. The remaining unresolved + // declaration are thus considered different. With this + // setup we can properly handle cases of two *different* + // struct S being defined in the same binary (in different + // translation units), and a third struct S being only + // declared as an opaque type in a third translation unit of + // its own, with no definition in there. In that case, the + // declaration-only struct S should be left alone and not + // resolved to any of the two definitions of struct S. + bool saved_decl_only_class_equals_definition = + env.decl_only_class_equals_definition(); + env.do_on_the_fly_canonicalization(true); + // Compare types by considering that decl-only classes don't + // equal their definition. + env.decl_only_class_equals_definition(false); + env.priv_->allow_type_comparison_results_caching(true); + bool equal = (types_defined_same_linux_kernel_corpus_public(canonical_type, + candidate_type) + || compare_types_during_canonicalization(canonical_type, + candidate_type)); + // Restore the state of the on-the-fly-canonicalization and + // the decl-only-class-being-equal-to-a-matching-definition + // flags. + env.priv_->allow_type_comparison_results_caching(false); + env.do_on_the_fly_canonicalization(false); + env.decl_only_class_equals_definition + (saved_decl_only_class_equals_definition); + return equal; +} + +/// Compare a canonical type against a candidate canonical type. +/// +/// This is ultimately a sub-routine of the +/// type_base::get_canonical_type_for(). +/// +/// The goal of this function is to ease debugging because it can be +/// called from within type_base::get_canonical_type_for() from the +/// prompt of the debugger (with some breakpoint appropriately set) to +/// debug the comparison that happens during type canonicalization, +/// between a candidate type being canonicalized, and an existing +/// canonical type that is registered in the system, in as returned by +/// environment::get_canonical_types() +/// +/// @param canonical_type the canonical type to consider. +/// +/// @param candidate_type the candidate type that is being +/// canonicalized, and thus compared to @p canonical_type. +/// +/// @return true iff @p canonical_type compares equal to @p +/// candidate_type. +static bool +compare_canonical_type_against_candidate(const type_base* canonical_type, + const type_base* candidate_type) +{ + return compare_canonical_type_against_candidate(*canonical_type, + *candidate_type); +} + +/// Compare a canonical type against a candidate canonical type. +/// +/// This is ultimately a sub-routine of the +/// type_base::get_canonical_type_for(). +/// +/// The goal of this function is to ease debugging because it can be +/// called from within type_base::get_canonical_type_for() from the +/// prompt of the debugger (with some breakpoint appropriately set) to +/// debug the comparison that happens during type canonicalization, +/// between a candidate type being canonicalized, and an existing +/// canonical type that is registered in the system, in as returned by +/// environment::get_canonical_types() +/// +/// @param canonical_type the canonical type to consider. +/// +/// @param candidate_type the candidate type that is being +/// canonicalized, and thus compared to @p canonical_type. +/// +/// @return true iff @p canonical_type compares equal to @p +/// candidate_type. +static bool +compare_canonical_type_against_candidate(const type_base_sptr& canonical_type, + const type_base_sptr& candidate_type) +{ + return compare_canonical_type_against_candidate(canonical_type.get(), + candidate_type.get()); +} + /// Compute the canonical type for a given instance of @ref type_base. /// /// Consider two types T and T'. The canonical type of T, denoted @@ -14530,38 +14649,7 @@ type_base::get_canonical_type_for(type_base_sptr t) it != v.rend(); ++it) { - // Before the "*it == it" comparison below is done, let's - // perform on-the-fly-canonicalization. For C types, let's - // consider that an unresolved struct declaration 'struct S' - // is different from a definition 'struct S'. This is - // because normally, at this point all the declarations of - // struct S that are compatible with the definition of - // struct S have already been resolved to that definition, - // during the DWARF parsing. The remaining unresolved - // declaration are thus considered different. With this - // setup we can properly handle cases of two *different* - // struct S being defined in the same binary (in different - // translation units), and a third struct S being only - // declared as an opaque type in a third translation unit of - // its own, with no definition in there. In that case, the - // declaration-only struct S should be left alone and not - // resolved to any of the two definitions of struct S. - bool saved_decl_only_class_equals_definition = - env.decl_only_class_equals_definition(); - env.do_on_the_fly_canonicalization(true); - // Compare types by considering that decl-only classes don't - // equal their definition. - env.decl_only_class_equals_definition(false); - env.priv_->allow_type_comparison_results_caching(true); - bool equal = (types_defined_same_linux_kernel_corpus_public(**it, *t) - || compare_types_during_canonicalization(*it, t)); - // Restore the state of the on-the-fly-canonicalization and - // the decl-only-class-being-equal-to-a-matching-definition - // flags. - env.priv_->allow_type_comparison_results_caching(false); - env.do_on_the_fly_canonicalization(false); - env.decl_only_class_equals_definition - (saved_decl_only_class_equals_definition); + bool equal = compare_canonical_type_against_candidate(*it, t); if (equal) { result = *it;