2019-01-01 14:01:51 +08:00
|
|
|
# Copyright (C) 2009-2019 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
|
2016-09-06 23:29:15 +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:
|
|
|
|
flag_list = [flag.short_name for flag in TYPE_FLAGS
|
|
|
|
if self.val & flag.value]
|
|
|
|
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
|
2012-04-18 14:46:47 +08:00
|
|
|
TYPE_FLAGS = [TypeFlag(field.name, field.enumval)
|
2016-09-06 23:29:15 +08:00
|
|
|
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 = []
|
|
|
|
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['instance_flags']))
|
|
|
|
fields.append("length = %d" % self.val['length'])
|
|
|
|
fields.append("main_type = %s" % self.val['main_type'])
|
|
|
|
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".
|
|
|
|
"""
|
|
|
|
fields = [field.name.replace("flag_", "")
|
|
|
|
for field in self.val.type.fields()
|
2018-06-28 03:31:05 +08:00
|
|
|
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):
|
|
|
|
"""Return an image of component "owner".
|
|
|
|
"""
|
|
|
|
if self.val['flag_objfile_owned'] != 0:
|
|
|
|
return "%s (objfile)" % self.val['owner']['objfile']
|
|
|
|
else:
|
|
|
|
return "%s (gdbarch)" % self.val['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.
|
|
|
|
"""
|
|
|
|
loc_val = field_val['loc']
|
|
|
|
loc_kind = str(field_val['loc_kind'])
|
|
|
|
if loc_kind == "FIELD_LOC_KIND_BITPOS":
|
|
|
|
return 'bitpos = %d' % loc_val['bitpos']
|
2012-04-18 14:46:47 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_ENUMVAL":
|
|
|
|
return 'enumval = %d' % loc_val['enumval']
|
2010-01-06 11:46:18 +08:00
|
|
|
elif loc_kind == "FIELD_LOC_KIND_PHYSADDR":
|
|
|
|
return 'physaddr = 0x%x' % loc_val['physaddr']
|
|
|
|
elif loc_kind == "FIELD_LOC_KIND_PHYSNAME":
|
|
|
|
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":
|
|
|
|
return 'dwarf_block = %s' % loc_val['dwarf_block']
|
2010-01-06 11:46:18 +08:00
|
|
|
else:
|
|
|
|
return 'loc = ??? (unsupported 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):
|
|
|
|
"""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
|
2010-01-06 11:46:18 +08:00
|
|
|
if f['artificial']:
|
|
|
|
label += " (artificial)"
|
|
|
|
fields = []
|
|
|
|
fields.append("name = %s" % f['name'])
|
|
|
|
fields.append("type = %s" % f['type'])
|
|
|
|
fields.append("loc_kind = %s" % f['loc_kind'])
|
|
|
|
fields.append("bitsize = %d" % f['bitsize'])
|
|
|
|
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."""
|
|
|
|
b = self.val['flds_bnds']['bounds'].dereference()[bound_name]
|
|
|
|
bnd_kind = str(b['kind'])
|
|
|
|
if bnd_kind == 'PROP_CONST':
|
|
|
|
return str(b['data']['const_val'])
|
|
|
|
elif bnd_kind == 'PROP_UNDEFINED':
|
|
|
|
return '(undefined)'
|
|
|
|
else:
|
|
|
|
info = [bnd_kind]
|
|
|
|
if bound_name == 'high' and b['flag_upper_bound_is_count']:
|
|
|
|
info.append('upper_bound_is_count')
|
|
|
|
return '{} ({})'.format(str(b['data']['baton']), ','.join(info))
|
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def bounds_img(self):
|
|
|
|
"""Return an image of the main_type bounds.
|
|
|
|
"""
|
|
|
|
b = self.val['flds_bnds']['bounds'].dereference()
|
2019-03-27 06:30:21 +08:00
|
|
|
low = self.bound_img('low')
|
|
|
|
high = self.bound_img('high')
|
|
|
|
|
|
|
|
img = "flds_bnds.bounds = {%s, %s}" % (low, high)
|
|
|
|
if b['flag_bound_evaluated']:
|
|
|
|
img += ' [evaluated]'
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
type_specific_kind = str(self.val['type_specific_field'])
|
|
|
|
type_specific = self.val['type_specific']
|
|
|
|
if type_specific_kind == "TYPE_SPECIFIC_NONE":
|
|
|
|
img = 'type_specific_field = %s' % type_specific_kind
|
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF":
|
|
|
|
img = "cplus_stuff = %s" % type_specific['cplus_stuff']
|
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_GNAT_STUFF":
|
|
|
|
img = ("gnat_stuff = {descriptive_type = %s}"
|
|
|
|
% type_specific['gnat_stuff']['descriptive_type'])
|
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_FLOATFORMAT":
|
|
|
|
img = "floatformat[0..1] = %s" % type_specific['floatformat']
|
2011-10-10 03:10:52 +08:00
|
|
|
elif type_specific_kind == "TYPE_SPECIFIC_FUNC":
|
2010-01-15 17:15:46 +08:00
|
|
|
img = ("calling_convention = %d"
|
2011-10-10 03:10:52 +08:00
|
|
|
% type_specific['func_stuff']['calling_convention'])
|
|
|
|
# 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":
|
|
|
|
img = "self_type = %s" % type_specific['self_type']
|
2010-01-15 17:15:46 +08:00
|
|
|
else:
|
|
|
|
img = ("type_specific = ??? (unknown type_secific_kind: %s)"
|
|
|
|
% type_specific_kind)
|
|
|
|
return img
|
|
|
|
|
2010-01-06 11:46:18 +08:00
|
|
|
def to_string(self):
|
|
|
|
"""Return a pretty-printed image of our main_type.
|
|
|
|
"""
|
|
|
|
fields = []
|
|
|
|
fields.append("name = %s" % self.val['name'])
|
|
|
|
fields.append("code = %s" % self.val['code'])
|
|
|
|
fields.append("flags = [%s]" % self.flags_to_string())
|
|
|
|
fields.append("owner = %s" % self.owner_to_string())
|
|
|
|
fields.append("target_type = %s" % self.val['target_type'])
|
|
|
|
if self.val['nfields'] > 0:
|
|
|
|
for fieldno in range(self.val['nfields']):
|
|
|
|
fields.append(self.struct_field_img(fieldno))
|
2010-01-16 03:22:40 +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))
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
if val.type.tag == "type":
|
|
|
|
return StructTypePrettyPrinter(val)
|
|
|
|
elif val.type.tag == "main_type":
|
|
|
|
return StructMainTypePrettyPrinter(val)
|
2018-06-28 03:21:47 +08:00
|
|
|
elif val.type.name == 'CORE_ADDR':
|
|
|
|
return CoreAddrPrettyPrinter(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):
|
|
|
|
"""A routine to register a pretty-printer against the given OBJFILE.
|
|
|
|
"""
|
|
|
|
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)
|