gdb: add pyproject.toml

When running black to format Python files, files with extension .py.in
are ignored, because they don't end in .py.  Add a pyproject.toml file
to instruct black to pick up these files too.

gdb/ChangeLog:

	* py-project.toml: New.
	* gdb-gdb.py.in: Re-format.

gdb/testsuite/ChangeLog:

	* gdb.python/py-framefilter-gdb.py.in: Re-format.
	* gdb.python/py-framefilter-invalidarg-gdb.py.in: Re-format.

Change-Id: I9b88faec3360ea24788f44c8b89fe0b2a5f4eb97
This commit is contained in:
Simon Marchi
2021-05-17 14:31:00 -04:00
parent 034dce7a47
commit 91e159e93b
6 changed files with 117 additions and 99 deletions

View File

@ -1,3 +1,8 @@
2021-05-17 Simon Marchi <simon.marchi@polymtl.ca>
* py-project.toml: New.
* gdb-gdb.py.in: Re-format.
2021-05-17 Simon Marchi <simon.marchi@polymtl.ca> 2021-05-17 Simon Marchi <simon.marchi@polymtl.ca>
* cli/cli-decode.h (cmd_list_element) <is_command_class_help>: * cli/cli-decode.h (cmd_list_element) <is_command_class_help>:

View File

