Skip to content

Commit 98a4181

Browse files
committed
Fix handling of negative offset to top for tagged types
TN: QA23-021
1 parent a204b1a commit 98a4181

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

gnatdbg/tagged.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import gdb
66

77
from gnatdbg.utils import (
8-
addr_to_val, encode_name, get_system_address, ptr_to_int, strip_typedefs
8+
address_as_offset, addr_to_val, encode_name, get_system_address,
9+
ptr_to_int, strip_typedefs
910
)
1011

1112
# The reader of this module is assumed to be familiar with how GNAT implements
@@ -130,9 +131,12 @@ def decode_tag(tag_addr):
130131
except IndexError:
131132
sig = '<invalid signature: {}>'.format(sig_int)
132133

134+
offset_to_top = address_as_offset(addr_to_val(offset_to_top_addr,
135+
system_address))
136+
133137
return (
134138
sig,
135-
int(addr_to_val(offset_to_top_addr, system_address)),
139+
offset_to_top,
136140
addr_to_val(tsd_addr, system_address),
137141
)
138142

gnatdbg/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ def get_system_address():
3737
return gdb.lookup_type('system__address')
3838

3939

40+
def address_as_offset(addr):
41+
"""
42+
In order to avoid requiring too much debug information, we use the
43+
System.Address type (which is unsigned) to decode what is actually a
44+
System.Storage_Elements.Storage_Offset (which is signed). This does the
45+
conversion.
46+
47+
:param gdb.Value addr: Address to decode.
48+
:rtype: int
49+
"""
50+
addr_range_size = 2 ** (8 * addr.type.sizeof)
51+
max_int = addr_range_size / 2 - 1
52+
int_addr = int(addr)
53+
if int_addr > max_int:
54+
return int_addr - addr_range_size
55+
else:
56+
return int_addr
57+
58+
4059
def ptr_to_int(ptr_value):
4160
"""
4261
Convert an access GDB value into the corresponding Python integer.

0 commit comments

Comments
 (0)