aboutsummaryrefslogtreecommitdiff
path: root/gdb/contrib
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/contrib
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/contrib')
-rw-r--r--gdb/contrib/test_pubnames_and_indexes.py303
1 files changed, 160 insertions, 143 deletions
diff --git a/gdb/contrib/test_pubnames_and_indexes.py b/gdb/contrib/test_pubnames_and_indexes.py
index 67e2430..cc767a2 100644
--- a/gdb/contrib/test_pubnames_and_indexes.py
+++ b/gdb/contrib/test_pubnames_and_indexes.py
@@ -39,7 +39,7 @@ to those that gdb produces.
Finally, check that all strings are canonicalized identically.
"""
-__author__ = 'saugustine@google.com (Sterling Augustine)'
+__author__ = "saugustine@google.com (Sterling Augustine)"
import os
import subprocess
@@ -49,159 +49,176 @@ OBJCOPY = None
READELF = None
GDB = None
+
def get_pub_info(filename, readelf_option):
- """Parse and return all the pubnames or pubtypes produced by readelf with the
- given option.
- """
- readelf = subprocess.Popen([READELF, '--debug-dump=' + readelf_option,
- filename], stdout=subprocess.PIPE)
- pubnames = []
-
- in_list = False;
- for line in readelf.stdout:
- fields = line.split(None, 1)
- if (len(fields) == 2 and fields[0] == 'Offset'
- and fields[1].strip() == 'Name'):
- in_list = True
- # Either a blank-line or a new Length field terminates the current section.
- elif (len(fields) == 0 or fields[0] == 'Length:'):
- in_list = False;
- elif (in_list):
- pubnames.append(fields[1].strip())
-
- readelf.wait()
- return pubnames
+ """Parse and return all the pubnames or pubtypes produced by readelf with the
+ given option.
+ """
+ readelf = subprocess.Popen(
+ [READELF, "--debug-dump=" + readelf_option, filename], stdout=subprocess.PIPE
+ )
+ pubnames = []
+
+ in_list = False
+ for line in readelf.stdout:
+ fields = line.split(None, 1)
+ if len(fields) == 2 and fields[0] == "Offset" and fields[1].strip() == "Name":
+ in_list = True
+ # Either a blank-line or a new Length field terminates the current section.
+ elif len(fields) == 0 or fields[0] == "Length:":
+ in_list = False
+ elif in_list:
+ pubnames.append(fields[1].strip())
+
+ readelf.wait()
+ return pubnames
def get_gdb_index(filename):
- """Use readelf to dump the gdb index and collect the types and names"""
- readelf = subprocess.Popen([READELF, '--debug-dump=gdb_index',
- filename], stdout=subprocess.PIPE)
- index_symbols = []
- symbol_table_started = False
- for line in readelf.stdout:
- if (line == 'Symbol table:\n'):
- symbol_table_started = True;
- elif (symbol_table_started):
- # Readelf prints gdb-index lines formatted like so:
- # [ 4] two::c2<double>::c2: 0
- # So take the string between the first close bracket and the last colon.
- index_symbols.append(line[line.find(']') + 2: line.rfind(':')])
-
- readelf.wait()
- return index_symbols
+ """Use readelf to dump the gdb index and collect the types and names"""
+ readelf = subprocess.Popen(
+ [READELF, "--debug-dump=gdb_index", filename], stdout=subprocess.PIPE
+ )
+ index_symbols = []
+ symbol_table_started = False
+ for line in readelf.stdout:
+ if line == "Symbol table:\n":
+ symbol_table_started = True
+ elif symbol_table_started:
+ # Readelf prints gdb-index lines formatted like so:
+ # [ 4] two::c2<double>::c2: 0
+ # So take the string between the first close bracket and the last colon.
+ index_symbols.append(line[line.find("]") + 2 : line.rfind(":")])
+
+ readelf.wait()
+ return index_symbols
def CheckSets(list0, list1, name0, name1):
- """Report any setwise differences between the two lists"""
-
- if len(list0) == 0 or len(list1) == 0:
+ """Report any setwise differences between the two lists"""
+
+ if len(list0) == 0 or len(list1) == 0:
+ return False
+
+ difference0 = set(list0) - set(list1)
+ if len(difference0) != 0:
+ print "Elements in " + name0 + " but not " + name1 + ": (",
+ print len(difference0),
+ print ")"
+ for element in difference0:
+ print " " + element
+
+ difference1 = set(list1) - set(list0)
+ if len(difference1) != 0:
+ print "Elements in " + name1 + " but not " + name0 + ": (",
+ print len(difference1),
+ print ")"
+ for element in difference1:
+ print " " + element
+
+ if len(difference0) != 0 or len(difference1) != 0:
+ return True
+
+ print name0 + " and " + name1 + " are identical."
return False
- difference0 = set(list0) - set(list1)
- if len(difference0) != 0:
- print "Elements in " + name0 + " but not " + name1 + ": (",
- print len(difference0),
- print ")"
- for element in difference0:
- print " " + element
-
- difference1 = set(list1) - set(list0)
- if len(difference1) != 0:
- print "Elements in " + name1 + " but not " + name0 + ": (",
- print len(difference1),
- print ")"
- for element in difference1:
- print " " + element
-
- if (len(difference0) != 0 or len(difference1) != 0):
- return True
-
- print name0 + " and " + name1 + " are identical."
- return False
-
def find_executables():
- """Find the copies of readelf, objcopy and gdb to use."""
- # Executable finding logic follows cc-with-index.sh
- global READELF
- READELF = os.getenv('READELF')
- if READELF is None:
- READELF = 'readelf'
- global OBJCOPY
- OBJCOPY = os.getenv('OBJCOPY')
- if OBJCOPY is None:
- OBJCOPY = 'objcopy'
-
- global GDB
- GDB = os.getenv('GDB')
- if (GDB is None):
- if os.path.isfile('./gdb') and os.access('./gdb', os.X_OK):
- GDB = './gdb'
- elif os.path.isfile('../gdb') and os.access('../gdb', os.X_OK):
- GDB = '../gdb'
- elif os.path.isfile('../../gdb') and os.access('../../gdb', os.X_OK):
- GDB = '../../gdb'
- else:
- # Punt and use the gdb in the path.
- GDB = 'gdb'
+ """Find the copies of readelf, objcopy and gdb to use."""
+ # Executable finding logic follows cc-with-index.sh
+ global READELF
+ READELF = os.getenv("READELF")
+ if READELF is None:
+ READELF = "readelf"
+ global OBJCOPY
+ OBJCOPY = os.getenv("OBJCOPY")
+ if OBJCOPY is None:
+ OBJCOPY = "objcopy"
+
+ global GDB
+ GDB = os.getenv("GDB")
+ if GDB is None:
+ if os.path.isfile("./gdb") and os.access("./gdb", os.X_OK):
+ GDB = "./gdb"
+ elif os.path.isfile("../gdb") and os.access("../gdb", os.X_OK):
+ GDB = "../gdb"
+ elif os.path.isfile("../../gdb") and os.access("../../gdb", os.X_OK):
+ GDB = "../../gdb"
+ else:
+ # Punt and use the gdb in the path.
+ GDB = "gdb"
def main(argv):
- """The main subprogram."""
- if len(argv) != 2:
- print "Usage: test_pubnames_and_indexes.py <filename>"
- sys.exit(2)
-
- find_executables();
-
- # Get the index produced by Gold--It should have been built into the binary.
- gold_index = get_gdb_index(argv[1])
-
- # Collect the pubnames and types list
- pubs_list = get_pub_info(argv[1], "pubnames")
- pubs_list = pubs_list + get_pub_info(argv[1], "pubtypes")
-
- # Generate a .gdb_index with gdb
- gdb_index_file = argv[1] + '.gdb-generated-index'
- subprocess.check_call([OBJCOPY, '--remove-section', '.gdb_index',
- argv[1], gdb_index_file])
- subprocess.check_call([GDB, '-batch', '-nx', gdb_index_file,
- '-ex', 'save gdb-index ' + os.path.dirname(argv[1]),
- '-ex', 'quit'])
- subprocess.check_call([OBJCOPY, '--add-section',
- '.gdb_index=' + gdb_index_file + '.gdb-index',
- gdb_index_file])
- gdb_index = get_gdb_index(gdb_index_file)
- os.remove(gdb_index_file)
- os.remove(gdb_index_file + '.gdb-index')
-
- failed = False
- gdb_index.sort()
- gold_index.sort()
- pubs_list.sort()
-
- # Find the differences between the various indices.
- if len(gold_index) == 0:
- print "Gold index is empty"
- failed |= True
-
- if len(gdb_index) == 0:
- print "Gdb index is empty"
- failed |= True
-
- if len(pubs_list) == 0:
- print "Pubs list is empty"
- failed |= True
-
- failed |= CheckSets(gdb_index, gold_index, "gdb index", "gold index")
- failed |= CheckSets(pubs_list, gold_index, "pubs list", "gold index")
- failed |= CheckSets(pubs_list, gdb_index, "pubs list", "gdb index")
-
- if failed:
- print "Test failed"
- sys.exit(1)
-
-
-if __name__ == '__main__':
- main(sys.argv)
+ """The main subprogram."""
+ if len(argv) != 2:
+ print "Usage: test_pubnames_and_indexes.py <filename>"
+ sys.exit(2)
+
+ find_executables()
+
+ # Get the index produced by Gold--It should have been built into the binary.
+ gold_index = get_gdb_index(argv[1])
+
+ # Collect the pubnames and types list
+ pubs_list = get_pub_info(argv[1], "pubnames")
+ pubs_list = pubs_list + get_pub_info(argv[1], "pubtypes")
+
+ # Generate a .gdb_index with gdb
+ gdb_index_file = argv[1] + ".gdb-generated-index"
+ subprocess.check_call(
+ [OBJCOPY, "--remove-section", ".gdb_index", argv[1], gdb_index_file]
+ )
+ subprocess.check_call(
+ [
+ GDB,
+ "-batch",
+ "-nx",
+ gdb_index_file,
+ "-ex",
+ "save gdb-index " + os.path.dirname(argv[1]),
+ "-ex",
+ "quit",
+ ]
+ )
+ subprocess.check_call(
+ [
+ OBJCOPY,
+ "--add-section",
+ ".gdb_index=" + gdb_index_file + ".gdb-index",
+ gdb_index_file,
+ ]
+ )
+ gdb_index = get_gdb_index(gdb_index_file)
+ os.remove(gdb_index_file)
+ os.remove(gdb_index_file + ".gdb-index")
+
+ failed = False
+ gdb_index.sort()
+ gold_index.sort()
+ pubs_list.sort()
+
+ # Find the differences between the various indices.
+ if len(gold_index) == 0:
+ print "Gold index is empty"
+ failed |= True
+
+ if len(gdb_index) == 0:
+ print "Gdb index is empty"
+ failed |= True
+
+ if len(pubs_list) == 0:
+ print "Pubs list is empty"
+ failed |= True
+
+ failed |= CheckSets(gdb_index, gold_index, "gdb index", "gold index")
+ failed |= CheckSets(pubs_list, gold_index, "pubs list", "gold index")
+ failed |= CheckSets(pubs_list, gdb_index, "pubs list", "gdb index")
+
+ if failed:
+ print "Test failed"
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ main(sys.argv)