mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-02 13:45:42 +00:00
Andry pointed out that the DAP code did not properly handle
gdb.LazyString results from a pretty-printer, yielding:
TypeError: Object of type LazyString is not JSON serializable
This patch fixes the problem, partly with a small patch in varref.py,
but mainly by implementing tp_str for LazyString.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
# Copyright (C) 2022-2023 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/>.
|
|
|
|
|
|
import gdb
|
|
|
|
|
|
class Printer(gdb.ValuePrinter):
|
|
"""Pretty print a string"""
|
|
|
|
def __init__(self, val):
|
|
self._val = val
|
|
|
|
def to_string(self):
|
|
return self._val.lazy_string()
|
|
|
|
|
|
def lookup_function(val):
|
|
typ = val.type
|
|
if typ.code == gdb.TYPE_CODE_PTR:
|
|
return Printer(val)
|
|
return None
|
|
|
|
|
|
gdb.pretty_printers.append(lookup_function)
|