aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-01-04 11:00:52 -0700
committerTom Tromey <tromey@adacore.com>2022-01-26 06:49:51 -0700
commitb583c328e71369f90f4042ac7973ce9edfdb44b3 (patch)
tree3ed1cfd9763fe4984c72d204113f3b166e47d011 /gdb/doc
parentdedb7102b3b35f789fd5c140fe01917eaeae2853 (diff)
downloadgdb-b583c328e71369f90f4042ac7973ce9edfdb44b3.zip
gdb-b583c328e71369f90f4042ac7973ce9edfdb44b3.tar.gz
gdb-b583c328e71369f90f4042ac7973ce9edfdb44b3.tar.bz2
Add a way to temporarily set a gdb parameter from Python
It's sometimes useful to temporarily set some gdb parameter from Python. Now that the 'endian' crash is fixed, and now that the current language is no longer captured by the Python layer, it seems reasonable to add a helper function for this situation. This adds a new gdb.with_parameter function. This creates a context manager which temporarily sets some parameter to a specified value. The old value is restored when the context is exited. This is most useful with the Python "with" statement: with gdb.with_parameter('language', 'ada'): ... do Ada stuff This also adds a simple function to set a parameter, gdb.set_parameter, as suggested by Andrew. This is PR python/10790. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=10790
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/python.texi26
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index f02380a..39bf6e8 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -332,6 +332,32 @@ parameter's value is converted to a Python value of the appropriate
type, and returned.
@end defun
+@findex gdb.set_parameter
+@defun gdb.set_parameter (name, value)
+Sets the gdb parameter @var{name} to @var{value}. As with
+@code{gdb.parameter}, the parameter name string may contain spaces if
+the parameter has a multi-part name.
+@end defun
+
+@findex gdb.with_parameter
+@defun gdb.with_parameter (name, value)
+Create a Python context manager (for use with the Python
+@command{with} statement) that temporarily sets the gdb parameter
+@var{name} to @var{value}. On exit from the context, the previous
+value will be restored.
+
+This uses @code{gdb.parameter} in its implementation, so it can throw
+the same exceptions as that function.
+
+For example, it's sometimes useful to evaluate some Python code with a
+particular gdb language:
+
+@smallexample
+with gdb.with_parameter('language', 'pascal'):
+ ... language-specific operations
+@end smallexample
+@end defun
+
@findex gdb.history
@defun gdb.history (number)
Return a value from @value{GDBN}'s value history (@pxref{Value