@ -39,7 +39,7 @@ class TypeFlag:
def __init__(self, name, value): def __init__(self, name, value):
self.name = name self.name = name
self.value = value self.value = value
self.short_name = name.replace("TYPE_INSTANCE_FLAG_", '') self.short_name = name.replace("TYPE_INSTANCE_FLAG_", "")
def __lt__(self, other): def __lt__(self, other):
"""Sort by value order.""" """Sort by value order."""
@ -73,8 +73,9 @@ class TypeFlagsPrinter:
if not self.val: if not self.val:
return "0" return "0"
if TYPE_FLAGS: if TYPE_FLAGS:
flag_list = [flag.short_name for flag in TYPE_FLAGS flag_list = [
if self.val & flag.value] flag.short_name for flag in TYPE_FLAGS if self.val & flag.value
]
else: else:
flag_list = ["???"] flag_list = ["???"]
return "0x%x [%s]" % (self.val, "|".join(flag_list)) return "0x%x [%s]" % (self.val, "|".join(flag_list))
@ -96,8 +97,7 @@ class TypeFlagsPrinter:
print("Warning: Cannot find enum type_instance_flag_value type.") print("Warning: Cannot find enum type_instance_flag_value type.")
print(" `struct type' pretty-printer will be degraded") print(" `struct type' pretty-printer will be degraded")
return return
TYPE_FLAGS = [TypeFlag(field.name, field.enumval) TYPE_FLAGS = [TypeFlag(field.name, field.enumval) for field in iflags.fields()]
for field in iflags.fields()]
TYPE_FLAGS.sort() TYPE_FLAGS.sort()
@ -109,13 +109,14 @@ class StructTypePrettyPrinter:
def to_string(self): def to_string(self):
fields = [] fields = []
fields.append("pointer_type = %s" % self.val['pointer_type']) fields.append("pointer_type = %s" % self.val["pointer_type"])
fields.append("reference_type = %s" % self.val['reference_type']) fields.append("reference_type = %s" % self.val["reference_type"])
fields.append("chain = %s" % self.val['reference_type']) fields.append("chain = %s" % self.val["reference_type"])
fields.append("instance_flags = %s" fields.append(
% TypeFlagsPrinter(self.val['m_instance_flags'])) "instance_flags = %s" % TypeFlagsPrinter(self.val["m_instance_flags"])
fields.append("length = %d" % self.val['length']) )
fields.append("main_type = %s" % self.val['main_type']) fields.append("length = %d" % self.val["length"])
fields.append("main_type = %s" % self.val["main_type"])
return "\n{" + ",\n ".join(fields) + "}" return "\n{" + ",\n ".join(fields) + "}"
@ -134,78 +135,77 @@ class StructMainTypePrettyPrinter:
flag_unsigned and flag_static are the only components set to 1, flag_unsigned and flag_static are the only components set to 1,
this function will return "unsigned|static". this function will return "unsigned|static".
""" """
fields = [field.name.replace("flag_", "") fields = [
for field in self.val.type.fields() field.name.replace("flag_", "")
if field.name.startswith("flag_") and self.val[field.name]] for field in self.val.type.fields()
if field.name.startswith("flag_") and self.val[field.name]
]
return "|".join(fields) return "|".join(fields)
def owner_to_string(self): def owner_to_string(self):
"""Return an image of component "owner". """Return an image of component "owner"."""
""" if self.val["m_flag_objfile_owned"] != 0:
if self.val['m_flag_objfile_owned'] != 0: return "%s (objfile)" % self.val["m_owner"]["objfile"]
return "%s (objfile)" % self.val['m_owner']['objfile']
else: else:
return "%s (gdbarch)" % self.val['m_owner']['gdbarch'] return "%s (gdbarch)" % self.val["m_owner"]["gdbarch"]
def struct_field_location_img(self, field_val): def struct_field_location_img(self, field_val):
"""Return an image of the loc component inside the given field """Return an image of the loc component inside the given field
gdb.Value. gdb.Value.
""" """
loc_val = field_val['loc'] loc_val = field_val["loc"]
loc_kind = str(field_val['loc_kind']) loc_kind = str(field_val["loc_kind"])
if loc_kind == "FIELD_LOC_KIND_BITPOS": if loc_kind == "FIELD_LOC_KIND_BITPOS":
return 'bitpos = %d' % loc_val['bitpos'] return "bitpos = %d" % loc_val["bitpos"]
elif loc_kind == "FIELD_LOC_KIND_ENUMVAL": elif loc_kind == "FIELD_LOC_KIND_ENUMVAL":
return 'enumval = %d' % loc_val['enumval'] return "enumval = %d" % loc_val["enumval"]
elif loc_kind == "FIELD_LOC_KIND_PHYSADDR": elif loc_kind == "FIELD_LOC_KIND_PHYSADDR":
return 'physaddr = 0x%x' % loc_val['physaddr'] return "physaddr = 0x%x" % loc_val["physaddr"]
elif loc_kind == "FIELD_LOC_KIND_PHYSNAME": elif loc_kind == "FIELD_LOC_KIND_PHYSNAME":
return 'physname = %s' % loc_val['physname'] return "physname = %s" % loc_val["physname"]
elif loc_kind == "FIELD_LOC_KIND_DWARF_BLOCK": elif loc_kind == "FIELD_LOC_KIND_DWARF_BLOCK":
return 'dwarf_block = %s' % loc_val['dwarf_block'] return "dwarf_block = %s" % loc_val["dwarf_block"]
else: else:
return 'loc = ??? (unsupported loc_kind value)' return "loc = ??? (unsupported loc_kind value)"
def struct_field_img(self, fieldno): def struct_field_img(self, fieldno):
"""Return an image of the main_type field number FIELDNO. """Return an image of the main_type field number FIELDNO."""
""" f = self.val["flds_bnds"]["fields"][fieldno]
f = self.val['flds_bnds']['fields'][fieldno]
label = "flds_bnds.fields[%d]:" % fieldno label = "flds_bnds.fields[%d]:" % fieldno
if f['artificial']: if f["artificial"]:
label += " (artificial)" label += " (artificial)"
fields = [] fields = []
fields.append("name = %s" % f['name']) fields.append("name = %s" % f["name"])
fields.append("type = %s" % f['m_type']) fields.append("type = %s" % f["m_type"])
fields.append("loc_kind = %s" % f['loc_kind']) fields.append("loc_kind = %s" % f["loc_kind"])
fields.append("bitsize = %d" % f['bitsize']) fields.append("bitsize = %d" % f["bitsize"])
fields.append(self.struct_field_location_img(f)) fields.append(self.struct_field_location_img(f))
return label + "\n" + " {" + ",\n ".join(fields) + "}" return label + "\n" + " {" + ",\n ".join(fields) + "}"
def bound_img(self, bound_name): def bound_img(self, bound_name):
"""Return an image of the given main_type's bound.""" """Return an image of the given main_type's bound."""
bounds = self.val['flds_bnds']['bounds'].dereference() bounds = self.val["flds_bnds"]["bounds"].dereference()
b = bounds[bound_name] b = bounds[bound_name]
bnd_kind = str(b['m_kind']) bnd_kind = str(b["m_kind"])
if bnd_kind == 'PROP_CONST': if bnd_kind == "PROP_CONST":
return str(b['m_data']['const_val']) return str(b["m_data"]["const_val"])
elif bnd_kind == 'PROP_UNDEFINED': elif bnd_kind == "PROP_UNDEFINED":
return '(undefined)' return "(undefined)"
else: else:
info = [bnd_kind] info = [bnd_kind]
if bound_name == 'high' and bounds['flag_upper_bound_is_count']: if bound_name == "high" and bounds["flag_upper_bound_is_count"]:
info.append('upper_bound_is_count') info.append("upper_bound_is_count")
return '{} ({})'.format(str(b['m_data']['baton']), ','.join(info)) return "{} ({})".format(str(b["m_data"]["baton"]), ",".join(info))
def bounds_img(self): def bounds_img(self):
"""Return an image of the main_type bounds. """Return an image of the main_type bounds."""
""" b = self.val["flds_bnds"]["bounds"].dereference()
b = self.val['flds_bnds']['bounds'].dereference() low = self.bound_img("low")
low = self.bound_img('low') high = self.bound_img("high")
high = self.bound_img('high')
img = "flds_bnds.bounds = {%s, %s}" % (low, high) img = "flds_bnds.bounds = {%s, %s}" % (low, high)
if b['flag_bound_evaluated']: if b["flag_bound_evaluated"]:
img += ' [evaluated]' img += " [evaluated]"
return img return img
def type_specific_img(self): def type_specific_img(self):
@ -213,46 +213,53 @@ class StructMainTypePrettyPrinter:
Only the relevant component of that union is printed (based on Only the relevant component of that union is printed (based on
the value of the type_specific_kind field. the value of the type_specific_kind field.
""" """
type_specific_kind = str(self.val['type_specific_field']) type_specific_kind = str(self.val["type_specific_field"])
type_specific = self.val['type_specific'] type_specific = self.val["type_specific"]
if type_specific_kind == "TYPE_SPECIFIC_NONE": if type_specific_kind == "TYPE_SPECIFIC_NONE":
img = 'type_specific_field = %s' % type_specific_kind img = "type_specific_field = %s" % type_specific_kind
elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF": elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF":
img = "cplus_stuff = %s" % type_specific['cplus_stuff'] img = "cplus_stuff = %s" % type_specific["cplus_stuff"]
elif type_specific_kind == "TYPE_SPECIFIC_GNAT_STUFF": elif type_specific_kind == "TYPE_SPECIFIC_GNAT_STUFF":
img = ("gnat_stuff = {descriptive_type = %s}" img = (
% type_specific['gnat_stuff']['descriptive_type']) "gnat_stuff = {descriptive_type = %s}"
% type_specific["gnat_stuff"]["descriptive_type"]
)
elif type_specific_kind == "TYPE_SPECIFIC_FLOATFORMAT": elif type_specific_kind == "TYPE_SPECIFIC_FLOATFORMAT":
img = "floatformat[0..1] = %s" % type_specific['floatformat'] img = "floatformat[0..1] = %s" % type_specific["floatformat"]
elif type_specific_kind == "TYPE_SPECIFIC_FUNC": elif type_specific_kind == "TYPE_SPECIFIC_FUNC":
img = ("calling_convention = %d" img = (
% type_specific['func_stuff']['calling_convention']) "calling_convention = %d"
% type_specific["func_stuff"]["calling_convention"]
)
# tail_call_list is not printed. # tail_call_list is not printed.
elif type_specific_kind == "TYPE_SPECIFIC_SELF_TYPE": elif type_specific_kind == "TYPE_SPECIFIC_SELF_TYPE":
img = "self_type = %s" % type_specific['self_type'] img = "self_type = %s" % type_specific["self_type"]
elif type_specific_kind == "TYPE_SPECIFIC_FIXED_POINT": elif type_specific_kind == "TYPE_SPECIFIC_FIXED_POINT":
# The scaling factor is an opaque structure, so we cannot # The scaling factor is an opaque structure, so we cannot
# decode its value from Python (not without insider knowledge). # decode its value from Python (not without insider knowledge).
img = ('scaling_factor: <opaque> (call __gmpz_dump with ' img = (
' _mp_num and _mp_den fields if needed)') "scaling_factor: <opaque> (call __gmpz_dump with "
" _mp_num and _mp_den fields if needed)"
)
else: else:
img = ("type_specific = ??? (unknown type_secific_kind: %s)" img = (
% type_specific_kind) "type_specific = ??? (unknown type_secific_kind: %s)"
% type_specific_kind
)
return img return img
def to_string(self): def to_string(self):
"""Return a pretty-printed image of our main_type. """Return a pretty-printed image of our main_type."""
"""
fields = [] fields = []
fields.append("name = %s" % self.val['name']) fields.append("name = %s" % self.val["name"])
fields.append("code = %s" % self.val['code']) fields.append("code = %s" % self.val["code"])
fields.append("flags = [%s]" % self.flags_to_string()) fields.append("flags = [%s]" % self.flags_to_string())
fields.append("owner = %s" % self.owner_to_string()) fields.append("owner = %s" % self.owner_to_string())
fields.append("target_type = %s" % self.val['target_type']) fields.append("target_type = %s" % self.val["target_type"])
if self.val['nfields'] > 0: if self.val["nfields"] > 0:
for fieldno in range(self.val['nfields']): for fieldno in range(self.val["nfields"]):
fields.append(self.struct_field_img(fieldno)) fields.append(self.struct_field_img(fieldno))
if self.val['code'] == gdb.TYPE_CODE_RANGE: if self.val["code"] == gdb.TYPE_CODE_RANGE:
fields.append(self.bounds_img()) fields.append(self.bounds_img())
fields.append(self.type_specific_img()) fields.append(self.type_specific_img())
@ -277,14 +284,13 @@ def type_lookup_function(val):
return StructTypePrettyPrinter(val) return StructTypePrettyPrinter(val)
elif val.type.tag == "main_type": elif val.type.tag == "main_type":
return StructMainTypePrettyPrinter(val) return StructMainTypePrettyPrinter(val)
elif val.type.name == 'CORE_ADDR': elif val.type.name == "CORE_ADDR":
return CoreAddrPrettyPrinter(val) return CoreAddrPrettyPrinter(val)
return None return None
def register_pretty_printer(objfile): def register_pretty_printer(objfile):
"""A routine to register a pretty-printer against the given OBJFILE. """A routine to register a pretty-printer against the given OBJFILE."""
"""
objfile.pretty_printers.append(type_lookup_function) objfile.pretty_printers.append(type_lookup_function)

2
gdb/pyproject.toml Normal file
View File

@ -0,0 +1,2 @@
[tool.black]
include = "\\.py(\\.in)?$"

View File

@ -1,3 +1,8 @@
2021-05-17 Simon Marchi <simon.marchi@polymtl.ca>
* gdb.python/py-framefilter-gdb.py.in: Re-format.
* gdb.python/py-framefilter-invalidarg-gdb.py.in: Re-format.
2021-05-17 Bhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com> 2021-05-17 Bhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com>
* gdb.base/class-allocatable-array.exp: Modified test for clang. * gdb.base/class-allocatable-array.exp: Modified test for clang.

View File

@ -20,29 +20,29 @@ import itertools
from gdb.FrameDecorator import FrameDecorator from gdb.FrameDecorator import FrameDecorator
class FrameObjFile (): class FrameObjFile:
def __init__(self):
def __init__ (self):
self.name = "Filter1" self.name = "Filter1"
self.priority = 1 self.priority = 1
self.enabled = False self.enabled = False
gdb.current_progspace().frame_filters ["Progspace" + self.name] = self gdb.current_progspace().frame_filters["Progspace" + self.name] = self
gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self gdb.current_objfile().frame_filters["ObjectFile" + self.name] = self
def filter (self, frame_iter): def filter(self, frame_iter):
return frame_iter return frame_iter
class FrameObjFile2 ():
def __init__ (self): class FrameObjFile2:
def __init__(self):
self.name = "Filter2" self.name = "Filter2"
self.priority = 100 self.priority = 100
self.enabled = True self.enabled = True
gdb.current_progspace().frame_filters ["Progspace" + self.name] = self gdb.current_progspace().frame_filters["Progspace" + self.name] = self
gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self gdb.current_objfile().frame_filters["ObjectFile" + self.name] = self
def filter (self, frame_iter): def filter(self, frame_iter):
return frame_iter return frame_iter
FrameObjFile() FrameObjFile()
FrameObjFile2() FrameObjFile2()

View File

@ -20,29 +20,29 @@ import itertools
from gdb.FrameDecorator import FrameDecorator from gdb.FrameDecorator import FrameDecorator
class FrameObjFile (): class FrameObjFile:
def __init__(self):
def __init__ (self):
self.name = "Filter1" self.name = "Filter1"
self.priority = 1 self.priority = 1
self.enabled = False self.enabled = False
gdb.current_progspace().frame_filters ["Progspace" + self.name] = self gdb.current_progspace().frame_filters["Progspace" + self.name] = self
gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self gdb.current_objfile().frame_filters["ObjectFile" + self.name] = self
def filter (self, frame_iter): def filter(self, frame_iter):
return frame_iter return frame_iter
class FrameObjFile2 ():
def __init__ (self): class FrameObjFile2:
def __init__(self):
self.name = "Filter2" self.name = "Filter2"
self.priority = 100 self.priority = 100
self.enabled = True self.enabled = True
gdb.current_progspace().frame_filters ["Progspace" + self.name] = self gdb.current_progspace().frame_filters["Progspace" + self.name] = self
gdb.current_objfile().frame_filters ["ObjectFile" + self.name] = self gdb.current_objfile().frame_filters["ObjectFile" + self.name] = self
def filter (self, frame_iter): def filter(self, frame_iter):
return frame_iter return frame_iter
FrameObjFile() FrameObjFile()
FrameObjFile2() FrameObjFile2()