From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZhvRMWdByGiflwUAWB0awg (envelope-from ) for ; Mon, 15 Sep 2025 12:40:07 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N1n7Es6l; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B70911E0BA; Mon, 15 Sep 2025 12:40:07 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 81E2A1E04C for ; Mon, 15 Sep 2025 12:40:06 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E593B3858407 for ; Mon, 15 Sep 2025 16:40:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E593B3858407 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N1n7Es6l Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 927FA3858D1E for ; Mon, 15 Sep 2025 16:39:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 927FA3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 927FA3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757954365; cv=none; b=F58JoUU/ZjTWCXwh6XUfOVX4wAW6ixG06r4swKEz4pQ/+Li2gSQVWjL5wMbZWH1tTwxHY2bUr/B43b11K7c3RioLvRtD8hCErRO01T1VdnsISDKHAUHjK2dBVGUGX6SbRIn9mCBotnGANMfgjx2opx+EXTuvRG/PmNty0Lldw8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757954365; c=relaxed/simple; bh=y0StVLC7I+PIEH5ySszM9eTN9VmkY+y3osTe1K0YE80=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KfdWhtYPhDdQwrUVJVVbDVTKk5WdbF9144k722c2rsDS76tWxrLticBLiz3kj42avR+quUrew8r6Uo2zo9M3qMywNm6Jope+tRnuZ1sQCDZyqut4K73At8HzOyxTdoT5WyMpSo/OOsARbN2iGb47kieqMv+Br3YHw6shAZoROqE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 927FA3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757954365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9W0DEyGcJBNVnrj3/qKSaK1kXmfedyOKaJtuKVxBWOY=; b=N1n7Es6lP94XdQ0V9gt/UVVlhA30KiDWPIWSjqmMqbn0Me6b9/phss8Ig23mavb0BzXApB qewP9dpEjk2DkYG+f9YKtnWpg0oCAc4+LptEaFGkjlwoW/1OZyxLKEmazhOGzQFrfpSkta xKsnpatqhno4OIHKkpPX3CS13+d+8yA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-YKUsVsOUOkefkLxqFbTaaw-1; Mon, 15 Sep 2025 12:39:23 -0400 X-MC-Unique: YKUsVsOUOkefkLxqFbTaaw-1 X-Mimecast-MFC-AGG-ID: YKUsVsOUOkefkLxqFbTaaw_1757954363 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EFDB01953954 for ; Mon, 15 Sep 2025 16:39:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.155]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D2C7300021A; Mon, 15 Sep 2025 16:39:20 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH] gdb: Make startup message more user friendly Date: Mon, 15 Sep 2025 13:39:12 -0300 Message-ID: <20250915163912.9024-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qNPAEJI-Q_fU-ON3-GE5lvSUOgN1ryVIp1FDuqUaqSg_1757954363 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Currently, on startup, GDB prints a lot of licensing information and then a few hints for new users. While there is an attempt to separate the hints from the rest of the text, my user testing showed that it is not good enough, and most unfamiliar users will just skip the information. Especially considering that the documentation link happens before the separation. This commit attempts to make the startup message more friendly to new users by using ascii art separators. If there is enough space availabe, an ascii art box is printed containing the hints, otherwise a simple separator is printed. The code deems "enough space available" when there is enough space to print the documentation URL inside the box, since the other hints will be broken into multiple lines if necessary. Here are examples of the 2 possible startups, with enough space: +-----------------------------------------------------------------+ | Find the GDB manual online at: | | http://www.gnu.org/software/gdb/documentation/ | | For help, type "help". | | Type "apropos " to search for commands related to "word". | +-----------------------------------------------------------------+ And with limited space: --------------------------------------------- Find the GDB manual documentation resources o nline at: . For help, type "help". Type "apropos word" to search for commands re lated to "word". Unfortunately, I was not able to think of a way in which the code could break a line if necessary and also include styled code for URLs and commands, so, since I believe it is more important to have the box as available as possible, I opted to not include any styling options. --- gdb/main.c | 2 ++ gdb/top.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++------- gdb/top.h | 4 +++ 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/gdb/main.c b/gdb/main.c index e1ef537c357..114b918bb39 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -1163,6 +1163,8 @@ captured_main_1 (struct captured_main_args *context) /* Print all the junk at the top, with trailing "..." if we are about to read a symbol file (possibly slowly). */ print_gdb_version (gdb_stdout, true); + gdb_printf ("\n"); + print_gdb_hints (gdb_stdout); if (symarg) gdb_printf (".."); gdb_printf ("\n"); diff --git a/gdb/top.c b/gdb/top.c index f5b9fdc3034..81ac6476d9b 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1357,17 +1357,81 @@ There is NO WARRANTY, to the extent permitted by law.", styled_string (file_name_style.style (), REPORT_BUGS_TO)); } - gdb_printf (stream, - _("Find the GDB manual and other documentation \ -resources online at:\n <%ps>."), - styled_string (file_name_style.style (), - "http://www.gnu.org/software/gdb/documentation/")); - gdb_printf (stream, "\n\n"); - gdb_printf (stream, _("For help, type \"%ps\".\n"), - styled_string (command_style.style (), "help")); - gdb_printf (stream, - _("Type \"%ps\" to search for commands related to \"word\"."), - styled_string (command_style.style (), "apropos word")); +} + +/* Print MESSAGE to STREAM in lines of maximum size WIDTH, so that it fits + in an ascii art box of width WIDTH+4. Messages may be broken on + spaces. */ +static void +box_one_message (ui_file *stream, std::string message, int width) +{ + while (!message.empty ()) + { + std::string line; + if (message.length () > width) + { + line = message.substr (0, message.rfind (" ", width)); + message = message.substr (line.length ()); + } + else + { + line = message; + message = ""; + } + + if (line.length () < width) + line.append (width - line.length (), ' '); + + gdb_printf (stream, "| %s |\n", line.c_str ()); + } +} + +/* Print some hints about how to use GDB in a very visible manner. */ +void +print_gdb_hints (struct ui_file *stream) +{ + int width = get_chars_per_line (); + + /* Arbitrarily setting maximum width to 80 characters, so that + things are big and visible but not overwhelming. */ + if (80 < width) + width = 80; + + std::string docs_url = "http://www.gnu.org/software/gdb/documentation/"; + /* If there isn't enough space to display the longest URL in a boxed + style, use the simple styling of a singular visual break. The longest + URL is used because the other messages may be broken into multiple + lines, but URLs can't. */ + if (width - 3 <= docs_url.length ()) + { + std::string sep (width, '-'); + gdb_printf (stream, "%s\n", sep.c_str ()); + gdb_printf (stream, + _("Find the GDB manual documentation resources online at:\ +\n <%ps>.\n"), + styled_string (file_name_style.style (), docs_url.c_str ())); + gdb_printf (stream, _("For help, type \"%ps\".\n"), + styled_string (command_style.style (), "help")); + gdb_printf (stream, + _("Type \"%ps\" to search for commands related to \"word\"."), + styled_string (command_style.style (), "apropos word")); + return; + } + else + { + std::string sep (width-2, '-'); + /* Account for opening and closing of the box. */ + width -= 4; + + gdb_printf (stream, "+%s+\n", sep.c_str ()); + box_one_message (stream, "Find the GDB manual online at:", width); + box_one_message (stream, docs_url.c_str (), width); + box_one_message (stream, "For help, type \"help\".", width); + box_one_message (stream, "Type \"apropos \" to search for" + " commands related to \"word\".", + width); + gdb_printf (stream, "+%s+\n", sep.c_str ()); + } } /* Print the details of GDB build-time configuration. */ diff --git a/gdb/top.h b/gdb/top.h index 41af51acecf..f90515ea740 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -36,6 +36,10 @@ extern auto_boolean interactive_mode; mentioned. */ extern void print_gdb_version (struct ui_file *stream, bool interactive); +/* Print some hints for an inexperienced user on how to get more + information about using GDB. */ +extern void print_gdb_hints (struct ui_file *stream); + extern void print_gdb_configuration (struct ui_file *); extern void read_command_file (FILE *); base-commit: 84c1e5cec0ec7d80d460db2b823d329e9759c642 -- 2.51.0