Files
fennec/gdb/fennec/filesystem.py

60 lines
2.3 KiB
Python

# ======================================================================================================================
# 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 gdb
# PATH =================================================================================================================
class PathPrinter:
def __init__(self, val):
self.val = val['_str']['_str']
def to_string(self):
value = "\"" + self.val['_data'].string('', 'replace', self.val['_capacity'] - 1) + "\""
return value
def display_hint(self):
return 'string'
# PATH =================================================================================================================
class FilePrinter:
def __init__(self, val):
self.val = val
self.path = val['_path']['_str']['_str']
def to_string(self):
if self.val['_handle']:
value = "{ path = \"" + self.path['_data'].string('', 'replace', self.path['_capacity'] - 1) + "\" }"
return value
return "{ closed }"
def display_hint(self):
return 'string'
# GDB Code =============================================================================================================
def register_printers():
print("registering filesystem")
pp = gdb.printing.RegexpCollectionPrettyPrinter("fennec::filesystem")
pp.add_printer('fennec::path', '^fennec::path$', PathPrinter)
pp.add_printer('fennec::file', '^fennec::file$', FilePrinter)
return pp
printer = register_printers()