- Implemented PrettyPrinters for vector, quaternion, and matrix

This commit is contained in:
2025-08-11 17:39:51 -04:00
parent 74fb525453
commit d6e31a89b0
2 changed files with 102 additions and 1 deletions

View File

@@ -26,9 +26,11 @@ from . import strings
from . import memory
from . import utility
from . import filesystem
from . import math
def register_printers(obj):
gdb.printing.register_pretty_printer(obj, containers.printer)
gdb.printing.register_pretty_printer(obj, strings.printer)
gdb.printing.register_pretty_printer(obj, memory.printer)
gdb.printing.register_pretty_printer(obj, filesystem.printer)
gdb.printing.register_pretty_printer(obj, filesystem.printer)
gdb.printing.register_pretty_printer(obj, math.printer)

99
gdb/fennec/math.py Normal file
View File

@@ -0,0 +1,99 @@
# ======================================================================================================================
# fennec, a free and open source game engine
# Copyright © 2025 Medusa Slockbower
#
# 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 <https://www.gnu.org/licenses/>.
# ======================================================================================================================
import os
import gdb
from . import utility
# VECTOR =================================================================================================================
class VectorPrinter:
def __init__(self, val):
self.val = val
self.base = val['data']['elements']
self.len = self.base.type.range()[1] + 1
def to_string(self):
res = "< "
if self.len > 0:
res += "x = " + str(self.val['x'])
if self.len > 1:
res += ", y = " + str(self.val['y'])
if self.len > 2:
res += ", z = " + str(self.val['z'])
if self.len > 3:
res += ", w = " + str(self.val['w'])
res += " >"
return res
def children(self):
return (('[{}]'.format(i), self.base[i]) for i in range(self.len))
def display_hint(self):
return 'array'
# PATH =================================================================================================================
class QuaternionPrinter:
def __init__(self, val):
self.val = val
self.base = val['data']['elements']
def to_string(self):
res = ("< "
+ str(self.val['x']) + " i + "
+ str(self.val['y']) + " j + "
+ str(self.val['z']) + " k + "
+ str(self.val['w']))
res += " >"
return res
def children(self):
return (('[{}]'.format(i), self.base[i]) for i in range(4))
def display_hint(self):
return 'array'
# VECTOR =================================================================================================================
class MatrixPrinter:
def __init__(self, val):
self.columns = val['data']['elements']
self.num_columns = self.columns.type.range()[1] + 1
self.num_rows = val.type.template_argument(1)
def to_string(self):
return "{ rows = " + str(self.num_rows) + ", columns = " + str(self.num_columns) + " }"
def children(self):
return (('[{}]'.format(i), self.columns[i]) for i in range(self.num_columns))
def display_hint(self):
return 'array'
# GDB Code =============================================================================================================
def register_printers():
print("registering filesystem")
pp = gdb.printing.RegexpCollectionPrettyPrinter("fennec::math")
pp.add_printer('fennec::vector', '^fennec::vector<.*>$', VectorPrinter)
pp.add_printer('fennec::quaternion', '^fennec::quaternion<.*>$', QuaternionPrinter)
pp.add_printer('fennec::matrix', '^fennec::matrix<.*>$', MatrixPrinter)
return pp
printer = register_printers()