Skip to content

Commit 7734102

Browse files
committed
Introduce new convenience variables $_gdb_major and $_gdb_minor
gdb/ChangeLog: 2019-03-30 Eli Zaretskii <eliz@gnu.org> * NEWS: Announce $_gdb_major and $_gdb_minor. * top.c (init_gdb_version_vars): New function. (gdb_init): Call init_gdb_version_vars. gdb/testsuite/ChangeLog: 2019-03-30 Simon Marchi <simark@simark.ca> * gdb.base/default.exp: Add values for $_gdb_major and $_gdb_minor. gdb/doc/ChangeLog: 2019-03-30 Eli Zaretskii <eliz@gnu.org> * gdb.texinfo (Convenience Vars): Document $_gdb_major and $_gdb_minor.
1 parent c6f03bc commit 7734102

File tree

7 files changed

+64
-13
lines changed

7 files changed

+64
-13
lines changed

gdb/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2019-03-30 Eli Zaretskii <eliz@gnu.org>
2+
3+
* NEWS: Announce $_gdb_major and $_gdb_minor.
4+
5+
* top.c (init_gdb_version_vars): New function.
6+
(gdb_init): Call init_gdb_version_vars.
7+
18
2019-03-29 Tom Tromey <tromey@adacore.com>
29

310
* printcmd.c (_initialize_printcmd): Add usage lines. Update some

gdb/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
*** Changes since GDB 8.3
55

6+
* New built-in convenience variables $_gdb_major and $_gdb_minor
7+
provide the GDB version. They are handy for conditionally using
8+
features available only in or since specific GDB versions, in
9+
scripts that should work error-free with many different versions,
10+
such as in system-wide init files.
11+
612
* GDB now supports Thread Local Storage (TLS) variables on several
713
FreeBSD architectures (amd64, i386, powerpc, riscv). Other
814
architectures require kernel changes. TLS is not yet supported for

gdb/doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-03-30 Eli Zaretskii <eliz@gnu.org>
2+
3+
* gdb.texinfo (Convenience Vars): Document $_gdb_major and
4+
$_gdb_minor.
5+
16
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
27

38
* python.texi (Pretty Printing API): Document use of None for the

gdb/doc/gdb.texinfo

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11197,7 +11197,7 @@ For example, it will be empty before you execute the @code{run} command.
1119711197
@vindex $_tlb@r{, convenience variable}
1119811198
The variable @code{$_tlb} is automatically set when debugging
1119911199
applications running on MS-Windows in native mode or connected to
11200-
gdbserver that supports the @code{qGetTIBAddr} request.
11200+
gdbserver that supports the @code{qGetTIBAddr} request.
1120111201
@xref{General Query Packets}.
1120211202
This variable contains the address of the thread information block.
1120311203

@@ -11211,6 +11211,17 @@ The thread number of the current thread. @xref{thread numbers}.
1121111211
@item $_gthread
1121211212
The global number of the current thread. @xref{global thread numbers}.
1121311213

11214+
@item $_gdb_major
11215+
@itemx $_gdb_minor
11216+
@vindex $_gdb_major@r{, convenience variable}
11217+
@vindex $_gdb_minor@r{, convenience variable}
11218+
The major and minor version numbers of the running @value{GDBN}.
11219+
Development snapshots and pretest versions have their minor version
11220+
incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
11221+
the value 12 for @code{$_gdb_minor}. These variables allow you to
11222+
write scripts that work with different versions of @value{GDBN}
11223+
without errors caused by features unavailable in some of those
11224+
versions.
1121411225
@end table
1121511226

1121611227
@node Convenience Funs

gdb/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-03-30 Simon Marchi <simark@simark.ca>
2+
3+
* gdb.base/default.exp: Add values for $_gdb_major and
4+
$_gdb_minor.
5+
16
2019-03-29 Tom Tromey <tromey@adacore.com>
27

38
* gdb.base/help.exp: Tighten apropos regexp.

