Add some temp AVL debugging code: In case an AVL table gets unbalanced, dump the table and a backtrace.

svn path=/trunk/; revision=56249
This commit is contained in:
Timo Kreuzer 2012-03-27 17:19:53 +00:00
parent 6fcb5fd53c
commit 98a00b314d

View file

@ -203,6 +203,46 @@ RtlpRebalanceAvlTreeNode(IN PRTL_BALANCED_LINKS Node)
return TRUE;
}
void
FORCEINLINE
Indent(ULONG Level)
{
while (Level--)
{
DbgPrint(" ");
}
}
VOID
FORCEINLINE
DbgDumpAvlNodes(
PRTL_BALANCED_LINKS Node,
ULONG Level)
{
#ifdef PRTL_BALANCED_LINKS
if (Level == 0)
{
DbgPrint("++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
DbgPrint("Root = %p\n", Node);
}
Indent(Level+1); DbgPrint("LetChid = %p", Node->LeftChild);
if (Node->LeftChild)
{
DbgPrint("(%lx, %lx)\n", Node->LeftChild->StartingVpn,Node->LeftChild->EndingVpn);
DbgDumpAvlNodes(Node->LeftChild, Level+1);
}
else DbgPrint("\n");
Indent(Level+1); DbgPrint("RightChild = %p\n", Node->RightChild);
if (Node->RightChild)
{
DbgPrint("(%lx, %lx)\n", Node->RightChild->StartingVpn,Node->RightChild->EndingVpn);
DbgDumpAvlNodes(Node->RightChild, Level+1);
}
#endif
}
VOID
FORCEINLINE
RtlpInsertAvlTreeNode(IN PRTL_AVL_TABLE Table,
@ -225,7 +265,14 @@ RtlpInsertAvlTreeNode(IN PRTL_AVL_TABLE Table,
/* This is the new root node */
RtlInsertAsRightChildAvl(&Table->BalancedRoot, NewNode);
//MI_ASSERT(RtlBalance(NewNode) == RtlBalancedAvlTree);
if (RtlBalance(NewNode) != RtlBalancedAvlTree) DPRINT1("Warning: Root node unbalanced?\n");
if (RtlBalance(NewNode) != RtlBalancedAvlTree)
{
DPRINT1("Warning: Root node unbalanced?\n");
DbgDumpAvlNodes(&Table->BalancedRoot, 0);
#ifdef PRTL_BALANCED_LINKS
KeRosDumpStackFrames(NULL, 0);
#endif
}
/* On AVL trees, we also update the depth */
ASSERT(Table->DepthOfTree == 0);
@ -245,7 +292,14 @@ RtlpInsertAvlTreeNode(IN PRTL_AVL_TABLE Table,
/* Little cheat to save on loop processing, taken from Timo */
//MI_ASSERT(RtlBalance(NewNode) == RtlBalancedAvlTree);
if (RtlBalance(NewNode) != RtlBalancedAvlTree) DPRINT1("Warning: Root node unbalanced?\n");
if (RtlBalance(NewNode) != RtlBalancedAvlTree)
{
DPRINT1("Warning: Root node unbalanced?\n");
DbgDumpAvlNodes(&Table->BalancedRoot, 0);
#ifdef PRTL_BALANCED_LINKS
KeRosDumpStackFrames(NULL, 0);
#endif
}
RtlSetBalance(&Table->BalancedRoot, RtlLeftHeavyAvlTree);
/*