2023-01-01 20:49:04 +08:00
|
|
|
# Copyright (C) 2009-2023 Free Software Foundation, Inc.
|
2010-01-06 11:46:18 +08:00
|
|
|
#
|
|
|
|
# This file is part of GDB.
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
import gdb
|
|
|
|
import os.path
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
class TypeFlag:
|
|
|
|
"""A class that allows us to store a flag name, its short name,
|
|
|
|
and its value.
|
|
|
|
|
|
|
|
In the GDB sources, struct type has a component called instance_flags
|
2010-02-11 02:39:45 +08:00
|
|
|
in which the value is the addition of various flags. These flags are
|
2016-09-06 23:29:15 +08:00
|
|
|
defined by the enumerates type_instance_flag_value. This class helps us
|
|
|
|
recreate a list with all these flags that is easy to manipulate and sort.
|
|
|
|
Because all flag names start with TYPE_INSTANCE_FLAG_, a short_name
|
|
|
|
attribute is provided that strips this prefix.
|
2010-01-06 11:46:18 +08:00
|
|
|
|
|
|
|
ATTRIBUTES
|
2016-09-06 23:29:15 +08:00
|
|
|
name: The enumeration name (eg: "TYPE_INSTANCE_FLAG_CONST").
|
2010-01-06 11:46:18 +08:00
|
|
|
value: The associated value.
|
|
|
|
short_name: The enumeration name, with the suffix stripped.
|
|
|
|
"""
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def __init__(self, name, value):
|
|
|
|
self.name = name
|
|
|
|
self.value = value
|
2021-05-18 02:31:00 +08:00
|
|
|
self.short_name = name.replace("TYPE_INSTANCE_FLAG_", "")
|
2018-06-28 02:32:05 +08:00
|
|
|
|
|
|
|
def __lt__(self, other):
|
2010-01-06 11:46:18 +08:00
|
|
|
"""Sort by value order."""
|
2018-06-28 02:32:05 +08:00
|
|
|
return self.value < other.value
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
|
2016-09-06 23:29:15 +08:00
|
|
|
# A list of all existing TYPE_INSTANCE_FLAGS_* enumerations,
|
|
|
|
# stored as TypeFlags objects. Lazy-initialized.
|
2010-01-06 11:46:18 +08:00
|
|
|
TYPE_FLAGS = None
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
class TypeFlagsPrinter:
|
|
|
|
"""A class that prints a decoded form of an instance_flags value.
|
|
|
|
|
|
|
|
This class uses a global named TYPE_FLAGS, which is a list of
|
|
|
|
all defined TypeFlag values. Using a global allows us to compute
|
|
|
|
this list only once.
|
|
|
|
|
|
|
|
This class relies on a couple of enumeration types being defined.
|
|
|
|
If not, then printing of the instance_flag is going to be degraded,
|
|
|
|
but it's not a fatal error.
|
|
|
|
"""
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def __str__(self):
|
|
|
|
global TYPE_FLAGS
|
|
|
|
if TYPE_FLAGS is None:
|
|
|
|
self.init_TYPE_FLAGS()
|
|
|
|
if not self.val:
|
|
|
|
return "0"
|
|
|
|
if TYPE_FLAGS:
|
2021-05-18 02:31:00 +08:00
|
|
|
flag_list = [
|
|
|
|
flag.short_name for flag in TYPE_FLAGS if self.val & flag.value
|
|
|
|
]
|
2010-01-06 11:46:18 +08:00
|
|
|
else:
|
|
|
|
flag_list = ["???"]
|
|
|
|
return "0x%x [%s]" % (self.val, "|".join(flag_list))
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def init_TYPE_FLAGS(self):
|
|
|
|
"""Initialize the TYPE_FLAGS global as a list of TypeFlag objects.
|
|
|
|
This operation requires the search of a couple of enumeration types.
|
|
|
|
If not found, a warning is printed on stdout, and TYPE_FLAGS is
|
|
|
|
set to the empty list.
|
|
|
|
|
|
|
|
The resulting list is sorted by increasing value, to facilitate
|
|
|
|
printing of the list of flags used in an instance_flags value.
|
|
|
|
"""
|
|
|
|
global TYPE_FLAGS
|
|
|
|
TYPE_FLAGS = []
|
|
|
|
try:
|
|
|
|
iflags = gdb.lookup_type("enum type_instance_flag_value")
|
|
|
|
except:
|
2016-02-23 00:15:14 +08:00
|
|
|
print("Warning: Cannot find enum type_instance_flag_value type.")
|
|
|
|
print(" `struct type' pretty-printer will be degraded")
|
2010-01-06 11:46:18 +08:00
|
|
|
return
|
2021-05-18 02:31:00 +08:00
|
|
|
TYPE_FLAGS = [TypeFlag(field.name, field.enumval) for field in iflags.fields()]
|
2010-01-06 11:46:18 +08:00
|
|
|
TYPE_FLAGS.sort()
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
class StructTypePrettyPrinter:
|
|
|
|
"""Pretty-print an object of type struct type"""
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def to_string(self):
|
|
|
|
fields = []
|
2021-05-18 02:31:00 +08:00
|
|
|
fields.append("pointer_type = %s" % self.val["pointer_type"])
|
|
|
|
fields.append("reference_type = %s" % self.val["reference_type"])
|
|
|
|
fields.append("chain = %s" % self.val["reference_type"])
|
|
|
|
fields.append(
|
|
|
|
"instance_flags = %s" % TypeFlagsPrinter(self.val["m_instance_flags"])
|
|
|
|
)
|
2022-09-23 21:21:18 +08:00
|
|
|
fields.append("length = %d" % self.val["m_length"])
|
2021-05-18 02:31:00 +08:00
|
|
|
fields.append("main_type = %s" % self.val["main_type"])
|
2010-01-06 11:46:18 +08:00
|
|
|
return "\n{" + ",\n ".join(fields) + "}"
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
class StructMainTypePrettyPrinter:
|
|
|
|
"""Pretty-print an objet of type main_type"""
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def flags_to_string(self):
|
|
|
|
"""struct main_type contains a series of components that
|
|
|
|
are one-bit ints whose name start with "flag_". For instance:
|
|
|
|
flag_unsigned, flag_stub, etc. In essence, these components are
|
|
|
|
really boolean flags, and this method prints a short synthetic
|
|
|
|
version of the value of all these flags. For instance, if
|
|
|
|
flag_unsigned and flag_static are the only components set to 1,
|
|
|
|
this function will return "unsigned|static".
|
|
|
|
"""
|
2021-05-18 02:31:00 +08:00
|
|
|
fields = [
|
|
|
|
field.name.replace("flag_", "")
|
|
|
|
for field in self.val.type.fields()
|
|
|
|
if field.name.startswith("flag_") and self.val[field.name]
|
|
|
|
]
|
2010-01-06 11:46:18 +08:00
|
|
|
return "|".join(fields)
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def owner_to_string(self):
|
2021-05-18 02:31:00 +08:00
|
|
|
"""Return an image of component "owner"."""
|
|
|
|
if self.val["m_flag_objfile_owned"] != 0:
|
|
|
|
return "%s (objfile)" % self.val["m_owner"]["objfile"]
|
2010-01-06 11:46:18 +08:00
|
|
|
else:
|
2021-05-18 02:31:00 +08:00
|
|
|
return "%s (gdbarch)" % self.val["m_owner"]["gdbarch"]
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def struct_field_location_img(self, field_val):
|
|
|
|
"""Return an image of the loc component inside the given field
|
|
|
|
gdb.Value.
|
|
|
|
"""
|
2021-12-06 19:25:04 +08:00
|
|
|
loc_val = field_val["m_loc"]
|
|
|
|
loc_kind = str(field_val["m_loc_kind"])
|
2010-01-06 11:46:18 +08:00
|
|
|
if loc_kind == "FIELD_LOC_KIND_BITPOS":
|
2021-05-18 02:31:00 +08:00
|
|
|
return "bitpos = %d" % loc_val["bitpos"]
|
2012-04-18 14:46:47 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_ENUMVAL":
|
2021-05-18 02:31:00 +08:00
|
|
|
return "enumval = %d" % loc_val["enumval"]
|
2010-01-06 11:46:18 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_PHYSADDR":
|
2021-05-18 02:31:00 +08:00
|
|
|
return "physaddr = 0x%x" % loc_val["physaddr"]
|
2010-01-06 11:46:18 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_PHYSNAME":
|
2021-05-18 02:31:00 +08:00
|
|
|
return "physname = %s" % loc_val["physname"]
|
gdb/
Implement basic support for DW_TAG_GNU_call_site.
* block.c: Include gdbtypes.h and exceptions.h.
(call_site_for_pc): New function.
* block.h (call_site_for_pc): New declaration.
* defs.h: Include hashtab.h.
(make_cleanup_htab_delete, core_addr_hash, core_addr_eq): New
declarations.
* dwarf2-frame.c (dwarf2_frame_ctx_funcs): Install
ctx_no_push_dwarf_reg_entry_value.
* dwarf2expr.c (read_uleb128, read_sleb128): Support R as NULL.
(dwarf_block_to_dwarf_reg): New function.
(execute_stack_op) <DW_OP_GNU_entry_value>: Implement it.
(ctx_no_push_dwarf_reg_entry_value): New function.
* dwarf2expr.h (struct dwarf_expr_context_funcs): New field
push_dwarf_reg_entry_value.
(ctx_no_push_dwarf_reg_entry_value, dwarf_block_to_dwarf_reg): New
declarations.
* dwarf2loc.c: Include gdbcmd.h.
(dwarf_expr_ctx_funcs): New forward declaration.
(entry_values_debug, show_entry_values_debug, call_site_to_target_addr)
(dwarf_expr_reg_to_entry_parameter)
(dwarf_expr_push_dwarf_reg_entry_value): New.
(dwarf_expr_ctx_funcs): Install dwarf_expr_push_dwarf_reg_entry_value.
(dwarf2_evaluate_loc_desc_full): Handle NO_ENTRY_VALUE_ERROR.
(needs_dwarf_reg_entry_value): New function.
(needs_frame_ctx_funcs): Install it.
(_initialize_dwarf2loc): New function.
* dwarf2loc.h (entry_values_debug): New declaration.
* dwarf2read.c (struct dwarf2_cu): New field call_site_htab.
(read_call_site_scope): New forward declaration.
(process_full_comp_unit): Copy call_site_htab.
(process_die): Support DW_TAG_GNU_call_site.
(read_call_site_scope): New function.
(dwarf2_get_pc_bounds): Support NULL HIGHPC.
(dwarf_tag_name): Support DW_TAG_GNU_call_site.
(cleanup_htab): Delete.
(write_psymtabs_to_index): Use make_cleanup_htab_delete instead of it.
* exceptions.h (enum errors): New NO_ENTRY_VALUE_ERROR.
* gdb-gdb.py (StructMainTypePrettyPrinter): Support
FIELD_LOC_KIND_DWARF_BLOCK.
* gdbtypes.h (enum field_loc_kind): New entry
FIELD_LOC_KIND_DWARF_BLOCK.
(struct main_type): New loc entry dwarf_block.
(struct call_site, FIELD_DWARF_BLOCK, SET_FIELD_DWARF_BLOCK)
(TYPE_FIELD_DWARF_BLOCK): New.
* python/py-type.c: Include dwarf2loc.h.
(check_types_equal): Support FIELD_LOC_KIND_DWARF_BLOCK. New
internal_error call on unknown FIELD_LOC_KIND.
* symtab.h (struct symtab): New field call_site_htab.
* utils.c (do_htab_delete_cleanup, make_cleanup_htab_delete)
(core_addr_hash, core_addr_eq): New functions.
gdb/testsuite/
Implement basic support for DW_TAG_GNU_call_site.
* gdb.arch/Makefile.in (EXECUTABLES): Add amd64-entry-value.
* gdb.arch/amd64-entry-value.cc: New file.
* gdb.arch/amd64-entry-value.exp: New file.
2011-10-10 03:21:39 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_DWARF_BLOCK":
|
2021-05-18 02:31:00 +08:00
|
|
|
return "dwarf_block = %s" % loc_val["dwarf_block"]
|
2010-01-06 11:46:18 +08:00
|
|
|
else:
|
2021-12-06 19:25:04 +08:00
|
|
|
return "m_loc = ??? (unsupported m_loc_kind value)"
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def struct_field_img(self, fieldno):
|
2021-05-18 02:31:00 +08:00
|
|
|
"""Return an image of the main_type field number FIELDNO."""
|
|
|
|
f = self.val["flds_bnds"]["fields"][fieldno]
|
2012-02-09 23:14:46 +08:00
|
|
|
label = "flds_bnds.fields[%d]:" % fieldno
|
2023-08-31 23:46:22 +08:00
|
|
|
if f["m_artificial"]:
|
2010-01-06 11:46:18 +08:00
|
|
|
label += " (artificial)"
|
|
|
|
fields = []
|
2021-12-06 19:25:04 +08:00
|
|
|
fields.append("m_name = %s" % f["m_name"])
|
|
|
|
fields.append("m_type = %s" % f["m_type"])
|
|
|
|
fields.append("m_loc_kind = %s" % f["m_loc_kind"])
|
2023-08-31 23:46:25 +08:00
|
|
|
fields.append("bitsize = %d" % f["m_bitsize"])
|
2010-01-06 11:46:18 +08:00
|
|
|
fields.append(self.struct_field_location_img(f))
|
|
|
|
return label + "\n" + " {" + ",\n ".join(fields) + "}"
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2019-03-27 06:30:21 +08:00
|
|
|
def bound_img(self, bound_name):
|
|
|
|
"""Return an image of the given main_type's bound."""
|
2021-05-18 02:31:00 +08:00
|
|
|
bounds = self.val["flds_bnds"]["bounds"].dereference()
|
2021-01-03 00:35:25 +08:00
|
|
|
b = bounds[bound_name]
|
2021-05-18 02:31:00 +08:00
|
|
|
bnd_kind = str(b["m_kind"])
|
|
|
|
if bnd_kind == "PROP_CONST":
|
|
|
|
return str(b["m_data"]["const_val"])
|
|
|
|
elif bnd_kind == "PROP_UNDEFINED":
|
|
|
|
return "(undefined)"
|
2019-03-27 06:30:21 +08:00
|
|
|
else:
|
|
|
|
info = [bnd_kind]
|
2021-05-18 02:31:00 +08:00
|
|
|
if bound_name == "high" and bounds["flag_upper_bound_is_count"]:
|
|
|
|
info.append("upper_bound_is_count")
|
|
|
|
return "{} ({})".format(str(b["m_data"]["baton"]), ",".join(info))
|
2019-03-27 06:30:21 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def bounds_img(self):
|
2021-05-18 02:31:00 +08:00
|
|
|
"""Return an image of the main_type bounds."""
|
|
|
|
b = self.val["flds_bnds"]["bounds"].dereference()
|
|
|
|
low = self.bound_img("low")
|
|
|
|
high = self.bound_img("high")
|
2019-03-27 06:30:21 +08:00
|
|
|
|
|
|
|
img = "flds_bnds.bounds = {%s, %s}" % (low, high)
|
2021-05-18 02:31:00 +08:00
|
|
|
if b["flag_bound_evaluated"]:
|
|
|
|
img += " [evaluated]"
|
2019-03-27 06:30:21 +08:00
|
|
|
return img
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-15 17:15:46 +08:00
|
|
|
def type_specific_img(self):
|
|
|
|
"""Return a string image of the main_type type_specific union.
|
|
|
|
Only the relevant component of that union is printed (based on
|
|
|
|
the value of the type_specific_kind field.
|
|
|
|
"""
|
2021-05-18 02:31:00 +08:00
|
|
|
type_specific_kind = str(self.val["type_specific_field"])
|
|
|
|
type_specific = self.val["type_specific"]
|
2010-01-15 17:15:46 +08:00
|
|
|
if type_specific_kind == "TYPE_SPECIFIC_NONE":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = "type_specific_field = %s" % type_specific_kind
|
2010-01-15 17:15:46 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = "cplus_stuff = %s" % type_specific["cplus_stuff"]
|
2010-01-15 17:15:46 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_GNAT_STUFF":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = (
|
|
|
|
"gnat_stuff = {descriptive_type = %s}"
|
|
|
|
% type_specific["gnat_stuff"]["descriptive_type"]
|
|
|
|
)
|
2010-01-15 17:15:46 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_FLOATFORMAT":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = "floatformat[0..1] = %s" % type_specific["floatformat"]
|
2011-10-10 03:10:52 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_FUNC":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = (
|
|
|
|
"calling_convention = %d"
|
|
|
|
% type_specific["func_stuff"]["calling_convention"]
|
|
|
|
)
|
2011-10-10 03:10:52 +08:00
|
|
|
# tail_call_list is not printed.
|
Move TYPE_SELF_TYPE into new field type_specific.
This patch moves TYPE_SELF_TYPE into new field type_specific.self_type
for MEMBERPTR,METHODPTR types, and into type_specific.func_stuff
for METHODs, and then updates everything to use that.
TYPE_CODE_METHOD could share some things with TYPE_CODE_FUNC
(e.g. TYPE_NO_RETURN) and it seemed simplest to keep them together.
Moving TYPE_SELF_TYPE into type_specific.func_stuff for TYPE_CODE_METHOD
is also nice because when we allocate space for function types we assume
they're TYPE_CODE_FUNCs. If TYPE_CODE_METHODs don't need or use that
space then that space would be wasted, and cleaning that up would involve
more invasive changes.
In order to catch errant uses I've added accessor functions
that do some checking.
One can no longer assign to TYPE_SELF_TYPE like this:
TYPE_SELF_TYPE (foo) = bar;
One instead has to do:
set_type_self_type (foo, bar);
But I've left reading of the type to the macro:
bar = TYPE_SELF_TYPE (foo);
In order to discourage bypassing the TYPE_SELF_TYPE macro
I've named the underlying function that implements it
internal_type_self_type.
While testing this I found the stabs reader leaving methods
as TYPE_CODE_FUNCs, hitting my newly added asserts.
Since the dwarf reader smashes functions to methods (via
smash_to_method) I've done a similar thing for stabs.
gdb/ChangeLog:
* cp-valprint.c (cp_find_class_member): Rename parameter domain_p
to self_p.
(cp_print_class_member): Rename local domain to self_type.
* dwarf2read.c (quirk_gcc_member_function_pointer): Rename local
domain_type to self_type.
(set_die_type) <need_gnat_info>: Handle
TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, TYPE_CODE_METHOD.
* gdb-gdb.py (StructMainTypePrettyPrinter): Handle
TYPE_SPECIFIC_SELF_TYPE.
* gdbtypes.c (internal_type_self_type): New function.
(set_type_self_type): New function.
(smash_to_memberptr_type): Rename parameter domain to self_type.
Update setting of TYPE_SELF_TYPE.
(smash_to_methodptr_type): Update setting of TYPE_SELF_TYPE.
(smash_to_method_type): Rename parameter domain to self_type.
Update setting of TYPE_SELF_TYPE.
(check_stub_method): Call smash_to_method_type.
(recursive_dump_type): Handle TYPE_SPECIFIC_SELF_TYPE.
(copy_type_recursive): Ditto.
* gdbtypes.h (enum type_specific_kind): New value
TYPE_SPECIFIC_SELF_TYPE.
(struct main_type) <type_specific>: New member self_type.
(struct cplus_struct_type) <fn_field.type>: Update comment.
(TYPE_SELF_TYPE): Rewrite.
(internal_type_self_type, set_type_self_type): Declare.
* gnu-v3-abi.c (gnuv3_print_method_ptr): Rename local domain to
self_type.
(gnuv3_method_ptr_to_value): Rename local domain_type to self_type.
* m2-typeprint.c (m2_range): Replace TYPE_SELF_TYPE with
TYPE_TARGET_TYPE.
* stabsread.c (read_member_functions): Mark methods with
TYPE_CODE_METHOD, not TYPE_CODE_FUNC. Update setting of
TYPE_SELF_TYPE.
2015-02-01 13:21:01 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_SELF_TYPE":
|
2021-05-18 02:31:00 +08:00
|
|
|
img = "self_type = %s" % type_specific["self_type"]
|
Add support for printing value of DWARF-based fixed-point type objects
This commit introduces a new kind of type, meant to describe
fixed-point types, using a new code added specifically for
this purpose (TYPE_CODE_FIXED_POINT).
It then adds handling of fixed-point base types in the DWARF reader.
And finally, as a first step, this commit adds support for printing
the value of fixed-point type objects.
Note that this commit has a known issue: Trying to print the value
of a fixed-point object with a format letter (e.g. "print /x NAME")
causes the wrong value to be printed because the scaling factor
is not applied. Since the fix for this issue is isolated, and
this is not a regression, the fix will be made in a pach of its own.
This is meant to simplify review and archeology.
Also, other functionalities related to fixed-point type handling
(ptype, arithmetics, etc), will be added piecemeal as well, for
the same reasons (faciliate reviews and archeology). Related to this,
the testcase gdb.ada/fixed_cmp.exp is adjusted to compile the test
program with -fgnat-encodings=all, so as to force the use of GNAT
encodings, rather than rely on the compiler's default to use them.
The intent is to enhance this testcase to also test the pure DWARF
approach using -fgnat-encodings=minimal as soon as the corresponding
suport gets added in. Thus, the modification to the testcase is made
in a way that it prepares this testcase to be tested in both modes.
gdb/ChangeLog:
* ada-valprint.c (ada_value_print_1): Add fixed-point type handling.
* dwarf2/read.c (get_dwarf2_rational_constant)
(get_dwarf2_unsigned_rational_constant, finish_fixed_point_type)
(has_zero_over_zero_small_attribute): New functions.
read_base_type, set_die_type): Add fixed-point type handling.
* gdb-gdb.py.in: Add fixed-point type handling.
* gdbtypes.c: #include "gmp-utils.h".
(create_range_type, set_type_code): Add fixed-point type handling.
(init_fixed_point_type): New function.
(is_integral_type, is_scalar_type): Add fixed-point type handling.
(print_fixed_point_type_info): New function.
(recursive_dump_type, copy_type_recursive): Add fixed-point type
handling.
(fixed_point_type_storage): New typedef.
(fixed_point_objfile_key): New static global.
(allocate_fixed_point_type_info, is_fixed_point_type): New functions.
(fixed_point_type_base_type, fixed_point_scaling_factor): New
functions.
* gdbtypes.h: #include "gmp-utils.h".
(enum type_code) <TYPE_SPECIFIC_FIXED_POINT>: New enum.
(union type_specific) <fixed_point_info>: New field.
(struct fixed_point_type_info): New struct.
(INIT_FIXED_POINT_SPECIFIC, TYPE_FIXED_POINT_INFO): New macros.
(init_fixed_point_type, is_fixed_point_type)
(fixed_point_type_base_type, fixed_point_scaling_factor)
(allocate_fixed_point_type_info): Add declarations.
* valprint.c (generic_val_print_fixed_point): New function.
(generic_value_print): Add fixed-point type handling.
* value.c (value_as_address, unpack_long): Add fixed-point type
handling.
gdb/testsuite/ChangeLog:
* gdb.ada/fixed_cmp.exp: Force compilation to use -fgnat-encodings=all.
* gdb.ada/fixed_points.exp: Add fixed-point variables printing tests.
* gdb.ada/fixed_points/pck.ads, gdb.ada/fixed_points/pck.adb:
New files.
* gdb.ada/fixed_points/fixed_points.adb: Add use of package Pck.
* gdb.dwarf2/dw2-fixed-point.c, gdb.dwarf2/dw2-fixed-point.exp:
New files.
2020-11-15 16:12:52 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_FIXED_POINT":
|
|
|
|
# The scaling factor is an opaque structure, so we cannot
|
|
|
|
# decode its value from Python (not without insider knowledge).
|
2021-05-18 02:31:00 +08:00
|
|
|
img = (
|
|
|
|
"scaling_factor: <opaque> (call __gmpz_dump with "
|
|
|
|
" _mp_num and _mp_den fields if needed)"
|
|
|
|
)
|
2021-12-06 19:25:04 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_INT":
|
2021-12-16 09:26:35 +08:00
|
|
|
img = "int_stuff = { bit_size = %d, bit_offset = %d }" % (
|
|
|
|
type_specific["int_stuff"]["bit_size"],
|
|
|
|
type_specific["int_stuff"]["bit_offset"],
|
|
|
|
)
|
2010-01-15 17:15:46 +08:00
|
|
|
else:
|
2021-05-18 02:31:00 +08:00
|
|
|
img = (
|
2021-12-06 19:25:04 +08:00
|
|
|
"type_specific = ??? (unknown type_specific_kind: %s)"
|
2021-05-18 02:31:00 +08:00
|
|
|
% type_specific_kind
|
|
|
|
)
|
2010-01-15 17:15:46 +08:00
|
|
|
return img
|
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def to_string(self):
|
2021-05-18 02:31:00 +08:00
|
|
|
"""Return a pretty-printed image of our main_type."""
|
2010-01-06 11:46:18 +08:00
|
|
|
fields = []
|
2021-05-18 02:31:00 +08:00
|
|
|
fields.append("name = %s" % self.val["name"])
|
|
|
|
fields.append("code = %s" % self.val["code"])
|
2010-01-06 11:46:18 +08:00
|
|
|
fields.append("flags = [%s]" % self.flags_to_string())
|
|
|
|
fields.append("owner = %s" % self.owner_to_string())
|
2022-09-23 21:21:18 +08:00
|
|
|
fields.append("target_type = %s" % self.val["m_target_type"])
|
Increase size of main_type::nfields
main_type::nfields is a 'short', and has been for many years. PR
c++/29985 points out that 'short' is too narrow for an enum that
contains more than 2^15 constants.
This patch bumps the size of 'nfields'. To verify that the field
isn't directly used, it is also renamed. Note that this does not
affect the size of main_type on x86-64 Fedora 36. And, if it does
have a negative effect somewhere, it's worth considering that types
could be shrunk more drastically by using subclasses for the different
codes.
This is v2 of this patch, which has these changes:
* I changed nfields to 'unsigned', per Simon's request. I looked at
changing all the uses, but this quickly fans out into a very large
patch. (One additional tweak was needed, though.)
* I wrote a test case. I discovered that GCC cannot compile a large
enough C test case, so I resorted to using the DWARF assembler.
This test doesn't reproduce the crash, but it does fail without the
patch.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29985
2023-01-12 03:42:40 +08:00
|
|
|
if self.val["m_nfields"] > 0:
|
|
|
|
for fieldno in range(self.val["m_nfields"]):
|
2010-01-06 11:46:18 +08:00
|
|
|
fields.append(self.struct_field_img(fieldno))
|
2021-05-18 02:31:00 +08:00
|
|
|
if self.val["code"] == gdb.TYPE_CODE_RANGE:
|
2010-01-06 11:46:18 +08:00
|
|
|
fields.append(self.bounds_img())
|
2010-01-15 17:15:46 +08:00
|
|
|
fields.append(self.type_specific_img())
|
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
return "\n{" + ",\n ".join(fields) + "}"
|
|
|
|
|
2018-06-28 03:21:47 +08:00
|
|
|
|
|
|
|
class CoreAddrPrettyPrinter:
|
|
|
|
"""Print CORE_ADDR values as hex."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self._val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return hex(int(self._val))
|
|
|
|
|
|
|
|
|
gdb: introduce intrusive_list, make thread_info use it
GDB currently has several objects that are put in a singly linked list,
by having the object's type have a "next" pointer directly. For
example, struct thread_info and struct inferior. Because these are
simply-linked lists, and we don't keep track of a "tail" pointer, when
we want to append a new element on the list, we need to walk the whole
list to find the current tail. It would be nice to get rid of that
walk. Removing elements from such lists also requires a walk, to find
the "previous" position relative to the element being removed. To
eliminate the need for that walk, we could make those lists
doubly-linked, by adding a "prev" pointer alongside "next". It would be
nice to avoid the boilerplate associated with maintaining such a list
manually, though. That is what the new intrusive_list type addresses.
With an intrusive list, it's also possible to move items out of the
list without destroying them, which is interesting in our case for
example for threads, when we exit them, but can't destroy them
immediately. We currently keep exited threads on the thread list, but
we could change that which would simplify some things.
Note that with std::list, element removal is O(N). I.e., with
std::list, we need to walk the list to find the iterator pointing to
the position to remove. However, we could store a list iterator
inside the object as soon as we put the object in the list, to address
it, because std::list iterators are not invalidated when other
elements are added/removed. However, if you need to put the same
object in more than one list, then std::list<object> doesn't work.
You need to instead use std::list<object *>, which is less efficient
for requiring extra memory allocations. For an example of an object
in multiple lists, see the step_over_next/step_over_prev fields in
thread_info:
/* Step-over chain. A thread is in the step-over queue if these are
non-NULL. If only a single thread is in the chain, then these
fields point to self. */
struct thread_info *step_over_prev = NULL;
struct thread_info *step_over_next = NULL;
The new intrusive_list type gives us the advantages of an intrusive
linked list, while avoiding the boilerplate associated with manually
maintaining it.
intrusive_list's API follows the standard container interface, and thus
std::list's interface. It is based the API of Boost's intrusive list,
here:
https://www.boost.org/doc/libs/1_73_0/doc/html/boost/intrusive/list.html
Our implementation is relatively simple, while Boost's is complicated
and intertwined due to a lot of customization options, which our version
doesn't have.
The easiest way to use an intrusive_list is to make the list's element
type inherit from intrusive_node. This adds a prev/next pointers to
the element type. However, to support putting the same object in more
than one list, intrusive_list supports putting the "node" info as a
field member, so you can have more than one such nodes, one per list.
As a first guinea pig, this patch makes the per-inferior thread list use
intrusive_list using the base class method.
Unlike Boost's implementation, ours is not a circular list. An earlier
version of the patch was circular: the intrusive_list type included an
intrusive_list_node "head". In this design, a node contained pointers
to the previous and next nodes, not the previous and next elements.
This wasn't great for when debugging GDB with GDB, as it was difficult
to get from a pointer to the node to a pointer to the element. With the
design proposed in this patch, nodes contain pointers to the previous
and next elements, making it easy to traverse the list by hand and
inspect each element.
The intrusive_list object contains pointers to the first and last
elements of the list. They are nullptr if the list is empty.
Each element's node contains a pointer to the previous and next
elements. The first element's previous pointer is nullptr and the last
element's next pointer is nullptr. Therefore, if there's a single
element in the list, both its previous and next pointers are nullptr.
To differentiate such an element from an element that is not linked into
a list, the previous and next pointers contain a special value (-1) when
the node is not linked. This is necessary to be able to reliably tell
if a given node is currently linked or not.
A begin() iterator points to the first item in the list. An end()
iterator contains nullptr. This makes iteration until end naturally
work, as advancing past the last element will make the iterator contain
nullptr, making it equal to the end iterator. If the list is empty,
a begin() iterator will contain nullptr from the start, and therefore be
immediately equal to the end.
Iterating on an intrusive_list yields references to objects (e.g.
`thread_info&`). The rest of GDB currently expects iterators and ranges
to yield pointers (e.g. `thread_info*`). To bridge the gap, add the
reference_to_pointer_iterator type. It is used to define
inf_threads_iterator.
Add a Python pretty-printer, to help inspecting intrusive lists when
debugging GDB with GDB. Here's an example of the output:
(top-gdb) p current_inferior_.m_obj.thread_list
$1 = intrusive list of thread_info = {0x61700002c000, 0x617000069080, 0x617000069400, 0x61700006d680, 0x61700006eb80}
It's not possible with current master, but with this patch [1] that I
hope will be merged eventually, it's possible to index the list and
access the pretty-printed value's children:
(top-gdb) p current_inferior_.m_obj.thread_list[1]
$2 = (thread_info *) 0x617000069080
(top-gdb) p current_inferior_.m_obj.thread_list[1].ptid
$3 = {
m_pid = 406499,
m_lwp = 406503,
m_tid = 0
}
Even though iterating the list in C++ yields references, the Python
pretty-printer yields pointers. The reason for this is that the output
of printing the thread list above would be unreadable, IMO, if each
thread_info object was printed in-line, since they contain so much
information. I think it's more useful to print pointers, and let the
user drill down as needed.
[1] https://sourceware.org/pipermail/gdb-patches/2021-April/178050.html
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3412a14dc77f25876d742dab8f44e0ba7c7586c0
2021-06-12 06:28:32 +08:00
|
|
|
class IntrusiveListPrinter:
|
|
|
|
"""Print a struct intrusive_list."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self._val = val
|
|
|
|
|
|
|
|
# Type of linked items.
|
|
|
|
self._item_type = self._val.type.template_argument(0)
|
|
|
|
self._node_ptr_type = gdb.lookup_type(
|
|
|
|
"intrusive_list_node<{}>".format(self._item_type.tag)
|
|
|
|
).pointer()
|
|
|
|
|
|
|
|
# Type of value -> node converter.
|
|
|
|
self._conv_type = self._val.type.template_argument(1)
|
|
|
|
|
|
|
|
if self._uses_member_node():
|
|
|
|
# The second template argument of intrusive_member_node is a member
|
|
|
|
# pointer value. Its value is the offset of the node member in the
|
|
|
|
# enclosing type.
|
|
|
|
member_node_ptr = self._conv_type.template_argument(1)
|
|
|
|
member_node_ptr = member_node_ptr.cast(gdb.lookup_type("int"))
|
|
|
|
self._member_node_offset = int(member_node_ptr)
|
|
|
|
|
|
|
|
# This is only needed in _as_node_ptr if using a member node. Look it
|
|
|
|
# up here so we only do it once.
|
|
|
|
self._char_ptr_type = gdb.lookup_type("char").pointer()
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return "array"
|
|
|
|
|
|
|
|
def _uses_member_node(self):
|
|
|
|
"""Return True if the list items use a node as a member, False if
|
|
|
|
they use a node as a base class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self._conv_type.name.startswith("intrusive_member_node<"):
|
|
|
|
return True
|
|
|
|
elif self._conv_type.name.startswith("intrusive_base_node<"):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise RuntimeError(
|
|
|
|
"Unexpected intrusive_list value -> node converter type: {}".format(
|
|
|
|
self._conv_type.name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
s = "intrusive list of {}".format(self._item_type)
|
|
|
|
|
|
|
|
if self._uses_member_node():
|
|
|
|
node_member = self._conv_type.template_argument(1)
|
|
|
|
s += ", linked through {}".format(node_member)
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
def _as_node_ptr(self, elem_ptr):
|
|
|
|
"""Given ELEM_PTR, a pointer to a list element, return a pointer to the
|
|
|
|
corresponding intrusive_list_node.
|
|
|
|
"""
|
|
|
|
|
|
|
|
assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
|
|
|
|
|
|
|
|
if self._uses_member_node():
|
|
|
|
# Node as a member: add the member node offset from to the element's
|
|
|
|
# address to get the member node's address.
|
|
|
|
elem_char_ptr = elem_ptr.cast(self._char_ptr_type)
|
|
|
|
node_char_ptr = elem_char_ptr + self._member_node_offset
|
|
|
|
return node_char_ptr.cast(self._node_ptr_type)
|
|
|
|
else:
|
|
|
|
# Node as a base: just casting from node pointer to item pointer
|
|
|
|
# will adjust the pointer value.
|
|
|
|
return elem_ptr.cast(self._node_ptr_type)
|
|
|
|
|
|
|
|
def _children_generator(self):
|
|
|
|
"""Generator that yields one tuple per list item."""
|
|
|
|
|
|
|
|
elem_ptr = self._val["m_front"]
|
|
|
|
idx = 0
|
|
|
|
while elem_ptr != 0:
|
|
|
|
yield (str(idx), elem_ptr.dereference())
|
|
|
|
node_ptr = self._as_node_ptr(elem_ptr)
|
|
|
|
elem_ptr = node_ptr["next"]
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
return self._children_generator()
|
|
|
|
|
|
|
|
|
2023-02-10 03:50:56 +08:00
|
|
|
class HtabPrinter:
|
|
|
|
"""Pretty-printer for htab_t hash tables."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self._val = val
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return "array"
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
n = int(self._val["n_elements"]) - int(self._val["n_deleted"])
|
|
|
|
return "htab_t with {} elements".format(n)
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
size = int(self._val["size"])
|
|
|
|
entries = self._val["entries"]
|
|
|
|
|
|
|
|
child_i = 0
|
|
|
|
for entries_i in range(size):
|
|
|
|
entry = entries[entries_i]
|
|
|
|
# 0 (NULL pointer) means there's nothing, 1 (HTAB_DELETED_ENTRY)
|
|
|
|
# means there was something, but is now deleted.
|
|
|
|
if int(entry) in (0, 1):
|
|
|
|
continue
|
|
|
|
|
|
|
|
yield (str(child_i), entry)
|
|
|
|
child_i += 1
|
|
|
|
|
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def type_lookup_function(val):
|
|
|
|
"""A routine that returns the correct pretty printer for VAL
|
|
|
|
if appropriate. Returns None otherwise.
|
|
|
|
"""
|
gdb: introduce intrusive_list, make thread_info use it
GDB currently has several objects that are put in a singly linked list,
by having the object's type have a "next" pointer directly. For
example, struct thread_info and struct inferior. Because these are
simply-linked lists, and we don't keep track of a "tail" pointer, when
we want to append a new element on the list, we need to walk the whole
list to find the current tail. It would be nice to get rid of that
walk. Removing elements from such lists also requires a walk, to find
the "previous" position relative to the element being removed. To
eliminate the need for that walk, we could make those lists
doubly-linked, by adding a "prev" pointer alongside "next". It would be
nice to avoid the boilerplate associated with maintaining such a list
manually, though. That is what the new intrusive_list type addresses.
With an intrusive list, it's also possible to move items out of the
list without destroying them, which is interesting in our case for
example for threads, when we exit them, but can't destroy them
immediately. We currently keep exited threads on the thread list, but
we could change that which would simplify some things.
Note that with std::list, element removal is O(N). I.e., with
std::list, we need to walk the list to find the iterator pointing to
the position to remove. However, we could store a list iterator
inside the object as soon as we put the object in the list, to address
it, because std::list iterators are not invalidated when other
elements are added/removed. However, if you need to put the same
object in more than one list, then std::list<object> doesn't work.
You need to instead use std::list<object *>, which is less efficient
for requiring extra memory allocations. For an example of an object
in multiple lists, see the step_over_next/step_over_prev fields in
thread_info:
/* Step-over chain. A thread is in the step-over queue if these are
non-NULL. If only a single thread is in the chain, then these
fields point to self. */
struct thread_info *step_over_prev = NULL;
struct thread_info *step_over_next = NULL;
The new intrusive_list type gives us the advantages of an intrusive
linked list, while avoiding the boilerplate associated with manually
maintaining it.
intrusive_list's API follows the standard container interface, and thus
std::list's interface. It is based the API of Boost's intrusive list,
here:
https://www.boost.org/doc/libs/1_73_0/doc/html/boost/intrusive/list.html
Our implementation is relatively simple, while Boost's is complicated
and intertwined due to a lot of customization options, which our version
doesn't have.
The easiest way to use an intrusive_list is to make the list's element
type inherit from intrusive_node. This adds a prev/next pointers to
the element type. However, to support putting the same object in more
than one list, intrusive_list supports putting the "node" info as a
field member, so you can have more than one such nodes, one per list.
As a first guinea pig, this patch makes the per-inferior thread list use
intrusive_list using the base class method.
Unlike Boost's implementation, ours is not a circular list. An earlier
version of the patch was circular: the intrusive_list type included an
intrusive_list_node "head". In this design, a node contained pointers
to the previous and next nodes, not the previous and next elements.
This wasn't great for when debugging GDB with GDB, as it was difficult
to get from a pointer to the node to a pointer to the element. With the
design proposed in this patch, nodes contain pointers to the previous
and next elements, making it easy to traverse the list by hand and
inspect each element.
The intrusive_list object contains pointers to the first and last
elements of the list. They are nullptr if the list is empty.
Each element's node contains a pointer to the previous and next
elements. The first element's previous pointer is nullptr and the last
element's next pointer is nullptr. Therefore, if there's a single
element in the list, both its previous and next pointers are nullptr.
To differentiate such an element from an element that is not linked into
a list, the previous and next pointers contain a special value (-1) when
the node is not linked. This is necessary to be able to reliably tell
if a given node is currently linked or not.
A begin() iterator points to the first item in the list. An end()
iterator contains nullptr. This makes iteration until end naturally
work, as advancing past the last element will make the iterator contain
nullptr, making it equal to the end iterator. If the list is empty,
a begin() iterator will contain nullptr from the start, and therefore be
immediately equal to the end.
Iterating on an intrusive_list yields references to objects (e.g.
`thread_info&`). The rest of GDB currently expects iterators and ranges
to yield pointers (e.g. `thread_info*`). To bridge the gap, add the
reference_to_pointer_iterator type. It is used to define
inf_threads_iterator.
Add a Python pretty-printer, to help inspecting intrusive lists when
debugging GDB with GDB. Here's an example of the output:
(top-gdb) p current_inferior_.m_obj.thread_list
$1 = intrusive list of thread_info = {0x61700002c000, 0x617000069080, 0x617000069400, 0x61700006d680, 0x61700006eb80}
It's not possible with current master, but with this patch [1] that I
hope will be merged eventually, it's possible to index the list and
access the pretty-printed value's children:
(top-gdb) p current_inferior_.m_obj.thread_list[1]
$2 = (thread_info *) 0x617000069080
(top-gdb) p current_inferior_.m_obj.thread_list[1].ptid
$3 = {
m_pid = 406499,
m_lwp = 406503,
m_tid = 0
}
Even though iterating the list in C++ yields references, the Python
pretty-printer yields pointers. The reason for this is that the output
of printing the thread list above would be unreadable, IMO, if each
thread_info object was printed in-line, since they contain so much
information. I think it's more useful to print pointers, and let the
user drill down as needed.
[1] https://sourceware.org/pipermail/gdb-patches/2021-April/178050.html
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3412a14dc77f25876d742dab8f44e0ba7c7586c0
2021-06-12 06:28:32 +08:00
|
|
|
tag = val.type.tag
|
|
|
|
name = val.type.name
|
|
|
|
if tag == "type":
|
2010-01-06 11:46:18 +08:00
|
|
|
return StructTypePrettyPrinter(val)
|
gdb: introduce intrusive_list, make thread_info use it
GDB currently has several objects that are put in a singly linked list,
by having the object's type have a "next" pointer directly. For
example, struct thread_info and struct inferior. Because these are
simply-linked lists, and we don't keep track of a "tail" pointer, when
we want to append a new element on the list, we need to walk the whole
list to find the current tail. It would be nice to get rid of that
walk. Removing elements from such lists also requires a walk, to find
the "previous" position relative to the element being removed. To
eliminate the need for that walk, we could make those lists
doubly-linked, by adding a "prev" pointer alongside "next". It would be
nice to avoid the boilerplate associated with maintaining such a list
manually, though. That is what the new intrusive_list type addresses.
With an intrusive list, it's also possible to move items out of the
list without destroying them, which is interesting in our case for
example for threads, when we exit them, but can't destroy them
immediately. We currently keep exited threads on the thread list, but
we could change that which would simplify some things.
Note that with std::list, element removal is O(N). I.e., with
std::list, we need to walk the list to find the iterator pointing to
the position to remove. However, we could store a list iterator
inside the object as soon as we put the object in the list, to address
it, because std::list iterators are not invalidated when other
elements are added/removed. However, if you need to put the same
object in more than one list, then std::list<object> doesn't work.
You need to instead use std::list<object *>, which is less efficient
for requiring extra memory allocations. For an example of an object
in multiple lists, see the step_over_next/step_over_prev fields in
thread_info:
/* Step-over chain. A thread is in the step-over queue if these are
non-NULL. If only a single thread is in the chain, then these
fields point to self. */
struct thread_info *step_over_prev = NULL;
struct thread_info *step_over_next = NULL;
The new intrusive_list type gives us the advantages of an intrusive
linked list, while avoiding the boilerplate associated with manually
maintaining it.
intrusive_list's API follows the standard container interface, and thus
std::list's interface. It is based the API of Boost's intrusive list,
here:
https://www.boost.org/doc/libs/1_73_0/doc/html/boost/intrusive/list.html
Our implementation is relatively simple, while Boost's is complicated
and intertwined due to a lot of customization options, which our version
doesn't have.
The easiest way to use an intrusive_list is to make the list's element
type inherit from intrusive_node. This adds a prev/next pointers to
the element type. However, to support putting the same object in more
than one list, intrusive_list supports putting the "node" info as a
field member, so you can have more than one such nodes, one per list.
As a first guinea pig, this patch makes the per-inferior thread list use
intrusive_list using the base class method.
Unlike Boost's implementation, ours is not a circular list. An earlier
version of the patch was circular: the intrusive_list type included an
intrusive_list_node "head". In this design, a node contained pointers
to the previous and next nodes, not the previous and next elements.
This wasn't great for when debugging GDB with GDB, as it was difficult
to get from a pointer to the node to a pointer to the element. With the
design proposed in this patch, nodes contain pointers to the previous
and next elements, making it easy to traverse the list by hand and
inspect each element.
The intrusive_list object contains pointers to the first and last
elements of the list. They are nullptr if the list is empty.
Each element's node contains a pointer to the previous and next
elements. The first element's previous pointer is nullptr and the last
element's next pointer is nullptr. Therefore, if there's a single
element in the list, both its previous and next pointers are nullptr.
To differentiate such an element from an element that is not linked into
a list, the previous and next pointers contain a special value (-1) when
the node is not linked. This is necessary to be able to reliably tell
if a given node is currently linked or not.
A begin() iterator points to the first item in the list. An end()
iterator contains nullptr. This makes iteration until end naturally
work, as advancing past the last element will make the iterator contain
nullptr, making it equal to the end iterator. If the list is empty,
a begin() iterator will contain nullptr from the start, and therefore be
immediately equal to the end.
Iterating on an intrusive_list yields references to objects (e.g.
`thread_info&`). The rest of GDB currently expects iterators and ranges
to yield pointers (e.g. `thread_info*`). To bridge the gap, add the
reference_to_pointer_iterator type. It is used to define
inf_threads_iterator.
Add a Python pretty-printer, to help inspecting intrusive lists when
debugging GDB with GDB. Here's an example of the output:
(top-gdb) p current_inferior_.m_obj.thread_list
$1 = intrusive list of thread_info = {0x61700002c000, 0x617000069080, 0x617000069400, 0x61700006d680, 0x61700006eb80}
It's not possible with current master, but with this patch [1] that I
hope will be merged eventually, it's possible to index the list and
access the pretty-printed value's children:
(top-gdb) p current_inferior_.m_obj.thread_list[1]
$2 = (thread_info *) 0x617000069080
(top-gdb) p current_inferior_.m_obj.thread_list[1].ptid
$3 = {
m_pid = 406499,
m_lwp = 406503,
m_tid = 0
}
Even though iterating the list in C++ yields references, the Python
pretty-printer yields pointers. The reason for this is that the output
of printing the thread list above would be unreadable, IMO, if each
thread_info object was printed in-line, since they contain so much
information. I think it's more useful to print pointers, and let the
user drill down as needed.
[1] https://sourceware.org/pipermail/gdb-patches/2021-April/178050.html
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3412a14dc77f25876d742dab8f44e0ba7c7586c0
2021-06-12 06:28:32 +08:00
|
|
|
elif tag == "main_type":
|
2010-01-06 11:46:18 +08:00
|
|
|
return StructMainTypePrettyPrinter(val)
|
gdb: introduce intrusive_list, make thread_info use it
GDB currently has several objects that are put in a singly linked list,
by having the object's type have a "next" pointer directly. For
example, struct thread_info and struct inferior. Because these are
simply-linked lists, and we don't keep track of a "tail" pointer, when
we want to append a new element on the list, we need to walk the whole
list to find the current tail. It would be nice to get rid of that
walk. Removing elements from such lists also requires a walk, to find
the "previous" position relative to the element being removed. To
eliminate the need for that walk, we could make those lists
doubly-linked, by adding a "prev" pointer alongside "next". It would be
nice to avoid the boilerplate associated with maintaining such a list
manually, though. That is what the new intrusive_list type addresses.
With an intrusive list, it's also possible to move items out of the
list without destroying them, which is interesting in our case for
example for threads, when we exit them, but can't destroy them
immediately. We currently keep exited threads on the thread list, but
we could change that which would simplify some things.
Note that with std::list, element removal is O(N). I.e., with
std::list, we need to walk the list to find the iterator pointing to
the position to remove. However, we could store a list iterator
inside the object as soon as we put the object in the list, to address
it, because std::list iterators are not invalidated when other
elements are added/removed. However, if you need to put the same
object in more than one list, then std::list<object> doesn't work.
You need to instead use std::list<object *>, which is less efficient
for requiring extra memory allocations. For an example of an object
in multiple lists, see the step_over_next/step_over_prev fields in
thread_info:
/* Step-over chain. A thread is in the step-over queue if these are
non-NULL. If only a single thread is in the chain, then these
fields point to self. */
struct thread_info *step_over_prev = NULL;
struct thread_info *step_over_next = NULL;
The new intrusive_list type gives us the advantages of an intrusive
linked list, while avoiding the boilerplate associated with manually
maintaining it.
intrusive_list's API follows the standard container interface, and thus
std::list's interface. It is based the API of Boost's intrusive list,
here:
https://www.boost.org/doc/libs/1_73_0/doc/html/boost/intrusive/list.html
Our implementation is relatively simple, while Boost's is complicated
and intertwined due to a lot of customization options, which our version
doesn't have.
The easiest way to use an intrusive_list is to make the list's element
type inherit from intrusive_node. This adds a prev/next pointers to
the element type. However, to support putting the same object in more
than one list, intrusive_list supports putting the "node" info as a
field member, so you can have more than one such nodes, one per list.
As a first guinea pig, this patch makes the per-inferior thread list use
intrusive_list using the base class method.
Unlike Boost's implementation, ours is not a circular list. An earlier
version of the patch was circular: the intrusive_list type included an
intrusive_list_node "head". In this design, a node contained pointers
to the previous and next nodes, not the previous and next elements.
This wasn't great for when debugging GDB with GDB, as it was difficult
to get from a pointer to the node to a pointer to the element. With the
design proposed in this patch, nodes contain pointers to the previous
and next elements, making it easy to traverse the list by hand and
inspect each element.
The intrusive_list object contains pointers to the first and last
elements of the list. They are nullptr if the list is empty.
Each element's node contains a pointer to the previous and next
elements. The first element's previous pointer is nullptr and the last
element's next pointer is nullptr. Therefore, if there's a single
element in the list, both its previous and next pointers are nullptr.
To differentiate such an element from an element that is not linked into
a list, the previous and next pointers contain a special value (-1) when
the node is not linked. This is necessary to be able to reliably tell
if a given node is currently linked or not.
A begin() iterator points to the first item in the list. An end()
iterator contains nullptr. This makes iteration until end naturally
work, as advancing past the last element will make the iterator contain
nullptr, making it equal to the end iterator. If the list is empty,
a begin() iterator will contain nullptr from the start, and therefore be
immediately equal to the end.
Iterating on an intrusive_list yields references to objects (e.g.
`thread_info&`). The rest of GDB currently expects iterators and ranges
to yield pointers (e.g. `thread_info*`). To bridge the gap, add the
reference_to_pointer_iterator type. It is used to define
inf_threads_iterator.
Add a Python pretty-printer, to help inspecting intrusive lists when
debugging GDB with GDB. Here's an example of the output:
(top-gdb) p current_inferior_.m_obj.thread_list
$1 = intrusive list of thread_info = {0x61700002c000, 0x617000069080, 0x617000069400, 0x61700006d680, 0x61700006eb80}
It's not possible with current master, but with this patch [1] that I
hope will be merged eventually, it's possible to index the list and
access the pretty-printed value's children:
(top-gdb) p current_inferior_.m_obj.thread_list[1]
$2 = (thread_info *) 0x617000069080
(top-gdb) p current_inferior_.m_obj.thread_list[1].ptid
$3 = {
m_pid = 406499,
m_lwp = 406503,
m_tid = 0
}
Even though iterating the list in C++ yields references, the Python
pretty-printer yields pointers. The reason for this is that the output
of printing the thread list above would be unreadable, IMO, if each
thread_info object was printed in-line, since they contain so much
information. I think it's more useful to print pointers, and let the
user drill down as needed.
[1] https://sourceware.org/pipermail/gdb-patches/2021-April/178050.html
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3412a14dc77f25876d742dab8f44e0ba7c7586c0
2021-06-12 06:28:32 +08:00
|
|
|
elif name == "CORE_ADDR":
|
2018-06-28 03:21:47 +08:00
|
|
|
return CoreAddrPrettyPrinter(val)
|
gdb: introduce intrusive_list, make thread_info use it
GDB currently has several objects that are put in a singly linked list,
by having the object's type have a "next" pointer directly. For
example, struct thread_info and struct inferior. Because these are
simply-linked lists, and we don't keep track of a "tail" pointer, when
we want to append a new element on the list, we need to walk the whole
list to find the current tail. It would be nice to get rid of that
walk. Removing elements from such lists also requires a walk, to find
the "previous" position relative to the element being removed. To
eliminate the need for that walk, we could make those lists
doubly-linked, by adding a "prev" pointer alongside "next". It would be
nice to avoid the boilerplate associated with maintaining such a list
manually, though. That is what the new intrusive_list type addresses.
With an intrusive list, it's also possible to move items out of the
list without destroying them, which is interesting in our case for
example for threads, when we exit them, but can't destroy them
immediately. We currently keep exited threads on the thread list, but
we could change that which would simplify some things.
Note that with std::list, element removal is O(N). I.e., with
std::list, we need to walk the list to find the iterator pointing to
the position to remove. However, we could store a list iterator
inside the object as soon as we put the object in the list, to address
it, because std::list iterators are not invalidated when other
elements are added/removed. However, if you need to put the same
object in more than one list, then std::list<object> doesn't work.
You need to instead use std::list<object *>, which is less efficient
for requiring extra memory allocations. For an example of an object
in multiple lists, see the step_over_next/step_over_prev fields in
thread_info:
/* Step-over chain. A thread is in the step-over queue if these are
non-NULL. If only a single thread is in the chain, then these
fields point to self. */
struct thread_info *step_over_prev = NULL;
struct thread_info *step_over_next = NULL;
The new intrusive_list type gives us the advantages of an intrusive
linked list, while avoiding the boilerplate associated with manually
maintaining it.
intrusive_list's API follows the standard container interface, and thus
std::list's interface. It is based the API of Boost's intrusive list,
here:
https://www.boost.org/doc/libs/1_73_0/doc/html/boost/intrusive/list.html
Our implementation is relatively simple, while Boost's is complicated
and intertwined due to a lot of customization options, which our version
doesn't have.
The easiest way to use an intrusive_list is to make the list's element
type inherit from intrusive_node. This adds a prev/next pointers to
the element type. However, to support putting the same object in more
than one list, intrusive_list supports putting the "node" info as a
field member, so you can have more than one such nodes, one per list.
As a first guinea pig, this patch makes the per-inferior thread list use
intrusive_list using the base class method.
Unlike Boost's implementation, ours is not a circular list. An earlier
version of the patch was circular: the intrusive_list type included an
intrusive_list_node "head". In this design, a node contained pointers
to the previous and next nodes, not the previous and next elements.
This wasn't great for when debugging GDB with GDB, as it was difficult
to get from a pointer to the node to a pointer to the element. With the
design proposed in this patch, nodes contain pointers to the previous
and next elements, making it easy to traverse the list by hand and
inspect each element.
The intrusive_list object contains pointers to the first and last
elements of the list. They are nullptr if the list is empty.
Each element's node contains a pointer to the previous and next
elements. The first element's previous pointer is nullptr and the last
element's next pointer is nullptr. Therefore, if there's a single
element in the list, both its previous and next pointers are nullptr.
To differentiate such an element from an element that is not linked into
a list, the previous and next pointers contain a special value (-1) when
the node is not linked. This is necessary to be able to reliably tell
if a given node is currently linked or not.
A begin() iterator points to the first item in the list. An end()
iterator contains nullptr. This makes iteration until end naturally
work, as advancing past the last element will make the iterator contain
nullptr, making it equal to the end iterator. If the list is empty,
a begin() iterator will contain nullptr from the start, and therefore be
immediately equal to the end.
Iterating on an intrusive_list yields references to objects (e.g.
`thread_info&`). The rest of GDB currently expects iterators and ranges
to yield pointers (e.g. `thread_info*`). To bridge the gap, add the
reference_to_pointer_iterator type. It is used to define
inf_threads_iterator.
Add a Python pretty-printer, to help inspecting intrusive lists when
debugging GDB with GDB. Here's an example of the output:
(top-gdb) p current_inferior_.m_obj.thread_list
$1 = intrusive list of thread_info = {0x61700002c000, 0x617000069080, 0x617000069400, 0x61700006d680, 0x61700006eb80}
It's not possible with current master, but with this patch [1] that I
hope will be merged eventually, it's possible to index the list and
access the pretty-printed value's children:
(top-gdb) p current_inferior_.m_obj.thread_list[1]
$2 = (thread_info *) 0x617000069080
(top-gdb) p current_inferior_.m_obj.thread_list[1].ptid
$3 = {
m_pid = 406499,
m_lwp = 406503,
m_tid = 0
}
Even though iterating the list in C++ yields references, the Python
pretty-printer yields pointers. The reason for this is that the output
of printing the thread list above would be unreadable, IMO, if each
thread_info object was printed in-line, since they contain so much
information. I think it's more useful to print pointers, and let the
user drill down as needed.
[1] https://sourceware.org/pipermail/gdb-patches/2021-April/178050.html
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3412a14dc77f25876d742dab8f44e0ba7c7586c0
2021-06-12 06:28:32 +08:00
|
|
|
elif tag is not None and tag.startswith("intrusive_list<"):
|
|
|
|
return IntrusiveListPrinter(val)
|
2023-02-10 03:50:56 +08:00
|
|
|
elif name == "htab_t":
|
|
|
|
return HtabPrinter(val)
|
2010-01-06 11:46:18 +08:00
|
|
|
return None
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def register_pretty_printer(objfile):
|
2021-05-18 02:31:00 +08:00
|
|
|
"""A routine to register a pretty-printer against the given OBJFILE."""
|
2010-01-06 11:46:18 +08:00
|
|
|
objfile.pretty_printers.append(type_lookup_function)
|
|
|
|
|
2018-06-28 03:31:05 +08:00
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if gdb.current_objfile() is not None:
|
|
|
|
# This is the case where this script is being "auto-loaded"
|
|
|
|
# for a given objfile. Register the pretty-printer for that
|
|
|
|
# objfile.
|
|
|
|
register_pretty_printer(gdb.current_objfile())
|
|
|
|
else:
|
|
|
|
# We need to locate the objfile corresponding to the GDB
|
|
|
|
# executable, and register the pretty-printer for that objfile.
|
|
|
|
# FIXME: The condition used to match the objfile is too simplistic
|
|
|
|
# and will not work on Windows.
|
|
|
|
for objfile in gdb.objfiles():
|
|
|
|
if os.path.basename(objfile.filename) == "gdb":
|
|
|
|
objfile.pretty_printers.append(type_lookup_function)
|