-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(libalgo: avl): add GDB pretty printer for avl_t
This is a nice and easy to have feature to help us eventual issues with our AVL implementation. It should not be useful anymore once we've debugged our implementation, but I'll leave it anyway just in case.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source scripts/gdb/pretty_printer.py |
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,40 @@ | ||
class Avl: | ||
|
||
def __init__(self, val) -> None: | ||
self.address = val.address | ||
self.height = val["height"] | ||
self.parent = val["parent"] | ||
self.left = val["left"] | ||
self.right = val["right"] | ||
|
||
def to_string_rec(self, parent, depth) -> str: | ||
prefix = ' ' * depth | ||
string = f'''{self.address} {{ | ||
{prefix}height: {self.height} | ||
{prefix}parent: {self.parent}{"" if self.parent == parent else " (error)"} | ||
''' | ||
|
||
if self.left: | ||
string += f" {prefix}left@{Avl(self.left.dereference()).to_string_rec(self.address, depth + 1)}\n" | ||
if self.right: | ||
string += f" {prefix}right@{Avl(self.right.dereference()).to_string_rec(self.address, depth + 1)}\n" | ||
|
||
string += f'{prefix}}}' | ||
return string | ||
|
||
def to_string(self): | ||
return f"avl@{self.to_string_rec(0, 0)}" | ||
|
||
|
||
def pretty_printers(val): | ||
printers = { | ||
"avl_t": Avl | ||
} | ||
|
||
if str(val.type) in printers: | ||
return printers[str(val.type)](val) | ||
|
||
return None | ||
|
||
|
||
gdb.pretty_printers.append(pretty_printers) |