From patchwork Sun Jan 29 16:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63877 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 D43DB385B531 for ; Sun, 29 Jan 2023 16:21:41 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id AEA463858D35 for ; Sun, 29 Jan 2023 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEA463858D35 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 C451E10048C1E for ; Sun, 29 Jan 2023 16:21:22 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQkpaT5WIqHFMAQkpN8bV; Sun, 29 Jan 2023 16:21:22 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=d/AwdTvE c=1 sm=1 tr=0 ts=63d69d02 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=peyYD-nQKP5d7ILD754A: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=JWofi/NUWRUdPlj2J+o47EN7N1/7KFvyAgmPCNg6fps=; b=yjaFk7heUh3ENkauWn1OnXprpi D/lgeXURT9pk13lzBvCfEX6TtEvqx9BRQaqrOg3C9RFKRaXjsThump5JhcWG4NAAgLhLgSraei1DS jgXSWFdWAS3DpEC1l8oATykfZ; 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-C1; Sun, 29 Jan 2023 09:21:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/5] Save breakpoints so they are automatically pending Date: Sun, 29 Jan 2023 09:21:01 -0700 Message-Id: <20230129162105.526266-2-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 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-C1 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: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.4 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 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" PR breakpoints/18183 points out that breakpoints saved with the "save breakpoints" command can be slightly inconvenient, depending on "set breakpoint pending". This patch makes use of the new "with" command to save breakpoints such that they will automatically be made pending, if necessary, when being restored. Unfortunately, reloading a breakpoint saved this way will also print: No symbol table is loaded. Use the "file" command. This seems strange to me, and also a bit useless, but changing create_breakpoint not to call exception_print in the AUTO_BOOLEAN_TRUE case caused other regressions, so I've left it as-is for the time being. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18183 --- gdb/breakpoint.c | 1 + gdb/testsuite/gdb.base/catch-signal.exp | 10 +++++----- gdb/testsuite/gdb.base/save-bp.exp | 20 ++++++++++++++++++++ gdb/testsuite/gdb.base/ui-redirect.exp | 7 ++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 00cc2ab401c..bd11d26fca4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -14170,6 +14170,7 @@ save_breakpoints (const char *filename, int from_tty, if (filter && !filter (tp)) continue; + fp.puts ("with breakpoint pending on -- "); tp->print_recreate (&fp); /* Note, we can't rely on tp->number for anything, as we can't diff --git a/gdb/testsuite/gdb.base/catch-signal.exp b/gdb/testsuite/gdb.base/catch-signal.exp index 774eb8ee856..2e3160c2a33 100644 --- a/gdb/testsuite/gdb.base/catch-signal.exp +++ b/gdb/testsuite/gdb.base/catch-signal.exp @@ -128,10 +128,10 @@ foreach {arg desc} {"" "standard signals" \ set data [split $file_data "\n"] close $fd - if {$arg == ""} { - set pattern "catch signal" - } else { - set pattern "catch signal $arg" + set prefix "with breakpoint pending on -- " + set pattern "${prefix}catch signal" + if {$arg != ""} { + append pattern " $arg" } gdb_assert {[expr [llength $data] == 3]} \ "Number of lines of save breakpoints for '$arg'" @@ -139,7 +139,7 @@ foreach {arg desc} {"" "standard signals" \ gdb_assert {[string match $pattern [lindex $data 0]]} \ "1st line of save breakpoints for '$arg'" # Check the second line. - gdb_assert {[string match "break main" [lindex $data 1]]} \ + gdb_assert {[string match "${prefix}break main" [lindex $data 1]]} \ "2nd line of save breakpoints for '$arg'" # Check the trailing newline. gdb_assert {[string match "" [lindex $data 2]]} \ diff --git a/gdb/testsuite/gdb.base/save-bp.exp b/gdb/testsuite/gdb.base/save-bp.exp index a39712c7f5c..daa7509ae8e 100644 --- a/gdb/testsuite/gdb.base/save-bp.exp +++ b/gdb/testsuite/gdb.base/save-bp.exp @@ -89,3 +89,23 @@ gdb_test_sequence "info break" "info break" [list \ "\[\r\n\]+\[ \t\]+printf" \ "\[\r\n\]+$disabled_row_start main at \[^\r\n\]*$srcfile:$loc_bp8" \ ] + +clean_restart +gdb_test "source $bps" "" "source bps without symbol file" + +set pending "\[0-9\]+ +breakpoint +keep +y + +" +set disabled_pending "\[0-9\]+ +breakpoint +keep +n + +" +set dprintf_pending "\[0-9\]+ +dprintf +keep +y + +" +gdb_test_sequence "info break" "info break without symbol file" \ + [list \ + "\[\r\n\]+Num +Type +Disp +Enb +Address +What" \ + "\[\r\n\]+$pending break_me" \ + "\[\r\n\]+$pending $srcfile:$loc_bp2" \ + "\[\r\n\]+$pending $srcfile:$loc_bp3 +thread 1" \ + "\[\r\n\]+$pending $srcfile:$loc_bp4" \ + "\[\r\n\]+\[ \t\]+stop only if i == 1( \\((host|target) evals\\))?" \ + "\[\r\n\]+$pending $srcfile:$loc_bp5" \ + "\[\r\n\]+\[ \t\]+silent" \ + "\[\r\n\]+$dprintf_pending $srcfile:$loc_bp5," \ + "\[\r\n\]+$disabled_pending $srcfile:$loc_bp8" \ + ] diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp index c0ba4f11809..a95e4fa6e90 100644 --- a/gdb/testsuite/gdb.base/ui-redirect.exp +++ b/gdb/testsuite/gdb.base/ui-redirect.exp @@ -42,13 +42,14 @@ gdb_test_no_output "end" gdb_breakpoint "foo" gdb_breakpoint "bar" +set prefix "with breakpoint pending on -- " set cmds [multi_line_input \ - "break -qualified main" \ + "${prefix}break -qualified main" \ " commands" \ " print 1" \ " end" \ - "break foo" \ - "break bar"] + "${prefix}break foo" \ + "${prefix}break bar"] set cmds "$cmds\n" set outdir [standard_output_file {}] set cmds_file "$outdir/cmds.txt" From patchwork Sun Jan 29 16:21:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63878 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 CFFC2385B511 for ; Sun, 29 Jan 2023 16:21:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id C70773858CDA for ; Sun, 29 Jan 2023 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C70773858CDA 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 cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id D09101004B50E for ; Sun, 29 Jan 2023 16:21:22 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQkp4x3jx5dfMAQkpmIRU; Sun, 29 Jan 2023 16:21:22 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=R+nGpfdX c=1 sm=1 tr=0 ts=63d69d02 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=iAAtyWHyVjSguO2617sA: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: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=8zxLhGBft9VUGDiFaMR6ms9zxln8p8ls6P6ItlBDcDc=; b=DzqPt1ynjJ7JO+KayBHC5edsbc J8uXttoaq7asTJ1BoGjFeps68J6U1rBHQO9AB0evTY9U1MD4TY0aP1lIkGJOXDJux5aqqjLA3Wsny lFAZXavO4tcQGykPAX84F6VPs; 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-HS; Sun, 29 Jan 2023 09:21:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/5] Move show_user_1 to cli-cmds.c Date: Sun, 29 Jan 2023 09:21:02 -0700 Message-Id: <20230129162105.526266-3-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 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-HS 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: 3 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 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" show_user_1 is only called from cli-cmds.c, so move it there and make it static. --- gdb/cli/cli-cmds.c | 35 +++++++++++++++++++++++++++++++++++ gdb/cli/cli-script.c | 35 ----------------------------------- gdb/cli/cli-script.h | 5 ----- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 6c0d780face..61f890a7dae 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1643,6 +1643,41 @@ make_command (const char *arg, int from_tty) } } +/* Print the definition of user command C to STREAM. Or, if C is a + prefix command, show the definitions of all user commands under C + (recursively). PREFIX and NAME combined are the name of the + current command. */ +static void +show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, + struct ui_file *stream) +{ + if (cli_user_command_p (c)) + { + struct command_line *cmdlines = c->user_commands.get (); + + gdb_printf (stream, "User %scommand \"", + c->is_prefix () ? "prefix" : ""); + fprintf_styled (stream, title_style.style (), "%s%s", + prefix, name); + gdb_printf (stream, "\":\n"); + if (cmdlines) + { + print_command_lines (current_uiout, cmdlines, 1); + gdb_puts ("\n", stream); + } + } + + if (c->is_prefix ()) + { + const std::string prefixname = c->prefixname (); + + for (c = *c->subcommands; c != NULL; c = c->next) + if (c->theclass == class_user || c->is_prefix ()) + show_user_1 (c, prefixname.c_str (), c->name, gdb_stdout); + } + +} + static void show_user (const char *args, int from_tty) { diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 92005ba8c38..0bd5803dc31 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1651,41 +1651,6 @@ script_from_file (FILE *stream, const char *file) } } -/* Print the definition of user command C to STREAM. Or, if C is a - prefix command, show the definitions of all user commands under C - (recursively). PREFIX and NAME combined are the name of the - current command. */ -void -show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, - struct ui_file *stream) -{ - if (cli_user_command_p (c)) - { - struct command_line *cmdlines = c->user_commands.get (); - - gdb_printf (stream, "User %scommand \"", - c->is_prefix () ? "prefix" : ""); - fprintf_styled (stream, title_style.style (), "%s%s", - prefix, name); - gdb_printf (stream, "\":\n"); - if (cmdlines) - { - print_command_lines (current_uiout, cmdlines, 1); - gdb_puts ("\n", stream); - } - } - - if (c->is_prefix ()) - { - const std::string prefixname = c->prefixname (); - - for (c = *c->subcommands; c != NULL; c = c->next) - if (c->theclass == class_user || c->is_prefix ()) - show_user_1 (c, prefixname.c_str (), c->name, gdb_stdout); - } - -} - void _initialize_cli_script (); void _initialize_cli_script () diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index da7307bbf8d..67ef0bb672e 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -130,11 +130,6 @@ extern counted_command_line read_command_lines_1 extern void script_from_file (FILE *stream, const char *file); -extern void show_user_1 (struct cmd_list_element *c, - const char *prefix, - const char *name, - struct ui_file *stream); - /* Execute the commands in CMDLINES. */ extern void execute_control_commands (struct command_line *cmdlines, From patchwork Sun Jan 29 16:21:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63881 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 00EB038493FB for ; Sun, 29 Jan 2023 16:22:34 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id 34FA33858C50 for ; Sun, 29 Jan 2023 16:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34FA33858C50 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 cmgw15.mail.unifiedlayer.com (unknown [10.0.90.130]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 08C3F1004743C for ; Sun, 29 Jan 2023 16:21:23 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQkpffAel2fvMAQkptrH9; Sun, 29 Jan 2023 16:21:23 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=NIUQR22g 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=Dyivgxzs2-QuVFkx6-cA: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=JCQTNgmC3wz20hRoLopkzppSb8Sq2fPBPstMnDV+K1g=; b=ZMFcXSG4x0j/+Ylf31HBngfTdF mjN/HHPy1pTnTuc8LQstpJ7fgDh02nlWrvktNgl00yzZFSYYxE3ociGc/h5f/uAekkn8Y7Nlu1CpU DILcXei8JCY5oHjXN4mFacpnW; 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-Mk; Sun, 29 Jan 2023 09:21:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/5] Add "save user" command Date: Sun, 29 Jan 2023 09:21:03 -0700 Message-Id: <20230129162105.526266-4-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 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-Mk 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: 4 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 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" PR cli/19395 points out that it would sometimes be convenient to save one's user-defined commands to a file. This patch implements this feature. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19395 --- gdb/NEWS | 3 ++ gdb/cli/cli-cmds.c | 72 +++++++++++++++++++++++++++++++++++++-------- gdb/doc/gdb.texinfo | 6 ++++ 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 2bc1672632a..3b7d768732c 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 user FILENAME + Save all user-defined commands to the given file. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 61f890a7dae..3f488d1a544 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -51,6 +51,7 @@ #include "cli/cli-style.h" #include "cli/cli-utils.h" #include "cli/cli-style.h" +#include "cli-out.h" #include "extension.h" #include "gdbsupport/pathstuff.h" @@ -1646,24 +1647,41 @@ make_command (const char *arg, int from_tty) /* Print the definition of user command C to STREAM. Or, if C is a prefix command, show the definitions of all user commands under C (recursively). PREFIX and NAME combined are the name of the - current command. */ + current command. DEF is true if the output should be written as a + source-able script. */ static void show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, - struct ui_file *stream) + struct ui_file *stream, struct ui_out *uiout, bool def) { if (cli_user_command_p (c)) { struct command_line *cmdlines = c->user_commands.get (); - gdb_printf (stream, "User %scommand \"", - c->is_prefix () ? "prefix" : ""); - fprintf_styled (stream, title_style.style (), "%s%s", - prefix, name); - gdb_printf (stream, "\":\n"); + if (def) + gdb_printf (stream, "define%s %s%s\n", + c->is_prefix () ? "-prefix" : "", + prefix, name); + else + { + gdb_printf (stream, "User %scommand \"", + c->is_prefix () ? "prefix" : ""); + fprintf_styled (stream, title_style.style (), "%s%s", + prefix, name); + gdb_printf (stream, "\":\n"); + } if (cmdlines) { - print_command_lines (current_uiout, cmdlines, 1); - gdb_puts ("\n", stream); + print_command_lines (uiout, cmdlines, 1); + if (!def) + gdb_puts ("\n", stream); + } + if (def) + { + gdb_puts ("end\n", stream); + + if (!c->is_prefix () && !streq (c->doc, "User-defined.")) + gdb_printf (stream, "document %s%s\n%s\nend\n", + prefix, name, c->doc); } } @@ -1673,9 +1691,8 @@ show_user_1 (struct cmd_list_element *c, const char *prefix, const char *name, for (c = *c->subcommands; c != NULL; c = c->next) if (c->theclass == class_user || c->is_prefix ()) - show_user_1 (c, prefixname.c_str (), c->name, gdb_stdout); + show_user_1 (c, prefixname.c_str (), c->name, stream, uiout, def); } - } static void @@ -1690,18 +1707,40 @@ show_user (const char *args, int from_tty) c = lookup_cmd (&comname, cmdlist, "", NULL, 0, 1); if (!cli_user_command_p (c)) error (_("Not a user command.")); - show_user_1 (c, "", args, gdb_stdout); + show_user_1 (c, "", args, gdb_stdout, current_uiout, false); } else { for (c = cmdlist; c; c = c->next) { if (cli_user_command_p (c) || c->is_prefix ()) - show_user_1 (c, "", c->name, gdb_stdout); + show_user_1 (c, "", c->name, gdb_stdout, current_uiout, false); } } } +/* The "save user" command. */ + +static void +save_user_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)); + + cli_ui_out uiout (&fp); + for (struct cmd_list_element *c = cmdlist; c != nullptr; c = c->next) + { + if (cli_user_command_p (c) || c->is_prefix ()) + show_user_1 (c, "", c->name, &fp, &uiout, true); + } +} + /* Return true if COMMAND or any of its sub-commands is a user defined command. This is a helper function for show_user_completer. */ @@ -2762,6 +2801,13 @@ Usage: apropos [-v] REGEXP\n\ Flag -v indicates to produce a verbose output, showing full documentation\n\ of the matching commands.")); + c = add_cmd ("user", no_class, save_user_command, _("\ +Save current user-defined commands as a script.\n\ +Usage: save user FILE\n\ +Use the 'source' command in another debug session to restore them."), + &save_cmdlist); + set_cmd_completer (c, filename_completer); + add_setshow_uinteger_cmd ("max-user-call-depth", no_class, &max_user_call_depth, _("\ Set the max call depth for non-python/scheme user-defined commands."), _("\ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index b5fad2cb16e..37db4785fd2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -28230,6 +28230,12 @@ The value of @code{max-user-call-depth} controls how many recursion levels are allowed in user-defined commands before @value{GDBN} suspects an infinite recursion and aborts the command. This does not apply to user-defined python commands. + +@kindex save user +@item save user @var{filename} +Save all user-defined commands to the file @var{filename}. This +command writes out the user-defined commands as a script that can be +re-read into @value{GDBN} using the @code{source} command. @end table In addition to the above commands, user-defined commands frequently From patchwork Sun Jan 29 16:21:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63876 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 0669C385B53C for ; Sun, 29 Jan 2023 16:21:41 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 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 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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" From patchwork Sun Jan 29 16:21:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63880 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 5B0AE383FBA9 for ; Sun, 29 Jan 2023 16:22:14 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id C438B3858D38 for ; Sun, 29 Jan 2023 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C438B3858D38 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 cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id 711651004824A for ; Sun, 29 Jan 2023 16:21:23 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id MAQlpch6Nc5SPMAQlpElVi; Sun, 29 Jan 2023 16:21:23 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=e7bD9Yl/ 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=mDV3o1hIAAAA:8 a=Chy_cNCYEP2WvqLK1q8A:9 a=ul9cdbp4aOFLsgKbc677:22 a=_FVE-zBwftR9WsbkzFJk: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=6Ko3gcQpFXu2iL/4Lbixw1epHaVJhXpMvG08Oju48OA=; b=ZCOOpE5Z/Gt2CzpbGL2Q8dB14n EyU57VFgcZgxJE4MfbPp9L/FVTWPhYq59AzXAjn5vM5kdq4/xQ/YOFA+mgRry+DiLP8ojm4uECrDD eWpBT7O4xJ/HhH9Fyyab7YIVy; 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 1pMAQl-001fCo-1N; Sun, 29 Jan 2023 09:21:23 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/5] Add "save history" command Date: Sun, 29 Jan 2023 09:21:05 -0700 Message-Id: <20230129162105.526266-6-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 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: 1pMAQl-001fCo-1N 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: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_BL_SPAMCOP_NET, 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 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" PR cli/23664 points out that it would sometimes be convenient to immediately save the current history to a file. This patch implements this feature. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23664 --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 8 ++++++ gdb/testsuite/gdb.base/save-history.exp | 36 +++++++++++++++++++++++++ gdb/top.c | 18 +++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 gdb/testsuite/gdb.base/save-history.exp diff --git a/gdb/NEWS b/gdb/NEWS index a5b6f8df2ff..0003dfc9bcb 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 history FILENAME + Save the command history to the given file. + save skip FILENAME Save all current "skip"s to the given file. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 31f73c33894..5ba8fbc5d16 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -26588,6 +26588,14 @@ removal of duplicate history entries is disabled. Only history entries added during the current session are considered for removal. This option is set to 0 by default. +@kindex save history +@item save history @var{filename} +Occasionally you may want to save your history to a file. This +command will do just that, saving the commands in your current session +to the named file. Note that you should normally edit the saved +history before using @code{source} to reload it, as the @code{save +history} command itself will be at the end of the file. + @end table History expansion assigns special meaning to the character @kbd{!}. diff --git a/gdb/testsuite/gdb.base/save-history.exp b/gdb/testsuite/gdb.base/save-history.exp new file mode 100644 index 00000000000..bb7a56b2a72 --- /dev/null +++ b/gdb/testsuite/gdb.base/save-history.exp @@ -0,0 +1,36 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the gdb testsuite. + +# Test the "save history" command. + +require {!is_remote host} + +gdb_start + +# Get something in history. +gdb_test "print 23" " = 23" + +set filename [standard_output_file histfile] +gdb_test_no_output "save history $filename" \ + "save history" + +set expected "set height 0\n" +append expected "set width 0\n" +append expected "print 23\n" +append expected "save history $filename\n" + +cmp_file_string $filename $expected "check history contents" diff --git a/gdb/top.c b/gdb/top.c index 205eb360ba3..f0c285e5989 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1325,6 +1325,18 @@ gdb_safe_append_history (void) } } +/* Implementation of 'save history' command. */ + +static void +save_history_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)); + write_history (expanded_filename.get ()); +} + /* Read one line from the command input stream `instream'. CMD_LINE_BUFFER is a buffer that the function may use to store the result, if @@ -2277,6 +2289,12 @@ Without an argument, saving is enabled."), show_write_history_p, &sethistlist, &showhistlist); + c = add_cmd ("history", no_class, save_history_command, _("\ +Save current history as a script.\n\ +Usage: save history FILE"), + &save_cmdlist); + set_cmd_completer (c, filename_completer); + add_setshow_zuinteger_unlimited_cmd ("size", no_class, &history_size_setshow_var, _("\ Set the size of the command history."), _("\