Hi,
Attached is a patch to add a gdb command script with some helpful
commands for debugging opencryptoki. I've prefixed all the useful
commands with "ock_" so they're easy to call up, and the internal
functions are prefixed with "__ock_" so they don't get in the way. Here
are the useful ones:
ock_dump_obj_template <OBJECT *>
- dump an object's template
ock_dump_object_map
ock_dump_sess_btree
ock_dump_sess_obj_btree
ock_dump_priv_tok_obj_btree
ock_dump_publ_tok_obj_btree
- dump one of the btrees
We can keep adding new functions to this as we need to, but this
should be a good start. This patch adds the script to the misc/
directory.
Signed-off-by: Kent Yoder <[email protected]>
diff --git a/misc/opencryptoki.gdb b/misc/opencryptoki.gdb
new file mode 100644
index 0000000..966b529
--- /dev/null
+++ b/misc/opencryptoki.gdb
@@ -0,0 +1,101 @@
+#
+# openCryptoki debugging helper script
+#
+# Kent Yoder <[email protected]>
+# April 29, 2011
+#
+# Functions:
+#
+# ock_dump_obj_template <OBJECT *>
+# ock_dump_object_map
+# ock_dump_sess_btree
+# ock_dump_sess_obj_btree
+# ock_dump_priv_tok_obj_btree
+# ock_dump_publ_tok_obj_btree
+#
+
+set $OBJECT_MAP = 1
+set $OBJECT = 2
+set $SESSION = 3
+
+#
+# ock_dump_obj_template <OBJECT *>
+#
+# Dump an OBJECT's template of attributes
+#
+define ock_dump_obj_template
+ set $obj = ($arg0)
+ set $node = $obj->template->attribute_list
+
+ while ($node)
+ print *(CK_ATTRIBUTE *)($node->data)
+ set $node = $node->next
+ end
+end
+
+define __ock_print_node_type
+ if $arg1 == $OBJECT_MAP
+ print *((OBJECT_MAP *)($arg0)->value)
+ end
+ if $arg1 == $OBJECT
+ print *((OBJECT *)($arg0)->value)
+ end
+ if $arg1 == $SESSION
+ print *((SESSION *)($arg0)->value)
+ end
+end
+
+define __ock_print_node
+ set $n = ($arg0)
+ set $loc = ($arg1)
+
+ while ($loc > 1)
+ if ($loc & 1)
+ set $n = $n->right
+ else
+ set $n = $n->left
+ end
+
+ set $loc = $loc >> 1
+ printf " "
+ end
+
+ if ($n->flags & 1)
+ printf "`- %d: (deleted node)\n", $arg1
+ else
+ printf "`- %d: ", $arg1
+ __ock_print_node_type $n $arg2
+ end
+end
+
+define __ock_dump_tree
+ set $size = ($arg0).size + 1
+ set $i = 1
+
+ printf "tree: size %d, free nodes: %d\n", $arg0.size, ($arg0).free_nodes
+ while ($i < $size)
+ __ock_print_node ($arg0).top $i ($arg1)
+ set $i = $i + 1
+ end
+end
+
+define ock_dump_object_map
+ __ock_dump_tree object_map_btree $OBJECT_MAP
+end
+
+define ock_dump_sess_btree
+ __ock_dump_tree sess_btree $SESSION
+end
+
+define ock_dump_sess_obj_btree
+ __ock_dump_tree sess_obj_btree $OBJECT
+end
+
+define ock_dump_priv_tok_obj_btree
+ __ock_dump_tree priv_token_obj_btree $OBJECT
+end
+
+define ock_dump_publ_tok_obj_btree
+ __ock_dump_tree publ_token_obj_btree $OBJECT
+end
+
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Opencryptoki-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech