diff mbox series

[ovs-dev,40/62] ovs_gdb.py: add print ofp buffers in gdb script

Message ID 20201228092520.11807-41-taoyunxiang@cmss.chinamobile.com
State Not Applicable
Headers show
Series DPDK Offload API to test | expand

Commit Message

Tao YunXiang Dec. 28, 2020, 9:24 a.m. UTC
From: Rongyin <rongyin@cmss.chinamobile.com>

This adds the ovs_dump_ifpacts command:

    (gdb) help ovs_dump_ofpacts
    Dump all actions in an ofpacts set
        Usage: ovs_dump_ofpacts <struct ofpact *> <ofpacts_len>

           <struct ofpact *> : Pointer to set of ofpact structures.
           <ofpacts_len>     : Total length of the set.

        Example dumping all actions when in the clone_xlate_actions() function:

        (gdb) ovs_dump_ofpacts actions actions_len
        (struct ofpact *) 0x561c7be487c8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
        (struct ofpact *) 0x561c7be487e0: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
        (struct ofpact *) 0x561c7be487f8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
        (struct ofpact *) 0x561c7be48810: {type = OFPACT_SET_FIELD, raw = 255 '', len = 32}
        (struct ofpact *) 0x561c7be48830: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
        (struct ofpact *) 0x561c7be48848: {type = OFPACT_RESUBMIT, raw = 38 '&', len = 16}

Code Source From: Self Code

Description:

     Add print ofp buffers in gdb script. The details as above.

Jira:  #[Optional]
市场项目编号(名称):[Optional]
---
 utilities/gdb/ovs_gdb.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
diff mbox series

Patch

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index befc2b4..1111f31 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -55,6 +55,7 @@ 
 #    ...
 #    ...
 #
+from __future__ import print_function
 import gdb
 import sys
 import uuid
@@ -414,6 +415,39 @@  class ForEachLIST():
 
 
 #
+# Class that will provide an iterator over an OFPACTS.
+#
+class ForEachOFPACTS():
+    def __init__(self, ofpacts, ofpacts_len):
+        self.ofpact = ofpacts.cast(gdb.lookup_type('struct ofpact').pointer())
+        self.length = int(ofpacts_len)
+
+    def __round_up(self, val, round_to):
+        return int(val) + (round_to - int(val)) % round_to
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        if self.ofpact is None or self.length <= 0:
+            raise StopIteration
+
+        ofpact = self.ofpact
+        length = self.__round_up(ofpact['len'], 8)
+
+        self.length -= length
+        self.ofpact = self.ofpact.cast(
+            gdb.lookup_type('void').pointer()) + length
+        self.ofpact = self.ofpact.cast(
+            gdb.lookup_type('struct ofpact').pointer())
+
+        return ofpact
+
+    def next(self):
+        return self.__next__()
+
+
+#
 # Implements the GDB "ovs_dump_bridges" command
 #
 class CmdDumpBridge(gdb.Command):
@@ -1234,6 +1268,46 @@  class CmdShowUpcall(gdb.Command):
 
 
 #
+# Implements the GDB "ovs_dump_ofpacts" command
+#
+class CmdDumpOfpacts(gdb.Command):
+    """Dump all actions in an ofpacts set
+    Usage: ovs_dump_ofpacts <struct ofpact *> <ofpacts_len>
+
+       <struct ofpact *> : Pointer to set of ofpact structures.
+       <ofpacts_len>     : Total length of the set.
+
+    Example dumping all actions when in the clone_xlate_actions() function:
+
+    (gdb) ovs_dump_ofpacts actions actions_len
+    (struct ofpact *) 0x561c7be487c8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
+    (struct ofpact *) 0x561c7be487e0: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
+    (struct ofpact *) 0x561c7be487f8: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
+    (struct ofpact *) 0x561c7be48810: {type = OFPACT_SET_FIELD, raw = 255 '', len = 32}
+    (struct ofpact *) 0x561c7be48830: {type = OFPACT_SET_FIELD, raw = 255 '', len = 24}
+    (struct ofpact *) 0x561c7be48848: {type = OFPACT_RESUBMIT, raw = 38 '&', len = 16}
+    """
+    def __init__(self):
+        super(CmdDumpOfpacts, self).__init__("ovs_dump_ofpacts",
+                                             gdb.COMMAND_DATA)
+
+    def invoke(self, arg, from_tty):
+        arg_list = gdb.string_to_argv(arg)
+
+        if len(arg_list) != 2:
+            print("usage: ovs_dump_ofpacts <struct ofpact *> <ofpacts_len>")
+            return
+
+        ofpacts = gdb.parse_and_eval(arg_list[0]).cast(
+            gdb.lookup_type('struct ofpact').pointer())
+
+        length = gdb.parse_and_eval(arg_list[1])
+
+        for node in ForEachOFPACTS(ofpacts, length):
+            print("(struct ofpact *) {}: {}".format(node, node.dereference()))
+
+
+#
 # Initialize all GDB commands
 #
 CmdDumpBridge()
@@ -1244,6 +1318,7 @@  CmdDumpDpNetdevPorts()
 CmdDumpDpProvider()
 CmdDumpNetdev()
 CmdDumpNetdevProvider()
+CmdDumpOfpacts()
 CmdDumpOvsList()
 CmdDumpSimap()
 CmdDumpSmap()