| 1 |
# Pretty printing of SDL objects in GDB. |
| 2 |
# |
| 3 |
# (c) Copyright 2011 by Kalle Olavi Niemitalo. |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
|
| 19 |
""" |
| 20 |
Pretty printing of SDL objects in the GNU Debugger. |
| 21 |
This requires GDB 7.0 or later, configured --with-python. |
| 22 |
The code was written for Python 2.6.6 but may work with earlier versions too. |
| 23 |
""" |
| 24 |
|
| 25 |
import gdb |
| 26 |
|
| 27 |
class Uint8Printer: |
| 28 |
"Pretty-print a Uint8." |
| 29 |
|
| 30 |
def __init__(self, val): |
| 31 |
object.__init__(self) |
| 32 |
self.val = val |
| 33 |
|
| 34 |
def to_string(self): |
| 35 |
"Called by GDB to find what to display as the value." |
| 36 |
# Stop GDB from displaying it as a character literal. |
| 37 |
return self.val.cast(gdb.lookup_type("unsigned int")) |
| 38 |
|
| 39 |
def lookup_printer(val): |
| 40 |
"Return a printer for the value, if supported; else None." |
| 41 |
type = val.type |
| 42 |
while type.code == gdb.TYPE_CODE_TYPEDEF: |
| 43 |
tag = str(type) |
| 44 |
if tag == "Uint8": |
| 45 |
return Uint8Printer(val) |
| 46 |
type = type.target() |
| 47 |
|
| 48 |
def register_printers(objfile): |
| 49 |
"""Register all the pretty printers defined by this module. |
| 50 |
OBJFILE may be an objfile, a progspace, or the entire gdb module.""" |
| 51 |
objfile.pretty_printers.append(lookup_printer) |