Files
binutils-gdb/gdb/testsuite/gdb.python/py-unwind-inline.py
Lancelot SIX f9e59d060f Use is/is not to check for None in python code.
While reviewing a patch sent to the mailing list, I noticed there are few
places where python code checks if a variable is 'None' or not by using the
comparison operators '==' and '!='.  PEP8[1], which is used as coding standard
in GDB coding standards, recommends using 'is' / 'is not' when comparing to a
singleton such as 'None'.

This patch proposes to change the instances of '== None' by 'is None' and
'!= None' by 'is not None'.

[1] https://www.python.org/dev/peps/pep-0008/

gdb/doc/ChangeLog:

	* python.texi (Writing a Pretty-Printer): Use 'is None' instead of
	'== None'.

gdb/ChangeLog:

	* python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None' instead of
	'== None'.
	(FrameVars): Use 'is not None' instead of '!= None'.
	* python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority): Use 'is None'
	instead of '== None' and 'is not None' instead of '!= None'.

gdb/testsuite/ChangeLog:

	* gdb.base/premature-dummy-frame-removal.py (TestUnwinder): Use
	'is None' instead of '== None' and 'is not None' instead of
	'!= None'.
	* gdb.python/py-frame-args.py (lookup_function): Same.
	* gdb.python/py-framefilter-invalidarg.py (Reverse_Function): Same.
	* gdb.python/py-framefilter.py (Reverse_Function): Same.
	* gdb.python/py-nested-maps.py (lookup_function): Same.
	* gdb.python/py-objfile-script-gdb.py (lookup_function): Same.
	* gdb.python/py-prettyprint.py (lookup_function): Same.
	* gdb.python/py-section-script.py (lookup_function): Same.
	* gdb.python/py-unwind-inline.py (dummy_unwinder): Same.
	* gdb.python/python.exp: Same.
	* gdb.rust/pp.py (lookup_function): Same.
2021-06-08 23:49:05 +01:00

73 lines
2.4 KiB
Python

# Copyright (C) 2020-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A dummy stack unwinder used for testing the Python unwinders when we
# have inline frames. This unwinder will never claim any frames,
# instead, all it does it try to read all registers possible target
# registers as part of the frame sniffing process..
import gdb
from gdb.unwinder import Unwinder
apb_global = None
class dummy_unwinder(Unwinder):
"""A dummy unwinder that looks at a bunch of registers as part of
the unwinding process."""
class frame_id(object):
"""Basic frame id."""
def __init__(self, sp, pc):
"""Create the frame id."""
self.sp = sp
self.pc = pc
def __init__(self):
"""Create the unwinder."""
Unwinder.__init__(self, "dummy stack unwinder")
self.void_ptr_t = gdb.lookup_type("void").pointer()
self.regs = None
def get_regs(self, pending_frame):
"""Return a list of register names that should be read. Only
gathers the list once, then caches the result."""
if self.regs is not None:
return self.regs
# Collect the names of all registers to read.
self.regs = list(pending_frame.architecture().register_names())
return self.regs
def __call__(self, pending_frame):
"""Actually performs the unwind, or at least sniffs this frame
to see if the unwinder should claim it, which is never does."""
try:
for r in self.get_regs(pending_frame):
v = pending_frame.read_register(r).cast(self.void_ptr_t)
except:
print("Dummy unwinder, exception")
raise
return None
# Register the ComRV stack unwinder.
gdb.unwinder.register_unwinder(None, dummy_unwinder(), True)
print("Python script imported")