gdb/testsuite/gdb.base/default.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ set show_conv_list \
602602
{$_probe_arg10 = <error: No frame selected>} \
603603
{$_probe_arg11 = <error: No frame selected>} \
604604
{$_isvoid = <internal function _isvoid>} \
605+
{$_gdb_major = 8} \
606+
{$_gdb_minor = 4} \
605607
}
606608
if ![skip_python_tests] {
607609
append show_conv_list \

gdb/top.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,22 @@ int server_command;
147147

148148
/* Timeout limit for response from target. */
149149

150-
/* The default value has been changed many times over the years. It
151-
was originally 5 seconds. But that was thought to be a long time
150+
/* The default value has been changed many times over the years. It
151+
was originally 5 seconds. But that was thought to be a long time
152152
to sit and wait, so it was changed to 2 seconds. That was thought
153-
to be plenty unless the connection was going through some terminal
153+
to be plenty unless the connection was going through some terminal
154154
server or multiplexer or other form of hairy serial connection.
155155
156-
In mid-1996, remote_timeout was moved from remote.c to top.c and
156+
In mid-1996, remote_timeout was moved from remote.c to top.c and
157157
it began being used in other remote-* targets. It appears that the
158158
default was changed to 20 seconds at that time, perhaps because the
159159
Renesas E7000 ICE didn't always respond in a timely manner.
160160
161161
But if 5 seconds is a long time to sit and wait for retransmissions,
162-
20 seconds is far worse. This demonstrates the difficulty of using
162+
20 seconds is far worse. This demonstrates the difficulty of using
163163
a single variable for all protocol timeouts.
164164
165-
As remote.c is used much more than remote-e7000.c, it was changed
165+
As remote.c is used much more than remote-e7000.c, it was changed
166166
back to 2 seconds in 1999. */
167167

168168
int remote_timeout = 2;
@@ -188,9 +188,9 @@ int (*deprecated_ui_loop_hook) (int);
188188

189189
/* Called from print_frame_info to list the line we stopped in. */
190190

191-
void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
191+
void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
192192
int line,
193-
int stopline,
193+
int stopline,
194194
int noerror);
195195
/* Replaces most of query. */
196196

@@ -237,7 +237,7 @@ ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
237237
/* Used by UI as a wrapper around command execution. May do various
238238
things like enabling/disabling buttons, etc... */
239239

240-
void (*deprecated_call_command_hook) (struct cmd_list_element * c,
240+
void (*deprecated_call_command_hook) (struct cmd_list_element * c,
241241
const char *cmd, int from_tty);
242242

243243
/* Called when the current thread changes. Argument is thread id. */
@@ -1339,8 +1339,9 @@ There is NO WARRANTY, to the extent permitted by law.");
13391339
resources online at:\n <http://www.gnu.org/software/gdb/documentation/>."));
13401340
fprintf_filtered (stream, "\n\n");
13411341
fprintf_filtered (stream, _("For help, type \"help\".\n"));
1342-
fprintf_filtered (stream, _("Type \"apropos word\" to search for \
1343-
commands related to \"word\"."));
1342+
fprintf_filtered (stream,
1343+
_("Type \"apropos word\" to search for commands \
1344+
related to \"word\"."));
13441345
}
13451346

13461347
/* Print the details of GDB build-time configuration. */
@@ -1608,7 +1609,7 @@ quit_force (int *exit_arg, int from_tty)
16081609

16091610
undo_terminal_modifications_before_exit ();
16101611

1611-
/* An optional expression may be used to cause gdb to terminate with the
1612+
/* An optional expression may be used to cause gdb to terminate with the
16121613
value of that expression. */
16131614
if (exit_arg)
16141615
exit_code = *exit_arg;
@@ -2002,6 +2003,17 @@ set_history_filename (const char *args,
20022003
history_filename, (char *) NULL);
20032004
}
20042005

2006+
static void
2007+
init_gdb_version_vars (void)
2008+
{
2009+
struct internalvar *major_version_var = create_internalvar ("_gdb_major");
2010+
struct internalvar *minor_version_var = create_internalvar ("_gdb_minor");
2011+
int vmajor = 0, vminor = 0, vrevision = 0;
2012+
sscanf (version, "%d.%d.%d", &vmajor, &vminor, &vrevision);
2013+
set_internalvar_integer (major_version_var, vmajor);
2014+
set_internalvar_integer (minor_version_var, vminor + (vrevision > 0));
2015+
}
2016+
20052017
static void
20062018
init_main (void)
20072019
{
@@ -2206,4 +2218,7 @@ gdb_init (char *argv0)
22062218
prefix to be installed. Keep things simple and just do final
22072219
script initialization here. */
22082220
finish_ext_lang_initialization ();
2221+
2222+
/* Create $_gdb_major and $_gdb_minor convenience variables. */
2223+
init_gdb_version_vars ();
22092224
}

0 commit comments

Comments
 (0)