31"""test_pubnames_and_indexes.py
33Test that the gdb_index produced by gold is identical to the gdb_index
34produced by gdb itself.
36Further check that the pubnames and pubtypes produced by gcc are identical
37to those that gdb produces.
39Finally, check that all strings are canonicalized identically.
42__author__ =
"saugustine@google.com (Sterling Augustine)"
54 """Parse and return all the pubnames or pubtypes produced by readelf with the
57 readelf = subprocess.Popen(
58 [READELF, "--debug-dump=" + readelf_option, filename], stdout=subprocess.PIPE
63 for line
in readelf.stdout:
64 fields = line.split(
None, 1)
65 if len(fields) == 2
and fields[0] ==
"Offset" and fields[1].strip() ==
"Name":
68 elif len(fields) == 0
or fields[0] ==
"Length:":
71 pubnames.append(fields[1].strip())
78 """Use readelf to dump the gdb index and collect the types and names"""
79 readelf = subprocess.Popen(
80 [READELF,
"--debug-dump=gdb_index", filename], stdout=subprocess.PIPE
83 symbol_table_started =
False
84 for line
in readelf.stdout:
85 if line ==
"Symbol table:\n":
86 symbol_table_started =
True
87 elif symbol_table_started:
91 index_symbols.append(line[line.find(
"]") + 2 : line.rfind(
":")])
98 """Report any setwise differences between the two lists"""
100 if len(list0) == 0
or len(list1) == 0:
103 difference0 = set(list0) - set(list1)
104 if len(difference0) != 0:
105 print(
"Elements in " + name0 +
" but not " + name1 +
": (", end=
" ")
106 print(len(difference0), end=
" ")
108 for element
in difference0:
111 difference1 = set(list1) - set(list0)
112 if len(difference1) != 0:
113 print(
"Elements in " + name1 +
" but not " + name0 +
": (", end=
" ")
114 print(len(difference1), end=
" ")
116 for element
in difference1:
119 if len(difference0) != 0
or len(difference1) != 0:
122 print(name0 +
" and " + name1 +
" are identical.")
127 """Find the copies of readelf, objcopy and gdb to use."""
130 READELF = os.getenv(
"READELF")
134 OBJCOPY = os.getenv(
"OBJCOPY")
139 GDB = os.getenv(
"GDB")
141 if os.path.isfile(
"./gdb")
and os.access(
"./gdb", os.X_OK):
143 elif os.path.isfile(
"../gdb")
and os.access(
"../gdb", os.X_OK):
145 elif os.path.isfile(
"../../gdb")
and os.access(
"../../gdb", os.X_OK):
153 """The main subprogram."""
155 print(
"Usage: test_pubnames_and_indexes.py <filename>")
165 pubs_list = pubs_list +
get_pub_info(argv[1],
"pubtypes")
168 gdb_index_file = argv[1] +
".gdb-generated-index"
169 subprocess.check_call(
170 [OBJCOPY,
"--remove-section",
".gdb_index", argv[1], gdb_index_file]
172 subprocess.check_call(
179 "save gdb-index " + os.path.dirname(argv[1]),
184 subprocess.check_call(
188 ".gdb_index=" + gdb_index_file +
".gdb-index",
193 os.remove(gdb_index_file)
194 os.remove(gdb_index_file +
".gdb-index")
202 if len(gold_index) == 0:
203 print(
"Gold index is empty")
206 if len(gdb_index) == 0:
207 print(
"Gdb index is empty")
210 if len(pubs_list) == 0:
211 print(
"Pubs list is empty")
214 failed |=
CheckSets(gdb_index, gold_index,
"gdb index",
"gold index")
215 failed |=
CheckSets(pubs_list, gold_index,
"pubs list",
"gold index")
216 failed |=
CheckSets(pubs_list, gdb_index,
"pubs list",
"gdb index")
223if __name__ ==
"__main__":
get_pub_info(filename, readelf_option)
CheckSets(list0, list1, name0, name1)