From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id 548DB3858D32 for ; Sun, 29 Jan 2023 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 548DB3858D32 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 cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway3.mail.pro1.eigbox.com (Postfix) with ESMTP id 1BDC510048C18 for ; Sun, 29 Jan 2023 16:21:23 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQlpaT5qIqHFMAQlpN8bp; Sun, 29 Jan 2023 16:21:23 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=d/AwdTvE c=1 sm=1 tr=0 ts=63d69d03 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=RvmDmJFTN0MA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=6tKk0tt6NCz1M0evsr4A:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: 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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=7NCZSvPa6O1o5XwyBJuE8i3hMxf9nB0lzxI0Xbs9EH8=; b=GF4rM9+kVGi23THV3HeWexDTEi 72q/FTeEIPJRwAVWzePiy5oAAL81I0xIn5TktB0RnzkCNi4mSdykSugoG3LRX7c3zyYqQOhKS1+/V Ea4NIkqxMTIfw5p2iPZY+KsML; Received: from 75-166-146-144.hlrn.qwest.net ([75.166.146.144]:59376 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pMAQk-001fCo-Sb; Sun, 29 Jan 2023 09:21:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/5] Add "save skip" command Date: Sun, 29 Jan 2023 09:21:04 -0700 Message-Id: <20230129162105.526266-5-tom@tromey.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230129162105.526266-1-tom@tromey.com> References: <20230129162105.526266-1-tom@tromey.com> 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: 75.166.146.144 X-Source-L: No X-Exim-ID: 1pMAQk-001fCo-Sb X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-146-144.hlrn.qwest.net (localhost.localdomain) [75.166.146.144]:59376 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.5 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: PR cli/17997 points out that it would sometimes be convenient to save the current "skip"s to a file. This patch implements this feature. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17997 --- gdb/NEWS | 3 ++ gdb/doc/gdb.texinfo | 6 +++ gdb/skip.c | 78 +++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/skip.exp | 12 +++++ 4 files changed, 99 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 3b7d768732c..a5b6f8df2ff 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -17,6 +17,9 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +save skip FILENAME + Save all current "skip"s to the given file. + save user FILENAME Save all user-defined commands to the given file. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 37db4785fd2..31f73c33894 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -6707,6 +6707,12 @@ Set whether to print the debug output about skipping files and functions. @item show debug skip Show whether the debug output about skipping files and functions is printed. +@kindex save skip +@item save skip @var{filename} +Save all skips to the file @var{filename}. This command writes out +the skips as a script that can be re-read into @value{GDBN} using the +@code{source} command. + @end table @node Signals diff --git a/gdb/skip.c b/gdb/skip.c index f3b1bec9e4c..5f98df803f9 100644 --- a/gdb/skip.c +++ b/gdb/skip.c @@ -38,6 +38,8 @@ #include #include "cli/cli-style.h" #include "gdbsupport/buildargv.h" +#include "safe-ctype.h" +#include "readline/tilde.h" /* True if we want to print debug printouts related to file/function skipping. */ @@ -76,6 +78,9 @@ class skiplist_entry skiplist_entry (const skiplist_entry &) = delete; void operator= (const skiplist_entry &) = delete; + /* Print a gdb command that can be used to recreate this skip. */ + void print_recreate (ui_file *stream) const; + private: /* Key that grants access to the constructor. */ struct private_key {}; @@ -160,6 +165,54 @@ skiplist_entry::add_entry (bool file_is_glob, std::string &&file, skiplist_entries.back ().m_number = ++highest_skiplist_entry_num; } +/* A helper function for print_recreate that prints a correctly-quoted + string to STREAM. */ + +static void +print_quoted (ui_file *stream, const std::string &str) +{ + gdb_putc ('"', stream); + for (char c : str) + { + if (ISSPACE (c) || c == '\\' || c == '\'' || c == '"') + gdb_putc ('\\', stream); + gdb_putc (c, stream); + } + gdb_putc ('"', stream); +} + +void +skiplist_entry::print_recreate (ui_file *stream) const +{ + if (!m_file_is_glob && !m_file.empty () + && !m_function_is_regexp && m_function.empty ()) + gdb_printf (stream, "skip file %s\n", m_file.c_str ()); + else if (!m_file_is_glob && m_file.empty () + && !m_function_is_regexp && !m_function.empty ()) + gdb_printf (stream, "skip function %s\n", m_function.c_str ()); + else + { + gdb_printf (stream, "skip "); + if (!m_file.empty ()) + { + if (m_file_is_glob) + gdb_printf (stream, "-gfile "); + else + gdb_printf (stream, "-file "); + print_quoted (stream, m_file); + } + if (!m_function.empty ()) + { + if (m_function_is_regexp) + gdb_printf (stream, "-rfunction "); + else + gdb_printf (stream, "-function "); + print_quoted (stream, m_function); + } + gdb_printf (stream, "\n"); + } +} + static void skip_file_command (const char *arg, int from_tty) { @@ -657,6 +710,24 @@ complete_skip_number (cmd_list_element *cmd, } } +/* Implementation of 'save skip' command. */ + +static void +save_skip_command (const char *filename, int from_tty) +{ + if (filename == nullptr || *filename == '\0') + error (_("Argument required (file name in which to save)")); + + gdb::unique_xmalloc_ptr expanded_filename (tilde_expand (filename)); + stdio_file fp; + if (!fp.open (expanded_filename.get (), "w")) + error (_("Unable to open file '%s' for saving (%s)"), + expanded_filename.get (), safe_strerror (errno)); + + for (const auto &entry : skiplist_entries) + entry.print_recreate (&fp); +} + void _initialize_step_skip (); void _initialize_step_skip () @@ -737,4 +808,11 @@ Show whether the debug output about skipping files and functions is printed."), When non-zero, debug output about skipping files and functions is displayed."), NULL, NULL, &setdebuglist, &showdebuglist); + + c = add_cmd ("skip", no_class, save_skip_command, _("\ +Save current skips as a script.\n\ +Usage: save skip FILE\n\ +Use the 'source' command in another debug session to restore them."), + &save_cmdlist); + set_cmd_completer (c, filename_completer); } diff --git a/gdb/testsuite/gdb.base/skip.exp b/gdb/testsuite/gdb.base/skip.exp index 41c811b9769..4b4e890ea21 100644 --- a/gdb/testsuite/gdb.base/skip.exp +++ b/gdb/testsuite/gdb.base/skip.exp @@ -206,6 +206,9 @@ with_test_prefix "admin" { "4\\s+y\\s+n\\s+\\s+n\\s+baz"] \ "info skip after enabling all" + gdb_test_no_output "save skip [standard_output_file skips]" \ + "save skips to file" + gdb_test "skip disable 4 2-3" gdb_test "info skip" \ [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \ @@ -337,3 +340,12 @@ with_test_prefix "skip delete completion" { test_gdb_complete_none "skip delete 2-33" } +clean_restart +gdb_test "source [standard_output_file skips]" "" \ + "re-read saved skips" +gdb_test "info skip" \ + [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \ + "1\\s+y\\s+n\\s+\\s+n\\s+main" \ + "2\\s+y\\s+n\\s+$srcfile1\\s+n\\s+" \ + "3\\s+y\\s+n\\s+\\s+n\\s+baz"] \ + "info skip after re-reading" -- 2.39.1