c0d4881122
Consider the following declarations: typedef long our_time_t; our_time_t current_time = 1384395743; The purpose of this patch is to allow the use of a pretty-printer for variables of type our_time_t. Normally, pretty-printing sniffers use the tag name in order to determine which, if any, pretty-printer should be used. But in the case above, the tag name is not set, since it does not apply to integral types. This patch extends the gdb.Type list of attributes to also include the name of the type, thus allowing the sniffer to match against that name. With that change, I was able to write a pretty-printer which displays our variable as follow: (gdb) print current_time $1 = Thu Nov 14 02:22:23 2013 (1384395743) gdb/ChangeLog: * python/py-type.c (typy_get_name): New function. (type_object_getset): Add entry for attribute "name". * NEWS: Add entry mentioning this new attribute. gdb/doc/ChangeLog: * gdb.texinfo (Types In Python): Document new attribute Types.name. gdb/testsuite: * gdb.python/py-pp-integral.c: New file. * gdb.python/py-pp-integral.py: New file. * gdb.python/py-pp-integral.exp: New file. Tested on x86_64-linux.
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
# Copyright (C) 2013-2014 Free Software Foundation, Inc.
|
|
|
|
# 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/>.
|
|
|
|
from time import asctime, gmtime
|
|
import gdb # silence pyflakes
|
|
|
|
|
|
class TimePrinter:
|
|
def __init__(self, val):
|
|
self.val = val
|
|
|
|
def to_string(self):
|
|
secs = int(self.val)
|
|
return "%s (%d)" % (asctime(gmtime(secs)), secs)
|
|
|
|
|
|
def time_sniffer(val):
|
|
if hasattr(val.type, 'name') and val.type.name == "time_t":
|
|
return TimePrinter(val)
|
|
return None
|
|
|
|
|
|
gdb.pretty_printers.append(time_sniffer)
|