Add basic Python API for convenience variables

This adds a basic Python API for accessing convenience variables.
With this, convenience variables can be read and set from Python.
Although gdb supports convenience variables whose value changes at
each call, this is not exposed to Python; it could be, but I think
it's just as good to write a convenience function in this situation.

This is PR python/23080.

Tested on x86-64 Fedora 26.

2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* NEWS: Update for new functions.
	* python/py-value.c (gdbpy_set_convenience_variable)
	(gdbpy_convenience_variable): New functions.
	* python/python-internal.h (gdbpy_convenience_variable)
	(gdbpy_set_convenience_variable): Declare.
	* python/python.c (python_GdbMethods): Add convenience_variable,
	set_convenience_variable.

doc/ChangeLog
2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* python.texi (Basic Python): Document gdb.convenience_variable,
	gdb.set_convenience_variable.

testsuite/ChangeLog
2018-04-22  Tom Tromey  <tom@tromey.com>

	PR python/23080:
	* gdb.python/python.exp: Add convenience variable tests.
This commit is contained in:
Tom Tromey
2018-04-22 15:13:09 -06:00
parent 8a60efe714
commit 7729052b53
6 changed files with 132 additions and 2 deletions

View File

@ -477,3 +477,23 @@ gdb_py_test_silent_cmd "step" "Step into func2" 1
gdb_py_test_silent_cmd "up" "Step out of func2" 1
gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line > line)" "True" "test find_pc_line with resume address"
gdb_test_no_output "set variable \$cvar1 = 23" "set convenience variable"
gdb_test "python print(gdb.convenience_variable('cvar1'))" "23"
gdb_test "python print(gdb.convenience_variable('cvar2'))" "None"
gdb_test_no_output "python gdb.set_convenience_variable('cvar1', 89)" \
"change convenience variable from python"
gdb_test "python print(gdb.convenience_variable('cvar1'))" "89" \
"print new value of convenience variable from python"
gdb_test "print \$cvar1" " = 89" \
"print new value of convenience variable from CLI"
gdb_test_no_output "python gdb.set_convenience_variable('cvar3', -5)" \
"make convenience variable from python"
gdb_test "python print(gdb.convenience_variable('cvar3'))" "-5" \
"print value of new convenience variable from python"
gdb_test_no_output "python gdb.set_convenience_variable('cvar3', None)" \
"reset convenience variable from python"
gdb_test "python print(gdb.convenience_variable('cvar3'))" "None" \
"print reset convenience variable from python"
gdb_test "print \$cvar3" "= void" \
"print reset convenience variable from CLI"