From patchwork Mon Mar 25 17:31:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Zaretskii X-Patchwork-Id: 31977 Received: (qmail 50950 invoked by alias); 25 Mar 2019 17:31:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 50842 invoked by uid 89); 25 Mar 2019 17:31:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:4.82, UD:texinfo, gdb.texinfo, gdbtexinfo X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Mar 2019 17:31:49 +0000 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39591) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8TRq-0005Pj-Aw for gdb-patches@sourceware.org; Mon, 25 Mar 2019 13:31:47 -0400 Received: from [176.228.60.248] (port=2265 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1h8TRm-0008MJ-O6 for gdb-patches@sourceware.org; Mon, 25 Mar 2019 13:31:45 -0400 Date: Mon, 25 Mar 2019 19:31:47 +0200 Message-Id: <83r2aun9mk.fsf@gnu.org> From: Eli Zaretskii To: gdb-patches@sourceware.org In-reply-to: <83k1gts5it.fsf@gnu.org> (message from Eli Zaretskii on Wed, 20 Mar 2019 21:35:38 +0200) Subject: Re: GDB version as convenience variable References: <20181128001435.12703-1-tom@tromey.com> <83k1kxfzwo.fsf@gnu.org> <8736rja4i8.fsf@tromey.com> <83r2brhw8k.fsf@gnu.org> <87h8cmh1wg.fsf@tromey.com> <83va12gz8j.fsf@gnu.org> <87mumeb935.fsf@tromey.com> <83d0n8eyzw.fsf@gnu.org> <87d0n6adk2.fsf@tromey.com> <83imwyee29.fsf@gnu.org> <87d0n67d29.fsf@tromey.com> <83imwwc7pj.fsf@gnu.org> <83k1gts5it.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-IsSubscribed: yes Seems like there's a consensus to have 2 separate variables, so here's a version of the patch that does that. OK to commit? diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2de1adc..f841e0a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-03-06 Eli Zaretskii + + * NEWS: Announce $_gdb_major and $_gdb_minor. + + * top.c (init_gdb_version_vars): New function. + (gdb_init): Call init_gdb_version_vars. + 2019-03-25 Alan Hayward * s390-linux-nat.c: Add include. diff --git a/gdb/NEWS b/gdb/NEWS index c45b313..676f0a0 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,12 @@ *** Changes since GDB 8.3 +* New built-in convenience variables $_gdb_major and $_gdb_minor + provide the GDB version. They are handy for conditionally using + features available only in or since specific GDB versions, in + scripts that should work error-free with many different versions, + such as in system-wide init files. + *** Changes in GDB 8.3 * GDB and GDBserver now support access to additional registers on diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 1f41498..c384267 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2019-03-06 Eli Zaretskii + + * gdb.texinfo (Convenience Vars): Document $_gdb_version. + 2019-03-22 Alan Hayward Jiong Wang diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 4c1d5e8..115bcf7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -11211,6 +11211,17 @@ @item $_gthread The global number of the current thread. @xref{global thread numbers}. +@item $_gdb_major +@itemx $_gdb_minor +@vindex $_gdb_major@{, convenience variable} +@vindex $_gdb_minor@{, convenience variable} +The major and minor version numbers of the running @value{GDBN}. +Development snapshots and pretest versions have their minor version +incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce +the value 12 for @code{$_gdb_minor}. These variables allow you to +write scripts that work with different versions of @value{GDBN} +without errors caused by features unavailable in some of those +versions. @end table @node Convenience Funs diff --git a/gdb/top.c b/gdb/top.c index b10b064..afb77c0 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -2003,6 +2004,17 @@ set_history_filename (const char *args, } static void +init_gdb_version_vars (void) +{ + struct internalvar *major_version_var = create_internalvar ("_gdb_major"); + struct internalvar *minor_version_var = create_internalvar ("_gdb_minor"); + int vmajor = 0, vminor = 0, vrevision = 0; + sscanf (version, "%d.%d.%d", &vmajor, &vminor, &vrevision); + set_internalvar_integer (major_version_var, vmajor); + set_internalvar_integer (minor_version_var, vminor + (vrevision > 0)); +} + +static void init_main (void) { struct cmd_list_element *c; @@ -2206,4 +2218,7 @@ gdb_init (char *argv0) prefix to be installed. Keep things simple and just do final script initialization here. */ finish_ext_lang_initialization (); + + /* Create $_gdb_major and $_gdb_minor convenience variables. */ + init_gdb_version_vars (); }