-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gdb
pretty-printers for simple types
#11499
Merged
rapids-bot
merged 9 commits into
rapidsai:branch-22.10
from
upsj:feature/pretty_printers
Sep 9, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6c897b8
add gdb pretty-printer
upsj 7350f3d
formatting and cleanup
upsj 7998689
add copyright header
upsj 583f968
add pretty-printer load script
upsj 6e0aa55
rename script
upsj 18abcca
formatting
upsj b5f1107
remove unnecessary check
upsj 950eca5
review updates
upsj 3debc6e
formatting and output fixes
upsj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import gdb | ||
|
||
global_locals = locals() | ||
if not all( | ||
name in global_locals | ||
for name in ( | ||
"HostIterator", | ||
"DeviceIterator", | ||
"is_template_type_not_alias", | ||
"template_match", | ||
) | ||
): | ||
raise NameError( | ||
"This file expects the RMM pretty-printers to be loaded already. " | ||
"Either load them manually, or use the generated load-pretty-printers " | ||
"script in the build directory" | ||
) | ||
|
||
|
||
class CudfHostSpanPrinter(gdb.printing.PrettyPrinter): | ||
"""Print a cudf::host_span""" | ||
|
||
def __init__(self, val): | ||
self.val = val | ||
self.pointer = val["_data"] | ||
self.size = int(val["_size"]) | ||
|
||
def children(self): | ||
return HostIterator(self.pointer, self.size) | ||
|
||
def to_string(self): | ||
return f"{self.val.type} of length {self.size} at {hex(self.pointer)}" | ||
|
||
def display_hint(self): | ||
return "array" | ||
|
||
|
||
class CudfDeviceSpanPrinter(gdb.printing.PrettyPrinter): | ||
"""Print a cudf::device_span""" | ||
|
||
def __init__(self, val): | ||
self.val = val | ||
self.pointer = val["_data"] | ||
self.size = int(val["_size"]) | ||
|
||
def children(self): | ||
return DeviceIterator(self.pointer, self.size) | ||
|
||
def to_string(self): | ||
return f"{self.val.type} of length {self.size} at {hex(self.pointer)}" | ||
|
||
def display_hint(self): | ||
return "array" | ||
|
||
|
||
def lookup_cudf_type(val): | ||
if not str(val.type.unqualified()).startswith("cudf::"): | ||
return None | ||
suffix = str(val.type.unqualified())[6:] | ||
if not is_template_type_not_alias(suffix): | ||
return None | ||
if template_match(suffix, "host_span"): | ||
return CudfHostSpanPrinter(val) | ||
if template_match(suffix, "device_span"): | ||
return CudfDeviceSpanPrinter(val) | ||
return None | ||
|
||
|
||
gdb.pretty_printers.append(lookup_cudf_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source @Thrust_SOURCE_DIR@/scripts/gdb-pretty-printers.py | ||
source @rmm_SOURCE_DIR@/scripts/gdb-pretty-printers.py | ||
source @PROJECT_SOURCE_DIR@/scripts/gdb-pretty-printers.py |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this printer work if we use
using namespace cudf
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,
using
is a source-level alias that doesn't affect the generated debug info, afaik.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that's the case after some small experiments :)