diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index ef41c2fc7c2ca..a38fabc480cff 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -248,7 +248,7 @@ add_subdirectory( source ) # Auxilliary extras for SYCL headers/library if (NOT WIN32) install(FILES - "${CMAKE_CURRENT_SOURCE_DIR}/xmethods/libsycl.so-gdb.py" + "${CMAKE_CURRENT_SOURCE_DIR}/gdb/libsycl.so-gdb.py" RENAME "libsycl.so.${SYCL_VERSION_STRING}-gdb.py" DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/" COMPONENT sycl-headers-extras) diff --git a/sycl/xmethods/libsycl.so-gdb.py b/sycl/gdb/libsycl.so-gdb.py similarity index 56% rename from sycl/xmethods/libsycl.so-gdb.py rename to sycl/gdb/libsycl.so-gdb.py index 393c33a858acb..4e1c4bacb7fb5 100644 --- a/sycl/xmethods/libsycl.so-gdb.py +++ b/sycl/gdb/libsycl.so-gdb.py @@ -2,9 +2,14 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +import gdb import gdb.xmethod +import gdb.printing +import itertools import re +### XMethod implementations ### + """ Generalized base class for buffer index calculation """ @@ -134,3 +139,86 @@ def match(self, class_type, method_name): gdb.xmethod.register_xmethod_matcher(None, AccessorOpIndexMatcher(), replace=True) + +### Pretty-printer implementations ### + +""" +Print an object deriving from cl::sycl::detail::array +""" +class SyclArrayPrinter: + class ElementIterator: + def __init__(self, data, size): + self.data = data + self.size = size + self.count = 0 + + def __iter__(self): + return self + + def __next__(self): + if self.count == self.size: + raise StopIteration + count = self.count + self.count = self.count + 1 + try: + elt = self.data[count] + except: + elt = "" + return ('[%d]' % count, elt) + + def __init__(self, value): + if value.type.code == gdb.TYPE_CODE_REF: + if hasattr(gdb.Value,"referenced_value"): + value = value.referenced_value() + + self.value = value + self.type = value.type.unqualified().strip_typedefs() + self.dimensions = self.type.template_argument(0) + + def children(self): + try: + return self.ElementIterator(self.value['common_array'], self.dimensions) + except: + # There is no way to return an error from this method. Return an + # empty iterable to make GDB happy and rely on to_string method + # to take care of formatting. + return [ ] + + def to_string(self): + try: + # Check if accessing array value will succeed and resort to + # error message otherwise. Individual array element access failures + # will be caught by iterator itself. + _ = self.value['common_array'] + return self.type.tag + except: + return "" + + def display_hint(self): + return 'array' + +""" +Print a cl::sycl::buffer +""" +class SyclBufferPrinter: + def __init__(self, value): + self.value = value + self.type = value.type.unqualified().strip_typedefs() + self.elt_type = value.type.template_argument(0) + self.dimensions = value.type.template_argument(1) + self.typeregex = re.compile('^([a-zA-Z0-9_:]+)(<.*>)?$') + + def to_string(self): + match = self.typeregex.match(self.type.tag) + if not match: + return "" + return ('%s<%s, %s> = {impl=%s}' + % (match.group(1), self.elt_type, self.dimensions, + self.value['impl'].address)) + +sycl_printer = gdb.printing.RegexpCollectionPrettyPrinter("SYCL") +sycl_printer.add_printer("cl::sycl::id", '^cl::sycl::id<.*$', SyclArrayPrinter) +sycl_printer.add_printer("cl::sycl::range", '^cl::sycl::range<.*$', SyclArrayPrinter) +sycl_printer.add_printer("cl::sycl::buffer", '^cl::sycl::buffer<.*$', SyclBufferPrinter) +gdb.printing.register_pretty_printer(None, sycl_printer, True) + diff --git a/sycl/test/xmethods/accessors-device.cpp b/sycl/test/gdb/accessors-device.cpp similarity index 100% rename from sycl/test/xmethods/accessors-device.cpp rename to sycl/test/gdb/accessors-device.cpp diff --git a/sycl/test/xmethods/accessors.cpp b/sycl/test/gdb/accessors.cpp similarity index 100% rename from sycl/test/xmethods/accessors.cpp rename to sycl/test/gdb/accessors.cpp diff --git a/sycl/test/gdb/printers.cpp b/sycl/test/gdb/printers.cpp new file mode 100644 index 0000000000000..1d7898d5686f9 --- /dev/null +++ b/sycl/test/gdb/printers.cpp @@ -0,0 +1,19 @@ +// RUN: %clangxx -c -fno-color-diagnostics -I %sycl_include -Xclang -ast-dump %s | FileCheck %s +// UNSUPPORTED: windows +#include +#include + +typedef cl::sycl::id<1> dummy_id; +typedef cl::sycl::buffer dummy_buffer; + +// array must have common_array field + +// CHECK: CXXRecordDecl {{.*}} class array definition +// CHECK-NOT: CXXRecordDecl {{.*}} definition +// CHECK: FieldDecl {{.*}} referenced common_array + +// buffer must have impl field + +// CHECK: CXXRecordDecl {{.*}} class buffer definition +// CHECK-NOT: CXXRecordDecl {{.*}} definition +// CHECK: FieldDecl {{.*}} referenced impl