Add attributes and methods to gdb.Inferior

This adds two new attributes and three new methods to gdb.Inferior.

The attributes let Python code see the command-line arguments and the
name of "main".  Argument setting is also supported.

The methods let Python code manipulate the inferior's environment
variables.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
Tom Tromey
2023-05-01 13:53:59 -06:00
parent 2f328f5b92
commit 3153113252
5 changed files with 263 additions and 0 deletions

View File

@@ -3451,10 +3451,30 @@ Boolean signaling whether the inferior was created using `attach', or
started by @value{GDBN} itself.
@end defvar
@defvar Inferior.main_name
A string holding the name of this inferior's ``main'' function, if it
can be determined. If the name of main is not known, this is
@code{None}.
@end defvar
@defvar Inferior.progspace
The inferior's program space. @xref{Progspaces In Python}.
@end defvar
@defvar Inferior.arguments
The inferior's command line arguments, if known. This corresponds to
the @code{set args} and @code{show args} commands. @xref{Arguments}.
When accessed, the value is a string holding all the arguments. The
contents are quoted as they would be when passed to the shell. If
there are no arguments, the value is @code{None}.
Either a string or a sequence of strings can be assigned to this
attribute. When a string is assigned, it is assumed to have any
necessary quoting for the shell; when a sequence is assigned, the
quoting is applied by @value{GDBN}.
@end defvar
A @code{gdb.Inferior} object has the following methods:
@defun Inferior.is_valid ()
@@ -3522,6 +3542,30 @@ the same functionality, but use of @code{Inferior.thread_from_thread_handle}
is deprecated.
@end defun
The environment that will be passed to the inferior can be changed
from Python by using the following methods. These methods only take
effect when the inferior is started -- they will not affect an
inferior that is already executing.
@findex Inferior.clear_env
@defun Inferior.clear_env ()
Clear the current environment variables that will be passed to this
inferior.
@end defun
@findex Inferior.set_env
@defun Inferior.set_env (name, value)
Set the environment variable @var{name} to have the indicated value.
Both parameters must be strings.
@end defun
@findex Inferior.unset_env
@defun Inferior.unset_env (name)
Unset the environment variable @var{name}. @var{name} must be a
string.
@end defun
@node Events In Python
@subsubsection Events In Python
@cindex inferior events in Python