Skip to content

Commit 0cd6335

Browse files
committed
gnatdbg.records.decoded_record: handle tagged types
Change-Id: Ief21b027fe75cabe226058122448fbcca57cda09 TN: RC14-025
1 parent f5f1cfc commit 0cd6335

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

gnatdbg/records.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ def process_record(r):
193193
# parts (case <discr> is ... end case, in Ada records) or regular
194194
# fields.
195195
for f in r.type.fields():
196-
if f.name.endswith(union_suffix):
196+
if f.name == '_parent':
197+
process_record(r[f.name])
198+
199+
elif f.name.endswith(union_suffix):
197200
# This is an undecoded variant part, materialized as an union
198201
# field whose name has follows the <discr>___XVN pattern.
199202
# Compute the corresponding discriminant and decode the union.
@@ -207,8 +210,8 @@ def process_record(r):
207210
# Just recurse on that record.
208211
process_record(r[f.name])
209212

210-
else:
211-
# This is a regular field.
213+
elif not f.name.startswith('_'):
214+
# This is a regular field (omit compiler-generated ones)
212215
result[f.name] = r[f.name]
213216

214217
def process_union(discr_value, u):
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
procedure Foo is
2+
3+
type Base is tagged record
4+
I : Integer;
5+
end record;
6+
7+
type Derived is new Base with record
8+
C : Character;
9+
end record;
10+
11+
procedure Process (R : Base'Class) is
12+
begin
13+
null;
14+
end Process;
15+
16+
R : Derived := (I => 1, C => 'A');
17+
18+
begin
19+
Process (R); -- BREAK
20+
end Foo;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from gnatdbg.records import decoded_record
2+
3+
4+
def print_record(name, value):
5+
print('== {} =='.format(name))
6+
for k, v in decoded_record(value).items():
7+
print(' {}: {}'.format(k, v))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from support.build import gnatmake
2+
from support.gdb import GDBSession
3+
4+
5+
gnatmake('foo')
6+
gdb = GDBSession('foo')
7+
gdb.run_to(gdb.find_loc('foo.adb', 'BREAK'))
8+
gdb.test('source helpers.py', '')
9+
gdb.test('pi print_record("R", gdb.parse_and_eval("R"))',
10+
'== R ==\n'
11+
' i: 1\n'
12+
' c: 65 \'A\'')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
driver: python

0 commit comments

Comments
 (0)