diff options
author | Tom de Vries <tdevries@suse.de> | 2024-12-03 22:49:40 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-12-03 22:49:40 +0100 |
commit | 348290c7ef4b731f3ff851d7922d038e671fea4a (patch) | |
tree | ae58e99cd97f9d0b3818119057ffceb3142a7d22 /gdb/testsuite/gdb.python/py-missing-objfile.c | |
parent | c9b37bc99776dd69ac0e53a1cf4829137fb69cce (diff) | |
download | binutils-348290c7ef4b731f3ff851d7922d038e671fea4a.zip binutils-348290c7ef4b731f3ff851d7922d038e671fea4a.tar.gz binutils-348290c7ef4b731f3ff851d7922d038e671fea4a.tar.bz2 |
[gdb/python] Warn and ignore ineffective python settings
Configuration flags "python dont-write-bytecode" and
"python ignore-environment" have effect only at Python initialization.
For instance, setting "python dont-write-bytecode" here has no effect:
...
$ gdb -q
(gdb) show python dont-write-bytecode
Python's dont-write-bytecode setting is auto (currently off).
(gdb) python import sys
(gdb) python print (sys.dont_write_bytecode)
False
(gdb) set python dont-write-bytecode on
(gdb) python print (sys.dont_write_bytecode)
False
...
This is not clear in the code: we set Py_DontWriteBytecodeFlag and
Py_IgnoreEnvironmentFlag in set_python_ignore_environment and
set_python_dont_write_bytecode. Fix this by moving the setting of those
variables to py_initialization.
Furthermore, this is not clear to the user: after Python initialization, the
user can still modify the configuration flags, and observe the changed setting:
...
$ gdb -q
(gdb) show python ignore-environment
Python's ignore-environment setting is off.
(gdb) set python ignore-environment on
(gdb) show python ignore-environment
Python's ignore-environment setting is on.
(gdb)
...
Fix this by emitting a warning when trying to set these configuration flags
after Python initialization:
...
$ gdb -q
(gdb) set python ignore-environment on
warning: Setting python ignore-environment after Python initialization has \
no effect, try setting this during early initialization
(gdb) set python dont-write-bytecode on
warning: Setting python dont-write-bytecode after Python initialization has \
no effect, try setting this during early initialization, or try setting \
sys.dont_write_bytecode
...
and by keeping the values constant after Python initialization.
Since the auto setting for python dont-write-bytecode depends on the current
value of environment variable PYTHONDONTWRITEBYTECODE, we simply avoid it
after Python initialization:
...
$ gdb -q -batch \
-eiex "show python dont-write-bytecode" \
-iex "show python dont-write-bytecode"
Python's dont-write-bytecode setting is auto (currently off).
Python's dont-write-bytecode setting is off.
...
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR python/32388
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32388
Diffstat (limited to 'gdb/testsuite/gdb.python/py-missing-objfile.c')
0 files changed, 0 insertions, 0 deletions