Rollup merge of #148540 - tromey:non-zero-gdb-cleanup, r=bjorn3

Minor fixes to StdNonZeroNumberProvider for gdb

While looking at the pretty-printers, I found a few minor oddities in StdNonZeroNumberProvider.

First, gdb.Type.fields() already returns a sequence, so there's no need to call list().

Second, it's more idiomatic for the (somewhat misnamed) to_string method to simply return the underlying gdb.Value.  This also lets gdb apply whatever formats were passed to `print`, as the new test shows.

Third, there's no need to use the field's name when looking up a field in a value, the gdb.Field itself can be used.
This commit is contained in:
Stuart Cook 2025-11-06 14:07:18 +11:00 committed by GitHub
commit 2d77f23f0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -252,15 +252,15 @@ class StdNonZeroNumberProvider(printer_base):
def __init__(self, valobj):
fields = valobj.type.fields()
assert len(fields) == 1
field = list(fields)[0]
field = fields[0]
inner_valobj = valobj[field.name]
inner_valobj = valobj[field]
inner_fields = inner_valobj.type.fields()
assert len(inner_fields) == 1
inner_field = list(inner_fields)[0]
inner_field = inner_fields[0]
self._value = str(inner_valobj[inner_field.name])
self._value = inner_valobj[inner_field]
def to_string(self):
return self._value

View file

@ -202,6 +202,8 @@
// gdb-command:print nz_usize
// gdb-check:[...]$12 = 122
// gdb-command:print/x nz_i8
// gdb-check:[...]$13 = 0xb
// === LLDB TESTS ==================================================================================