Skip to content

Commit a0e87da

Browse files
committed
Strip name suffix for body-nested package entities
GNAT appends Xn/Xb suffixes for entities which are nested in body packages and GDB does not strip them when getting type pretty names. This commit introduces a helper to strip them and then uses it where relevant in pretty-printers. For GitHub issue #3 Change-Id: Ic3c93e0eb34d17af101015c054e8b2004a967d58 no-tn-check
1 parent 8aaaa12 commit a0e87da

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

gnatdbg/generics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import gdb
99

10-
from gnatdbg.utils import gdb_code_names
10+
from gnatdbg.utils import gdb_code_names, pretty_typename
1111

1212

1313
regex_type = type(re.compile('.*'))
@@ -191,7 +191,8 @@ def _match(self, typ, mt):
191191
types.append(typ)
192192

193193
for typ in types:
194-
type_name = str(typ) if self.match_pretty_name else typ.name
194+
type_name = (pretty_typename(typ)
195+
if self.match_pretty_name else typ.name)
195196

196197
with mt.scope(self, typ):
197198

gnatdbg/lists.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from gnatdbg.generics import Match
1010
from gnatdbg.printers import PrettyPrinter
11+
from gnatdbg.utils import pretty_typename
1112

1213

1314
class DoublyLinkedListPrinter(PrettyPrinter):
@@ -49,7 +50,7 @@ def children(self):
4950

5051
def to_string(self):
5152
return '{} of length {}'.format(
52-
str(self.value.type),
53+
pretty_typename(self.value.type),
5354
self.length,
5455
)
5556

gnatdbg/maps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from gnatdbg.hash_tables import iterate, get_htable_pattern
99
from gnatdbg.printers import PrettyPrinter
1010
from gnatdbg.red_black_trees import dfs, get_rbtree_pattern
11+
from gnatdbg.utils import pretty_typename
1112

1213

1314
class BaseMapPrinter(PrettyPrinter):
@@ -30,7 +31,7 @@ def children(self):
3031

3132
def to_string(self):
3233
return '{} of length {}'.format(
33-
str(self.value.type),
34+
pretty_typename(self.value.type),
3435
self.length
3536
)
3637

gnatdbg/sets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from gnatdbg.hash_tables import iterate, get_htable_pattern
77
from gnatdbg.printers import PrettyPrinter
88
from gnatdbg.red_black_trees import dfs, get_rbtree_pattern
9+
from gnatdbg.utils import pretty_typename
910

1011

1112
class BaseSetPrinter(PrettyPrinter):
@@ -19,7 +20,7 @@ def children(self):
1920

2021
def to_string(self):
2122
return '{} of length {}'.format(
22-
str(self.value.type),
23+
pretty_typename(self.value.type),
2324
self.length
2425
)
2526

gnatdbg/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Gathering of various helpers that don't deserve their own submodule.
33
"""
44

5+
import re
6+
57
import gdb
68
import gdb.printing
79

@@ -13,6 +15,8 @@
1315
}
1416
objfile_filter_true = lambda objfile: True # no-code-coverage
1517

18+
bnpe_suffix_re = re.compile('X[bn]*$')
19+
1620

1721
def register_pretty_printers(printers, objfile_filter=objfile_filter_true):
1822
"""
@@ -156,6 +160,27 @@ def encode_name(name):
156160
return name.lower().replace('.', '__')
157161

158162

163+
def pretty_typename(typ):
164+
"""
165+
Return a pretty (Ada-like) name for the given type.
166+
167+
:param gdb.Type typ: Type whose name is requested.
168+
:rtype: str
169+
"""
170+
return strip_bnpe_suffix(str(typ))
171+
172+
173+
def strip_bnpe_suffix(name):
174+
"""
175+
Strip suffix for body-nested package entities from "name".
176+
177+
:param str name: Name to strip.
178+
:rtype: str
179+
"""
180+
m = bnpe_suffix_re.search(name)
181+
return name[:m.start()] if m else name
182+
183+
159184
def addr_to_val(addr, valtype):
160185
"""
161186
Create a value based on the given address and type.

gnatdbg/vectors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from gnatdbg.generics import Match
88
from gnatdbg.printers import PrettyPrinter
9+
from gnatdbg.utils import pretty_typename
910

1011

1112
class VectorPrinter(PrettyPrinter):
@@ -78,7 +79,8 @@ def children(self):
7879
yield ('[{}]'.format(i), elt)
7980

8081
def to_string(self):
81-
return '{} of length {}'.format(str(self.value.type), self.length)
82+
return '{} of length {}'.format(pretty_typename(self.value.type),
83+
self.length)
8284

8385

8486
class VectorCursorPrinter(PrettyPrinter):

0 commit comments

Comments
 (0)