2022-01-01 22:56:03 +08:00
|
|
|
# Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
2019-04-01 15:59:53 +08:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
# This file is part of the GDB testsuite. It tests python pretty
|
|
|
|
# printers.
|
|
|
|
|
|
|
|
import gdb
|
|
|
|
|
2022-06-06 23:54:45 +08:00
|
|
|
saved_options = {}
|
|
|
|
|
2021-05-07 22:56:20 +08:00
|
|
|
|
|
|
|
class PointPrinter(object):
|
|
|
|
def __init__(self, val):
|
2019-04-01 15:59:53 +08:00
|
|
|
self.val = val
|
|
|
|
|
2021-05-07 22:56:20 +08:00
|
|
|
def to_string(self):
|
2022-06-06 23:54:45 +08:00
|
|
|
global saved_options
|
|
|
|
saved_options = gdb.print_options()
|
2022-06-07 21:05:02 +08:00
|
|
|
if saved_options["summary"]:
|
|
|
|
return "No Data"
|
2021-05-07 22:56:20 +08:00
|
|
|
return "Pretty Point (%s, %s)" % (self.val["x"], self.val["y"])
|
|
|
|
|
2019-04-01 15:59:53 +08:00
|
|
|
|
2021-05-07 22:56:20 +08:00
|
|
|
def test_lookup_function(val):
|
2019-04-01 15:59:53 +08:00
|
|
|
"Look-up and return a pretty-printer that can print val."
|
|
|
|
|
|
|
|
# Get the type.
|
|
|
|
type = val.type
|
|
|
|
|
|
|
|
# If it points to a reference, get the reference.
|
|
|
|
if type.code == gdb.TYPE_CODE_REF:
|
2021-05-07 22:56:20 +08:00
|
|
|
type = type.target()
|
2019-04-01 15:59:53 +08:00
|
|
|
|
|
|
|
# Get the unqualified type, stripped of typedefs.
|
2021-05-07 22:56:20 +08:00
|
|
|
type = type.unqualified().strip_typedefs()
|
2019-04-01 15:59:53 +08:00
|
|
|
|
|
|
|
# Get the type name.
|
|
|
|
typename = type.tag
|
|
|
|
|
2021-05-07 22:56:20 +08:00
|
|
|
if typename == "point":
|
|
|
|
return PointPrinter(val)
|
2019-04-01 15:59:53 +08:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
2021-05-07 22:56:20 +08:00
|
|
|
|
|
|
|
gdb.pretty_printers.append(test_lookup_function)
|