Skip to content

Commit e3fc16f

Browse files
authored
[SYCL][GDB] Enable pretty-printing of reference objects (#9197)
This commit modifies the output of sycl pretty-printers such that a reference can be distinguished from a non-reference object. Printing of references is now in line with GDB's common way to print C++ references. A sycl::id reference is now printed as: '(sycl::_V1::id<3> &) @0x7fffffffd350: sycl::_V1::id<3> = {11, 22, 33}' Before it was exactly the same output as for a non-reference object: 'sycl::_V1::id<3> = {11, 22, 33}' Similar changes apply for sycl::range. Printing sycl::buffer objects resulted in an exception 'Python Exception <class 'TypeError'>: expected string or bytes-like object' before this patch due to the 'None' type returned by GDB in case the type is a reference. This is is also fixed by this commit. Now the output looks like: '(sycl::_V1::buffer<int, 3> &) @0x7fffffffd1d0: sycl::_V1::buffer<int, 3> = {impl=0x7fffffffd1d0}' Non-reference objects are still printed as: 'sycl::_V1::buffer<int, 3> = {impl=0x7fffffffd070}' Signed-off-by: Christina Schimpe <[email protected]> Signed-off-by: Christina Schimpe <[email protected]>
1 parent 09caf67 commit e3fc16f

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

sycl/gdb/libsycl.so-gdb.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,13 @@ def __next__(self):
311311
return ("[%d]" % count, elt)
312312

313313
def __init__(self, value):
314-
if value.type.code == gdb.TYPE_CODE_REF:
315-
if hasattr(gdb.Value, "referenced_value"):
316-
value = value.referenced_value()
317314

318315
self.value = value
319-
self.type = value.type.unqualified().strip_typedefs()
316+
if self.value.type.code == gdb.TYPE_CODE_REF:
317+
self.type = value.referenced_value().type.unqualified().strip_typedefs()
318+
else:
319+
self.type = value.type.unqualified().strip_typedefs()
320+
320321
self.dimensions = self.type.template_argument(0)
321322

322323
def children(self):
@@ -334,6 +335,10 @@ def to_string(self):
334335
# error message otherwise. Individual array element access failures
335336
# will be caught by iterator itself.
336337
_ = self.value["common_array"]
338+
if self.value.type.code == gdb.TYPE_CODE_REF:
339+
return "({tag} &) @{address}: {tag}".format(
340+
tag=self.type.tag, address=self.value.address
341+
)
337342
return self.type.tag
338343
except:
339344
return "<error reading variable>"
@@ -347,7 +352,11 @@ class SyclBufferPrinter:
347352

348353
def __init__(self, value):
349354
self.value = value
350-
self.type = value.type.unqualified().strip_typedefs()
355+
if self.value.type.code == gdb.TYPE_CODE_REF:
356+
self.type = value.referenced_value().type.unqualified().strip_typedefs()
357+
else:
358+
self.type = value.type.unqualified().strip_typedefs()
359+
351360
self.elt_type = value.type.template_argument(0)
352361
self.dimensions = value.type.template_argument(1)
353362
self.typeregex = re.compile("^([a-zA-Z0-9_:]+)(<.*>)?$")
@@ -356,12 +365,15 @@ def to_string(self):
356365
match = self.typeregex.match(self.type.tag)
357366
if not match:
358367
return "<error parsing type>"
359-
return "%s<%s, %s> = {impl=%s}" % (
360-
match.group(1),
361-
self.elt_type,
362-
self.dimensions,
363-
self.value["impl"].address,
368+
r_value = "{{impl={address}}}".format(address=self.value["impl"].address)
369+
r_type = "{group}<{elt_type}, {dim}>".format(
370+
group=match.group(1), elt_type=self.elt_type, dim=self.dimensions
364371
)
372+
if self.value.type.code == gdb.TYPE_CODE_REF:
373+
return "({type} &) @{address}: {type} = {value}".format(
374+
type=r_type, address=self.value.address, value=r_value
375+
)
376+
return "{type} = {value}".format(type=r_type, value=r_value)
365377

366378

367379
sycl_printer = gdb.printing.RegexpCollectionPrettyPrinter("SYCL")

0 commit comments

Comments
 (0)