Skip to content

Commit dfe844c

Browse files
gdb-stubs fixes (#9439)
* fix: Union subprinters with `None` See https://github.com/bminor/binutils-gdb/blob/a4418a9c6f99fd31c51698b1f6a6f8dbc1b81b6f/gdb/python/lib/gdb/printing.py#L52-L55 * fix: Allow callables as argument to `printer` See https://github.com/bminor/binutils-gdb/blob/a4418a9c6f99fd31c51698b1f6a6f8dbc1b81b6f/gdb/python/lib/gdb/printing.py#L77 and the description of "function / old way" in the body of `register_pretty_printer`. The new union's signature is equivalent to `gdb.printing.PrettyPrinter(...).__call__`. * fix: make `gdb.Block` iterable over `gdb.Symbol` See https://sourceware.org/gdb/onlinedocs/gdb/Blocks-In-Python.html#Blocks-In-Python: > A gdb.Block is iterable. The iterator returns the symbols (see [Symbols In Python](https://sourceware.org/gdb/onlinedocs/gdb/Symbols-In-Python.html#Symbols-In-Python)) local to the block. Implementation of `gdb.BlockIterator` is given in https://github.com/bminor/binutils-gdb/blob/gdb-12-branch/gdb/python/py-block.c. As with many of the other classes, `BlockIterator` is actually imported from the built-in `_gdb` module (https://github.com/bminor/binutils-gdb/blob/a4418a9c6f99fd31c51698b1f6a6f8dbc1b81b6f/gdb/python/lib/gdb/__init__.py#L28). Co-authored-by: Alex Waygood <[email protected]>
1 parent 605378d commit dfe844c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

stubs/gdb/gdb/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ class Block:
492492
is_static: bool
493493

494494
def is_valid(self) -> bool: ...
495+
def __iter__(self) -> BlockIterator: ...
496+
497+
class BlockIterator:
498+
def is_valid(self) -> bool: ...
499+
def __iter__(self: _typeshed.Self) -> _typeshed.Self: ...
500+
def __next__(self) -> Symbol: ...
495501

496502
# Symbols
497503

stubs/gdb/gdb/printing.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from collections.abc import Iterable
1+
from collections.abc import Callable, Iterable
22

33
import gdb
44
from gdb import _PrettyPrinterLookupFunction
55

66
class PrettyPrinter:
77

88
name: str
9-
subprinters: list[SubPrettyPrinter]
9+
subprinters: list[SubPrettyPrinter] | None
1010
enabled: bool
1111

1212
def __init__(self, name: str, subprinters: Iterable[SubPrettyPrinter] | None = ...) -> None: ...
@@ -26,4 +26,8 @@ class RegexpCollectionPrettyPrinter(PrettyPrinter):
2626
class FlagEnumerationPrinter(PrettyPrinter):
2727
def __init__(self, enum_type: str) -> None: ...
2828

29-
def register_pretty_printer(obj: gdb.Objfile | gdb.Progspace | None, printer: PrettyPrinter, replace: bool = ...) -> None: ...
29+
def register_pretty_printer(
30+
obj: gdb.Objfile | gdb.Progspace | None,
31+
printer: PrettyPrinter | Callable[[gdb.Value], gdb._PrettyPrinter | None],
32+
replace: bool = ...,
33+
) -> None: ...

0 commit comments

Comments
 (0)