From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway34.websitewelcome.com (gateway34.websitewelcome.com [192.185.148.222]) by sourceware.org (Postfix) with ESMTPS id C0BCF385DC1A for ; Sat, 4 Apr 2020 14:54:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C0BCF385DC1A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 6D2FC17549E for ; Sat, 4 Apr 2020 09:54:24 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id KkBkjRfTaAGTXKkBkjonBi; Sat, 04 Apr 2020 09:54:24 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=lY32NydI9nfGZvUfNFRboAQAazn/PNkJ/bVzh8AAKvY=; b=gXq/BvMrbGuoM3wCAc5ll6VtM+ qCUB2/DceR/P7e60Qsgpz0kfhQrJjrVlE7cdJE7ZLl8Jt0RpzU+FPF7BAZVtfxxcHVoTZeEj6XC9D YrXpGUynAQTnTZo+28Xax76oN; Received: from 174-16-110-145.hlrn.qwest.net ([174.16.110.145]:58652 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jKkBk-003pFd-6F; Sat, 04 Apr 2020 08:54:24 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 3/6] Add "tips" file to gdb Date: Sat, 4 Apr 2020 08:54:19 -0600 Message-Id: <20200404145422.19917-4-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200404145422.19917-1-tom@tromey.com> References: <20200404145422.19917-1-tom@tromey.com> 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: 174.16.110.145 X-Source-L: No X-Exim-ID: 1jKkBk-003pFd-6F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-110-145.hlrn.qwest.net (bapiya.Home) [174.16.110.145]:58652 X-Source-Auth: tom+tromey.com X-Email-Count: 35 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-18.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sat, 04 Apr 2020 14:54:26 -0000 This adds a "tips" file to gdb. This file holds handy tips -- right now there are just a few, but it's easy to add more. A random tip is displayed during interactive startup. gdb/ChangeLog 2020-03-28 Tom Tromey * NEWS: Add entry. * top.c (startup_style): New global. (print_tip): New function. (print_gdb_version): Update. Don't print "show configuration" or "apropos" info. Call print_tip. * tips: New file. * data-directory/Makefile.in (GDB_FILES): Add "tips". --- gdb/ChangeLog | 10 +++++ gdb/NEWS | 2 + gdb/data-directory/Makefile.in | 2 +- gdb/tips | 9 ++++ gdb/top.c | 78 +++++++++++++++++++++++++++++----- 5 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 gdb/tips diff --git a/gdb/NEWS b/gdb/NEWS index 9d85e630e8c..b376737e409 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,8 @@ *** Changes since GDB 9 +* GDB will now display a helpful tip when starting up. + * GDB now supports debuginfod, an HTTP server for distributing ELF/DWARF debugging information as well as source code. diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index 95258d184e7..5cc7ec80c40 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -139,7 +139,7 @@ SYSTEM_GDBINIT_FILES = \ elinos.py \ wrs-linux.py -GDB_FILES = NEWS +GDB_FILES = NEWS tips FLAGS_TO_PASS = \ "prefix=$(prefix)" \ diff --git a/gdb/tips b/gdb/tips new file mode 100644 index 00000000000..75957fb853d --- /dev/null +++ b/gdb/tips @@ -0,0 +1,9 @@ +This file is in the old "fortune" format. Each entry is separated by +a percent character on a line of its own. Anything before the first +percent will never be shown. +% +You can use "help news" to see what has changed in GDB. +% +Type "apropos word" to search for commands related to "word". +% +Type "show configuration" for configuration details. diff --git a/gdb/top.c b/gdb/top.c index e2432489dc8..7af820b0bb9 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -56,6 +56,8 @@ #include "gdbarch.h" #include "gdbsupport/pathstuff.h" #include "cli/cli-style.h" +#include "gdbsupport/scoped_fd.h" +#include /* readline include files. */ #include "readline/readline.h" @@ -128,6 +130,14 @@ current_ui_current_uiout_ptr () int inhibit_gdbinit = 0; +/* The style used for informational messages at startup. */ +static ui_file_style startup_style = +{ + ui_file_style::MAGENTA, + ui_file_style::NONE, + ui_file_style::BOLD +}; + /* Flag for whether we want to confirm potentially dangerous operations. Default is yes. */ @@ -1376,6 +1386,59 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix) return cmd; } + +/* Print a useful tip to STREAM. */ + +static void +print_tip (struct ui_file *stream) +{ + std::string tip_name = std::string (gdb_datadir) + SLASH_STRING + "tips"; + scoped_fd fd (gdb_open_cloexec (tip_name.c_str (), O_RDONLY | O_BINARY, 0)); + if (fd.get () < 0) + { + perror_warning_with_name ((std::string (_("Could not open tip file ")) + + tip_name).c_str ()); + return; + } + + std::string lines; + try + { + lines = read_entire_file (tip_name.c_str (), fd.get ()); + } + catch (const gdb_exception &exc) + { + exception_print (stream, exc); + return; + } + + std::vector strings; + size_t offset = lines.find ("%\n"); + if (offset == std::string::npos) + return; + while (offset != std::string::npos) + { + offset += 2; + size_t next_offset = lines.find ("%\n", offset); + + if (next_offset == std::string::npos) + strings.emplace_back (lines.c_str () + offset); + else + strings.emplace_back (lines.c_str () + offset, next_offset - offset); + + offset = next_offset; + } + + std::random_device rd; + std::mt19937 mt (rd ()); + std::uniform_int_distribution<> distr (0, strings.size () - 1); + int index = distr (mt); + /* Note that the string will include a newline. */ + fprintf_styled (stream, startup_style, "\n%.*s", + (int) strings[index].size (), + strings[index].data ()); +} + /* See top.h. */ void print_gdb_version (struct ui_file *stream, bool interactive) @@ -1386,11 +1449,7 @@ print_gdb_version (struct ui_file *stream, bool interactive) ui_file_style style; if (interactive) - { - ui_file_style nstyle = { ui_file_style::MAGENTA, ui_file_style::NONE, - ui_file_style::BOLD }; - style = nstyle; - } + style = startup_style; fprintf_styled (stream, style, "GNU gdb %s%s\n", PKGVERSION, version); /* Second line is a copyright notice. */ @@ -1428,9 +1487,6 @@ There is NO WARRANTY, to the extent permitted by law."); } fprintf_filtered (stream, "\".\n"); - fprintf_filtered (stream, _("Type \"show configuration\" " - "for configuration details.\n")); - if (REPORT_BUGS_TO[0]) { fprintf_filtered (stream, @@ -1442,9 +1498,9 @@ There is NO WARRANTY, to the extent permitted by law."); resources online at:\n .")); fprintf_filtered (stream, "\n\n"); fprintf_filtered (stream, _("For help, type \"help\".\n")); - fprintf_filtered (stream, - _("Type \"apropos word\" to search for commands \ -related to \"word\".")); + + if (interactive) + print_tip (stream); } /* Print the details of GDB build-time configuration. */ -- 2.17.2