From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WOxjAk2DTWLSMAAAWB0awg (envelope-from ) for ; Wed, 06 Apr 2022 08:10:53 -0400 Received: by simark.ca (Postfix, from userid 112) id 05DB41F344; Wed, 6 Apr 2022 08:10:53 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2C0831E787 for ; Wed, 6 Apr 2022 08:10:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA1A83857820 for ; Wed, 6 Apr 2022 12:10:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA1A83857820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649247051; bh=gRioYaz4avKnDFGU2CSZURU2Y6TMfAwMIOMy3LqzQd0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=hz9qa3iTEdIP5AK0cb8nuBNOeXqbTysh15tDX/tGopzuxjgRiV0idL3vwSNhWU+GY j0lhTrmH4D4MVtIm81c+Cc7khgOz3BlMxa/l/HaBXJbl2JBFgWvlFX4zB4wxr/y2K3 ANPX3MaP9wmEhD+HuR6zzrMxj+WBI+VqkQRJjL6k= 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 CC1B13857018 for ; Wed, 6 Apr 2022 12:05:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC1B13857018 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-5HMPseuTP_ySf7Ma-AJnuw-1; Wed, 06 Apr 2022 08:05:13 -0400 X-MC-Unique: 5HMPseuTP_ySf7Ma-AJnuw-1 Received: by mail-wm1-f69.google.com with SMTP id x8-20020a7bc768000000b0038e73173886so1223992wmk.6 for ; Wed, 06 Apr 2022 05:05:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gRioYaz4avKnDFGU2CSZURU2Y6TMfAwMIOMy3LqzQd0=; b=IinOeVYJrR22F39sMSvbT9qwvCBaKhMwu3cIS3gJosG/lfojYn/lstmShD6+9v0Atg 4Pzpd33hEgDwQ/shqH0I0DsQk3i+oNIi1VAn7Z7Z/i0pkQrPDer5tgpnZVkfRmSIMKpA 6LDHRV9WliXLUbcqqhOCrVyIHuzi2cvR2V7F5nPciLh6UJSyrIYcJ0UMPNlUMTgcPCFU CVNByGOGpYDFjEypwph+PkKUUZ+MUqx+I4DmwClZyFt3JOvnpdqwgsZJMaB4wUaGmC/5 xl2zIDUdTJWQ217jlcrGh2+Yzcq/ewGLEFua1WJwok3Rwb2N/ocQoRrohrGtDOwUAy5G JRSQ== X-Gm-Message-State: AOAM533xVVah3qf976hExKaCeQ2uxhKuxw+zieolcw+ln2wcWkZA7OX8 j9XxicVgHZI6PWpIOtEYZpxNGdSPA+2uS6MpoH7jqXWPfuARF9CMsyi5iE8syb9TWEAItM9ijyY GWCWdA0WI1rDWWRJ8q/ZT1ZSaVdDeoMRaimJoWDUOo4wcrJSHIVJivoLiUb7qZ/XiN8lLbzCwow == X-Received: by 2002:a05:600c:4401:b0:38c:8df8:9797 with SMTP id u1-20020a05600c440100b0038c8df89797mr7132744wmn.13.1649246712065; Wed, 06 Apr 2022 05:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6xduOdw+JojQGkih3W5yCNQJvcpNu1jxVgglWWFSCbty6hPmjAv1i0YG9TdGBBT6iunLd+g== X-Received: by 2002:a05:600c:4401:b0:38c:8df8:9797 with SMTP id u1-20020a05600c440100b0038c8df89797mr7132720wmn.13.1649246711606; Wed, 06 Apr 2022 05:05:11 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id 61-20020adf8043000000b00205e1d92a41sm15106736wrk.74.2022.04.06.05.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:05:10 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCHv2 10/16] gdb: convert reggroups to use a std::vector Date: Wed, 6 Apr 2022 13:04:43 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Replace manual linked list with a std::vector. This commit doesn't change the reggroup_next and reggroup_prev API, but that will change in a later commit. This commit is focused on the minimal changes needed to manage the reggroups using a std::vector, without changing the API exposed by the reggroup.c file. There should be no user visible changes after this commit. --- gdb/reggroups.c | 153 ++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 78 deletions(-) diff --git a/gdb/reggroups.c b/gdb/reggroups.c index e47a6daf9a0..262bf49cea8 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -74,35 +74,46 @@ reggroup_type (const struct reggroup *group) return group->type; } -/* A linked list of groups for the given architecture. */ - -struct reggroup_el -{ - struct reggroup *group; - struct reggroup_el *next; -}; +/* A container holding all the register groups for a particular + architecture. */ struct reggroups { - struct reggroup_el *first; - struct reggroup_el **last; + /* Add GROUP to the list of register groups. */ + + void add (struct reggroup *group) + { + gdb_assert (group != nullptr); + gdb_assert (std::find (m_groups.begin(), m_groups.end(), group) + == m_groups.end()); + + m_groups.push_back (group); + } + + /* The number of register groups. */ + + std::vector::size_type + size () const + { + return m_groups.size (); + } + + /* Return a reference to the list of all groups. */ + + const std::vector & + groups () const + { + return m_groups; + } + +private: + /* The register groups. */ + std::vector m_groups; }; static struct gdbarch_data *reggroups_data; -/* Add a register group (with attribute values) to the pre-defined - list. */ - -static void -add_group (struct reggroups *groups, struct reggroup *group, - struct reggroup_el *el) -{ - gdb_assert (group != NULL); - el->group = group; - el->next = NULL; - (*groups->last) = el; - groups->last = &el->next; -} +/* Add GROUP to the list of register groups for GDBARCH. */ void reggroup_add (struct gdbarch *gdbarch, struct reggroup *group) @@ -110,15 +121,10 @@ reggroup_add (struct gdbarch *gdbarch, struct reggroup *group) struct reggroups *groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data); - /* The same reggroup should not be added multiple times. */ gdb_assert (groups != nullptr); - for (struct reggroup_el *el = groups->first; - el != nullptr; - el = el->next) - gdb_assert (group != el->group); + gdb_assert (group != nullptr); - add_group (groups, group, - GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el)); + groups->add (group); } /* Called to initialize the per-gdbarch register group information. */ @@ -126,25 +132,16 @@ reggroup_add (struct gdbarch *gdbarch, struct reggroup *group) static void * reggroups_init (struct obstack *obstack) { - struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups); - - groups->last = &groups->first; + struct reggroups *groups = obstack_new (obstack); /* Add the default groups. */ - add_group (groups, general_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, float_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, system_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, vector_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, all_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, save_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); - add_group (groups, restore_reggroup, - OBSTACK_ZALLOC (obstack, struct reggroup_el)); + groups->add (general_reggroup); + groups->add (float_reggroup); + groups->add (system_reggroup); + groups->add (vector_reggroup); + groups->add (all_reggroup); + groups->add (save_reggroup); + groups->add (restore_reggroup); return groups; } @@ -154,29 +151,28 @@ reggroups_init (struct obstack *obstack) struct reggroup * reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last) { - struct reggroups *groups; - struct reggroup_el *el; - /* Don't allow this function to be called during architecture creation. If there are no groups, use the default groups list. */ - groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data); - gdb_assert (groups != NULL); - gdb_assert (groups->first != NULL); + struct reggroups *groups + = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data); + gdb_assert (groups != nullptr); + gdb_assert (groups->size () > 0); /* Return the first/next reggroup. */ - if (last == NULL) - return groups->first->group; - for (el = groups->first; el != NULL; el = el->next) + if (last == nullptr) + return groups->groups ().front (); + for (int i = 0; i < groups->size (); ++i) { - if (el->group == last) + if (groups->groups ()[i] == last) { - if (el->next != NULL) - return el->next->group; + if (i + 1 < groups->size ()) + return groups->groups ()[i + 1]; else - return NULL; + return nullptr; } } - return NULL; + + return nullptr; } /* See reggroups.h. */ @@ -184,27 +180,28 @@ reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last) struct reggroup * reggroup_prev (struct gdbarch *gdbarch, const struct reggroup *curr) { - struct reggroups *groups; - struct reggroup_el *el; - struct reggroup *prev; - /* Don't allow this function to be called during architecture creation. If there are no groups, use the default groups list. */ - groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data); - gdb_assert (groups != NULL); - gdb_assert (groups->first != NULL); + struct reggroups *groups + = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data); + gdb_assert (groups != nullptr); + gdb_assert (groups->size () > 0); - prev = NULL; - for (el = groups->first; el != NULL; el = el->next) + /* Return the first/next reggroup. */ + if (curr == nullptr) + return groups->groups ().back (); + for (int i = groups->size () - 1; i >= 0; --i) { - gdb_assert (el->group != NULL); - if (el->group == curr) - return prev; - prev = el->group; + if (groups->groups ()[i] == curr) + { + if (i - 1 >= 0) + return groups->groups ()[i - 1]; + else + return nullptr; + } } - if (curr == NULL) - return prev; - return NULL; + + return nullptr; } /* Is REGNUM a member of REGGROUP? */ @@ -234,7 +231,7 @@ default_register_reggroup_p (struct gdbarch *gdbarch, int regnum, return (!vector_p && !float_p); if (group == save_reggroup || group == restore_reggroup) return raw_p; - return 0; + return 0; } /* See reggroups.h. */ @@ -273,7 +270,7 @@ reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file) name = reggroup_name (group); gdb_printf (file, " %-10s", name); } - + /* Group type. */ { const char *type; -- 2.25.4