Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Pedro Alves <palves@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH v3 1/7] Add a new $_inferior convenience variable
Date: Wed, 06 Jan 2016 18:56:00 -0000	[thread overview]
Message-ID: <568D6365.2080601@ericsson.com> (raw)
In-Reply-To: <1452085418-18300-2-git-send-email-palves@redhat.com>

On 16-01-06 08:03 AM, Pedro Alves wrote:
> Like $_thread, but holds the current inferior number.
> 
> gdb/ChangeLog:
> 2016-01-06  Pedro Alves  <palves@redhat.com>
> 
> 	* NEWS: Mention $_inferior.
> 	* inferior.c (inferior_id_make_value): New.
> 	(inferior_funcs): New.
> 	(_initialize_inferior): Create $_inferior variable.
> 
> gdb/testsuite/ChangeLog:
> 2016-01-06  Pedro Alves  <palves@redhat.com>
> 
> 	* gdb.base/default.exp: Expect $_inferior as well.
> 	* gdb.multi/base.exp: Test $_inferior.
> 
> gdb/doc/ChangeLog:
> 2016-01-06  Pedro Alves  <palves@redhat.com>
> 
> 	* gdb.texinfo (Inferiors and Programs): Document the $_inferior
> 	convenience variable.
> 	(Convenience Vars): Likewise.
> ---
>  gdb/NEWS                           |  3 +++
>  gdb/doc/gdb.texinfo                | 10 ++++++++++
>  gdb/inferior.c                     | 21 +++++++++++++++++++++
>  gdb/testsuite/gdb.base/default.exp |  1 +
>  gdb/testsuite/gdb.multi/base.exp   |  4 ++++
>  5 files changed, 39 insertions(+)
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 484d98d..31c870d 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 7.10
>  
> +* The new convenience variable $_inferior holds the number of the
> +  current inferior.
> +
>  * Record btrace now supports non-stop mode.
>  
>  * Support for tracepoints on aarch64-linux was added in GDBserver.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 0778383..f01b703 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -2658,6 +2658,12 @@ Make inferior number @var{infno} the current inferior.  The argument
>  in the first field of the @samp{info inferiors} display.
>  @end table
>  
> +@vindex $_inferior@r{, convenience variable}
> +The debugger convenience variable @samp{$_inferior} contains the
> +number of the current inferior.  You may find this useful in writing
> +breakpoint conditional expressions, command scripts, and so forth.
> +@xref{Convenience Vars,, Convenience Variables}, for general
> +information on convenience variables.
>  
>  You can get multiple executables into a debugging session via the
>  @code{add-inferior} and @w{@code{clone-inferior}} commands.  On some
> @@ -10382,6 +10388,10 @@ gdbserver that supports the @code{qGetTIBAddr} request.
>  @xref{General Query Packets}.
>  This variable contains the address of the thread information block.
>  
> +@item $_inferior
> +The number of the current inferior.  @xref{Inferiors and
> +Programs, ,Debugging Multiple Inferiors and Programs}.
> +
>  @end table
>  
>  @node Convenience Funs
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index e71104d..8f9ac33 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -1008,6 +1008,26 @@ show_print_inferior_events (struct ui_file *file, int from_tty,
>    fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value);
>  }
>  
> +/* Return a new value for the selected inferior's id.  */
> +
> +static struct value *
> +inferior_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
> +			void *ignore)
> +{
> +  struct inferior *inf = current_inferior ();
> +
> +  return value_from_longest (builtin_type (gdbarch)->builtin_int, inf->num);
> +}
> +
> +/* Implementation of `$_inferior' variable.  */
> +
> +static const struct internalvar_funcs inferior_funcs =
> +{
> +  inferior_id_make_value,
> +  NULL,
> +  NULL
> +};
> +
>  \f
>  
>  void
> @@ -1071,4 +1091,5 @@ Show printing of inferior events (e.g., inferior start and exit)."), NULL,
>           show_print_inferior_events,
>           &setprintlist, &showprintlist);
>  
> +  create_internalvar_type_lazy ("_inferior", &inferior_funcs, NULL);
>  }
> diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
> index 90bf27d..fec2cde 100644
> --- a/gdb/testsuite/gdb.base/default.exp
> +++ b/gdb/testsuite/gdb.base/default.exp
> @@ -587,6 +587,7 @@ set show_conv_list \
>  	{$_sdata = void} \
>  	{$_siginfo = void} \
>  	{$_thread = 0} \
> +	{$_inferior = 1} \
>  	{$_exception = <error: No frame selected>} \
>  	{$_probe_argc = <error: No frame selected>} \
>  	{$_probe_arg0 = <error: No frame selected>} \
> diff --git a/gdb/testsuite/gdb.multi/base.exp b/gdb/testsuite/gdb.multi/base.exp
> index 6f0bc63..1aa907d 100644
> --- a/gdb/testsuite/gdb.multi/base.exp
> +++ b/gdb/testsuite/gdb.multi/base.exp
> @@ -44,12 +44,16 @@ if { [build_executable ${testfile}.exp ${exec3} "${srcfile3}" {debug}] == -1 } {
>  
>  clean_restart ${exec1}
>  
> +gdb_test {print $_inferior} " = 1"
> +
>  # Add an empty inferior, switch to it, and load a main executable into
>  # it.
>  gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
>  gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2"
>  gdb_test "file ${binfile2}" ".*" "load ${exec2} file in inferior 2"
>  
> +gdb_test {print $_inferior} " = 2" "print \$_inferior after switching"
> +
>  # Add a new inferior and load a main executable into it in one
>  # command.
>  gdb_test "add-inferior -exec ${binfile3}" \
> 

LGTM.


  reply	other threads:[~2016-01-06 18:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-06 13:03 [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 13:03 ` [PATCH v3 3/7] Centralize thread ID printing Pedro Alves
2016-01-06 18:57   ` Simon Marchi
2016-01-06 13:03 ` [PATCH v3 1/7] Add a new $_inferior convenience variable Pedro Alves
2016-01-06 18:56   ` Simon Marchi [this message]
2016-01-06 13:03 ` [PATCH v3 5/7] InferiorThread.global_num Pedro Alves
2016-01-06 19:03   ` Simon Marchi
2016-01-06 13:03 ` [PATCH v3 2/7] Add Python InferiorThread.inferior attribute Pedro Alves
2016-01-06 18:57   ` Simon Marchi
2016-01-06 13:04 ` [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 18:51   ` Simon Marchi
2016-01-07 19:45     ` Pedro Alves
2016-01-07 22:28       ` Simon Marchi
2016-01-07 23:37         ` Pedro Alves
2016-12-07 21:10           ` Thomas Schwinge
2016-12-07 21:29             ` Simon Marchi
2016-12-08  8:53               ` Thomas Schwinge
2016-01-07 22:02   ` Simon Marchi
2016-01-07 22:24     ` Pedro Alves
2016-01-06 13:11 ` [PATCH v3 6/7] Implement "info threads -gid" Pedro Alves
2016-01-06 19:12   ` Simon Marchi
2016-01-06 13:11 ` [PATCH v3 7/7] Add $_gthread convenience variable Pedro Alves
2016-01-06 19:14   ` Simon Marchi
2016-01-08 13:54 ` [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Yao Qi
2016-01-13 11:25   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=568D6365.2080601@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox