1# Copyright (C) 2023-2024 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This file is part of the GDB testsuite. 17# It tests Python-based pretty-printing of stubs. 18 19 20class SPrinter: 21 def __init__(self, val): 22 self.val = val 23 24 def to_string(self): 25 char_ptr = gdb.lookup_type("char").pointer() 26 int_ptr = gdb.lookup_type("int").pointer() 27 # m_i should be after the vtable, which has the size of a pointer 28 i = ( 29 (self.val.address.cast(char_ptr) + int_ptr.sizeof) 30 .cast(int_ptr) 31 .dereference() 32 ) 33 return "{pp m_i = %d}" % int(i) 34 35 36pp = gdb.printing.RegexpCollectionPrettyPrinter("S") 37pp.add_printer("S", "^S$", SPrinter) 38gdb.printing.register_pretty_printer(gdb.current_objfile(), pp, True) 39