aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-xmethods.py
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-07 10:56:20 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-07 10:56:20 -0400
commit13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d (patch)
treeec33a85ccb58f44445608d0cab68020fa588cb74 /gdb/testsuite/gdb.python/py-xmethods.py
parenta9b49cbcd5935a713da5715799ea3b24e0a52851 (diff)
downloadgdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.zip
gdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.tar.gz
gdb-13123da89a2c7e06a5312ca6b4b24c68ba1c6c2d.tar.bz2
gdb: re-format Python files using black 21.4b0
Re-format all Python files using black [1] version 21.4b0. The goal is that from now on, we keep all Python files formatted using black. And that we never have to discuss formatting during review (for these files at least) ever again. One change is needed in gdb.python/py-prettyprint.exp, because it matches the string representation of an exception, which shows source code. So the change in formatting must be replicated in the expected regexp. To document our usage of black I plan on adding this to the "GDB Python Coding Standards" wiki page [2]: --8<-- All Python source files under the `gdb/` directory must be formatted using black version 21.4b0. This specific version can be installed using: $ pip3 install 'black == 21.4b0' All you need to do to re-format files is run `black <file/directory>`, and black will re-format any Python file it finds in there. It runs quite fast, so the simplest is to do: $ black gdb/ from the top-level. If you notice that black produces changes unrelated to your patch, it's probably because someone forgot to run it before you. In this case, don't include unrelated hunks in your patch. Push an obvious patch fixing the formatting and rebase your work on top of that. -->8-- Once this is merged, I plan on setting a up an `ignoreRevsFile` config so that git-blame ignores this commit, as described here: https://github.com/psf/black#migrating-your-code-style-without-ruining-git-blame I also plan on working on a git commit hook (checked in the repo) to automatically check the formatting of the Python files on commit. [1] https://pypi.org/project/black/ [2] https://sourceware.org/gdb/wiki/Internals%20GDB-Python-Coding-Standards gdb/ChangeLog: * Re-format all Python files using black. gdb/testsuite/ChangeLog: * Re-format all Python files using black. * gdb.python/py-prettyprint.exp (run_lang_tests): Adjust. Change-Id: I28588a22c2406afd6bc2703774ddfff47cd61919
Diffstat (limited to 'gdb/testsuite/gdb.python/py-xmethods.py')
-rw-r--r--gdb/testsuite/gdb.python/py-xmethods.py136
1 files changed, 62 insertions, 74 deletions
diff --git a/gdb/testsuite/gdb.python/py-xmethods.py b/gdb/testsuite/gdb.python/py-xmethods.py
index 7bfd190..1df3bd0 100644
--- a/gdb/testsuite/gdb.python/py-xmethods.py
+++ b/gdb/testsuite/gdb.python/py-xmethods.py
@@ -25,52 +25,55 @@ from gdb.xmethod import SimpleXMethodMatcher
def A_plus_A(obj, opr):
- print('From Python <A_plus_A>:')
- return obj['a'] + opr['a']
+ print("From Python <A_plus_A>:")
+ return obj["a"] + opr["a"]
def plus_plus_A(obj):
- print('From Python <plus_plus_A>:')
- return obj['a'] + 1
+ print("From Python <plus_plus_A>:")
+ return obj["a"] + 1
def A_geta(obj):
- print('From Python <A_geta>:')
- return obj['a']
+ print("From Python <A_geta>:")
+ return obj["a"]
def A_getarrayind(obj, index):
- print('From Python <A_getarrayind>:')
- return obj['array'][index]
+ print("From Python <A_getarrayind>:")
+ return obj["array"][index]
+
def A_indexoper(obj, index):
- return obj['array'][index].reference_value()
+ return obj["array"][index].reference_value()
+
def B_indexoper(obj, index):
- return obj['array'][index].const_value().reference_value()
+ return obj["array"][index].const_value().reference_value()
-type_A = gdb.parse_and_eval('(dop::A *) 0').type.target()
-type_B = gdb.parse_and_eval('(dop::B *) 0').type.target()
-type_int = gdb.parse_and_eval('(int *) 0').type.target()
+type_A = gdb.parse_and_eval("(dop::A *) 0").type.target()
+type_B = gdb.parse_and_eval("(dop::B *) 0").type.target()
+type_int = gdb.parse_and_eval("(int *) 0").type.target()
# The E class matcher and worker test two things:
# 1. xmethod returning None.
# 2. Matcher returning a list of workers.
+
class E_method_char_worker(XMethodWorker):
def __init__(self):
pass
def get_arg_types(self):
- return gdb.lookup_type('char')
+ return gdb.lookup_type("char")
def get_result_type(self, obj, arg):
- return gdb.lookup_type('void')
+ return gdb.lookup_type("void")
def __call__(self, obj, arg):
- print('From Python <E_method_char>')
+ print("From Python <E_method_char>")
return None
@@ -79,25 +82,25 @@ class E_method_int_worker(XMethodWorker):
pass
def get_arg_types(self):
- return gdb.lookup_type('int')
+ return gdb.lookup_type("int")
# Note: get_result_type method elided on purpose
def __call__(self, obj, arg):
- print('From Python <E_method_int>')
+ print("From Python <E_method_int>")
return None
class E_method_matcher(XMethodMatcher):
def __init__(self):
- XMethodMatcher.__init__(self, 'E_methods')
- self.methods = [XMethod('method_int'), XMethod('method_char')]
+ XMethodMatcher.__init__(self, "E_methods")
+ self.methods = [XMethod("method_int"), XMethod("method_char")]
def match(self, class_type, method_name):
class_tag = class_type.unqualified().tag
- if not re.match('^dop::E$', class_tag):
+ if not re.match("^dop::E$", class_tag):
return None
- if not re.match('^method$', method_name):
+ if not re.match("^method$", method_name):
return None
workers = []
if self.methods[0].enabled:
@@ -111,6 +114,7 @@ class E_method_matcher(XMethodMatcher):
# xmethod matchers and workers for template classes and template
# methods.
+
class G_size_diff_worker(XMethodWorker):
def __init__(self, class_template_type, method_template_type):
self._class_template_type = class_template_type
@@ -120,9 +124,8 @@ class G_size_diff_worker(XMethodWorker):
pass
def __call__(self, obj):
- print('From Python G<>::size_diff()')
- return (self._method_template_type.sizeof -
- self._class_template_type.sizeof)
+ print("From Python G<>::size_diff()")
+ return self._method_template_type.sizeof - self._class_template_type.sizeof
class G_size_mul_worker(XMethodWorker):
@@ -134,7 +137,7 @@ class G_size_mul_worker(XMethodWorker):
pass
def __call__(self, obj):
- print('From Python G<>::size_mul()')
+ print("From Python G<>::size_mul()")
return self._class_template_type.sizeof * self._method_template_val
@@ -147,16 +150,14 @@ class G_mul_worker(XMethodWorker):
return self._method_template_type
def __call__(self, obj, arg):
- print('From Python G<>::mul()')
- return obj['t'] * arg
+ print("From Python G<>::mul()")
+ return obj["t"] * arg
class G_methods_matcher(XMethodMatcher):
def __init__(self):
- XMethodMatcher.__init__(self, 'G_methods')
- self.methods = [XMethod('size_diff'),
- XMethod('size_mul'),
- XMethod('mul')]
+ XMethodMatcher.__init__(self, "G_methods")
+ self.methods = [XMethod("size_diff"), XMethod("size_mul"), XMethod("mul")]
def _is_enabled(self, name):
for method in self.methods:
@@ -165,16 +166,15 @@ class G_methods_matcher(XMethodMatcher):
def match(self, class_type, method_name):
class_tag = class_type.unqualified().tag
- if not re.match('^dop::G<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$',
- class_tag):
+ if not re.match("^dop::G<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$", class_tag):
return None
t_name = class_tag[7:-1]
try:
t_type = gdb.lookup_type(t_name)
except gdb.error:
return None
- if re.match('^size_diff<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$', method_name):
- if not self._is_enabled('size_diff'):
+ if re.match("^size_diff<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$", method_name):
+ if not self._is_enabled("size_diff"):
return None
t1_name = method_name[10:-1]
try:
@@ -182,13 +182,13 @@ class G_methods_matcher(XMethodMatcher):
return G_size_diff_worker(t_type, t1_type)
except gdb.error:
return None
- if re.match('^size_mul<[ ]*[0-9]+[ ]*>$', method_name):
- if not self._is_enabled('size_mul'):
+ if re.match("^size_mul<[ ]*[0-9]+[ ]*>$", method_name):
+ if not self._is_enabled("size_mul"):
return None
m_val = int(method_name[9:-1])
return G_size_mul_worker(t_type, m_val)
- if re.match('^mul<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$', method_name):
- if not self._is_enabled('mul'):
+ if re.match("^mul<[ ]*[_a-zA-Z][ _a-zA-Z0-9]*>$", method_name):
+ if not self._is_enabled("mul"):
return None
t1_name = method_name[4:-1]
try:
@@ -199,41 +199,29 @@ class G_methods_matcher(XMethodMatcher):
global_dm_list = [
- SimpleXMethodMatcher(r'A_plus_A',
- r'^dop::A$',
- r'operator\+',
- A_plus_A,
- # This is a replacement, hence match the arg type
- # exactly!
- type_A.const().reference()),
- SimpleXMethodMatcher(r'plus_plus_A',
- r'^dop::A$',
- r'operator\+\+',
- plus_plus_A),
- SimpleXMethodMatcher(r'A_geta',
- r'^dop::A$',
- r'^geta$',
- A_geta),
- SimpleXMethodMatcher(r'A_getarrayind',
- r'^dop::A$',
- r'^getarrayind$',
- A_getarrayind,
- type_int),
- SimpleXMethodMatcher(r'A_indexoper',
- r'^dop::A$',
- r'operator\[\]',
- A_indexoper,
- type_int),
- SimpleXMethodMatcher(r'B_indexoper',
- r'^dop::B$',
- r'operator\[\]',
- B_indexoper,
- type_int)
+ SimpleXMethodMatcher(
+ r"A_plus_A",
+ r"^dop::A$",
+ r"operator\+",
+ A_plus_A,
+ # This is a replacement, hence match the arg type
+ # exactly!
+ type_A.const().reference(),
+ ),
+ SimpleXMethodMatcher(r"plus_plus_A", r"^dop::A$", r"operator\+\+", plus_plus_A),
+ SimpleXMethodMatcher(r"A_geta", r"^dop::A$", r"^geta$", A_geta),
+ SimpleXMethodMatcher(
+ r"A_getarrayind", r"^dop::A$", r"^getarrayind$", A_getarrayind, type_int
+ ),
+ SimpleXMethodMatcher(
+ r"A_indexoper", r"^dop::A$", r"operator\[\]", A_indexoper, type_int
+ ),
+ SimpleXMethodMatcher(
+ r"B_indexoper", r"^dop::B$", r"operator\[\]", B_indexoper, type_int
+ ),
]
for matcher in global_dm_list:
gdb.xmethod.register_xmethod_matcher(gdb, matcher)
-gdb.xmethod.register_xmethod_matcher(gdb.current_progspace(),
- G_methods_matcher())
-gdb.xmethod.register_xmethod_matcher(gdb.current_progspace(),
- E_method_matcher())
+gdb.xmethod.register_xmethod_matcher(gdb.current_progspace(), G_methods_matcher())
+gdb.xmethod.register_xmethod_matcher(gdb.current_progspace(), E_method_matcher())