From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 880AA3858C2F for ; Mon, 15 Aug 2022 23:10:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 880AA3858C2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 24BB410048555 for ; Mon, 15 Aug 2022 23:10:31 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id NjE6omAfkG7RFNjE6o7jnd; Mon, 15 Aug 2022 23:10:31 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=EscXEQQA c=1 sm=1 tr=0 ts=62fad267 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=biHskzXt2R4A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=87nVPqrEVjfPlE3DYKgA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=b1Mvb3HcOyG5wh84J3IxmdTsrJJEb/jKYTSK8/rY2s8=; b=EnJBI27WzaPyeUKJ2fA/wKswFW jtAf/Z6wctJwOOfgPJtJLnVx1qZeTI0AuyWT69SMQqCYWJsNOoiCQRhZvq2U3NILiHW87KifORWeg mKN0OtfzGShWbDOqchLgkFfN+; Received: from 71-211-185-228.hlrn.qwest.net ([71.211.185.228]:45804 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oNjE6-003Lki-8U; Mon, 15 Aug 2022 17:10:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Change bookmark allocation Date: Mon, 15 Aug 2022 17:10:28 -0600 Message-Id: <20220815231028.352098-1-tom@tromey.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.185.228 X-Source-L: No X-Exim-ID: 1oNjE6-003Lki-8U X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-185-228.hlrn.qwest.net (prentzel.Home) [71.211.185.228]:45804 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3029.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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: 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: , X-List-Received-Date: Mon, 15 Aug 2022 23:10:47 -0000 This changes how bookmarks are allocated and stored, replacing a linked list with a vector and removing some ALL_* iterator macros. Regression tested on x86-64 Fedora 34. --- gdb/reverse.c | 137 +++++++++++++++++--------------------------------- 1 file changed, 46 insertions(+), 91 deletions(-) diff --git a/gdb/reverse.c b/gdb/reverse.c index dc417497b7a..fc94b8d1825 100644 --- a/gdb/reverse.c +++ b/gdb/reverse.c @@ -92,23 +92,15 @@ reverse_finish (const char *args, int from_tty) /* Data structures for a bookmark list. */ struct bookmark { - struct bookmark *next; - int number; - CORE_ADDR pc; - struct symtab_and_line sal; - gdb_byte *opaque_data; + int number = 0; + CORE_ADDR pc = 0; + struct symtab_and_line sal {}; + gdb::unique_xmalloc_ptr opaque_data; }; -static struct bookmark *bookmark_chain; +static std::vector all_bookmarks; static int bookmark_count; -#define ALL_BOOKMARKS(B) for ((B) = bookmark_chain; (B); (B) = (B)->next) - -#define ALL_BOOKMARKS_SAFE(B,TMP) \ - for ((B) = bookmark_chain; \ - (B) ? ((TMP) = (B)->next, 1) : 0; \ - (B) = (TMP)) - /* save_bookmark_command -- implement "bookmark" command. Call target method to get a bookmark identifier. Insert bookmark identifier into list. @@ -130,80 +122,46 @@ save_bookmark_command (const char *args, int from_tty) error (_("target_get_bookmark failed.")); /* Set up a bookmark struct. */ - bookmark *b = new bookmark (); - b->number = ++bookmark_count; - b->pc = regcache_read_pc (get_current_regcache ()); - b->sal = find_pc_line (b->pc, 0); - b->sal.pspace = get_frame_program_space (get_current_frame ()); - b->opaque_data = bookmark_id; - b->next = NULL; - - /* Add this bookmark to the end of the chain, so that a list - of bookmarks will come out in order of increasing numbers. */ - - bookmark *b1 = bookmark_chain; - if (b1 == 0) - bookmark_chain = b; - else - { - while (b1->next) - b1 = b1->next; - b1->next = b; - } - gdb_printf (_("Saved bookmark %d at %s\n"), b->number, - paddress (gdbarch, b->sal.pc)); + bookmark &b = all_bookmarks.emplace_back (); + b.number = ++bookmark_count; + b.pc = regcache_read_pc (get_current_regcache ()); + b.sal = find_pc_line (b.pc, 0); + b.sal.pspace = get_frame_program_space (get_current_frame ()); + b.opaque_data.reset (bookmark_id); + + gdb_printf (_("Saved bookmark %d at %s\n"), b.number, + paddress (gdbarch, b.sal.pc)); } /* Implement "delete bookmark" command. */ -static int +static bool delete_one_bookmark (int num) { - struct bookmark *b1, *b; - /* Find bookmark with corresponding number. */ - ALL_BOOKMARKS (b) - if (b->number == num) - break; - - /* Special case, first item in list. */ - if (b == bookmark_chain) - bookmark_chain = b->next; - - /* Find bookmark preceding "marked" one, so we can unlink. */ - if (b) + for (auto iter = all_bookmarks.begin (); + iter != all_bookmarks.end (); + ++iter) { - ALL_BOOKMARKS (b1) - if (b1->next == b) - { - /* Found designated bookmark. Unlink and delete. */ - b1->next = b->next; - break; - } - xfree (b->opaque_data); - delete b; - return 1; /* success */ + if (iter->number == num) + { + all_bookmarks.erase (iter); + return true; + } } - return 0; /* failure */ + return false; } static void -delete_all_bookmarks (void) +delete_all_bookmarks () { - struct bookmark *b, *b1; - - ALL_BOOKMARKS_SAFE (b, b1) - { - xfree (b->opaque_data); - xfree (b); - } - bookmark_chain = NULL; + all_bookmarks.clear (); } static void delete_bookmark_command (const char *args, int from_tty) { - if (bookmark_chain == NULL) + if (all_bookmarks.empty ()) { warning (_("No bookmarks.")); return; @@ -232,7 +190,6 @@ delete_bookmark_command (const char *args, int from_tty) static void goto_bookmark_command (const char *args, int from_tty) { - struct bookmark *b; unsigned long num; const char *p = args; @@ -263,15 +220,14 @@ goto_bookmark_command (const char *args, int from_tty) if (num == 0) error (_("goto-bookmark: invalid bookmark number '%s'."), p); - ALL_BOOKMARKS (b) - if (b->number == num) - break; - - if (b) + for (const bookmark &iter : all_bookmarks) { - /* Found. Send to target method. */ - target_goto_bookmark (b->opaque_data, from_tty); - return; + if (iter.number == num) + { + /* Found. Send to target method. */ + target_goto_bookmark (iter.opaque_data.get (), from_tty); + return; + } } /* Not found. */ error (_("goto-bookmark: no bookmark found for '%s'."), p); @@ -281,20 +237,19 @@ static int bookmark_1 (int bnum) { struct gdbarch *gdbarch = get_current_regcache ()->arch (); - struct bookmark *b; int matched = 0; - ALL_BOOKMARKS (b) - { - if (bnum == -1 || bnum == b->number) - { - gdb_printf (" %d %s '%s'\n", - b->number, - paddress (gdbarch, b->pc), - b->opaque_data); - matched++; - } - } + for (const bookmark &iter : all_bookmarks) + { + if (bnum == -1 || bnum == iter.number) + { + gdb_printf (" %d %s '%s'\n", + iter.number, + paddress (gdbarch, iter.pc), + iter.opaque_data.get ()); + matched++; + } + } if (bnum > 0 && matched == 0) gdb_printf ("No bookmark #%d\n", bnum); @@ -307,7 +262,7 @@ bookmark_1 (int bnum) static void info_bookmarks_command (const char *args, int from_tty) { - if (!bookmark_chain) + if (all_bookmarks.empty ()) gdb_printf (_("No bookmarks.\n")); else if (args == NULL || *args == '\0') bookmark_1 (-1); -- 2.34.1