diff mbox series

[ovs-dev] utilities: Add a GDB macro to dump hmap structures.

Message ID 167043039955.3835972.825469155349022127.stgit@ebuild
State Accepted
Commit 79e7756a5d9e10c18343096187744f95a793ccf8
Headers show
Series [ovs-dev] utilities: Add a GDB macro to dump hmap structures. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Eelco Chaudron Dec. 7, 2022, 4:26 p.m. UTC
Add a new GDB macro called ovs_dump_hmap, which can be used to dump any
cmap structure. For example

  (gdb) ovs_dump_hmap "&'all_bridges.lto_priv.0'" "struct bridge" "node"
  (struct bridge *) 0x55ec43069c70
  (struct bridge *) 0x55ec430428a0
  (struct bridge *) 0x55ec430a55f0

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
 utilities/gdb/ovs_gdb.py |   53 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

Comments

Ilya Maximets Dec. 20, 2022, 3:26 p.m. UTC | #1
On 12/7/22 17:26, Eelco Chaudron wrote:
> Add a new GDB macro called ovs_dump_hmap, which can be used to dump any
> cmap structure. For example
> 
>   (gdb) ovs_dump_hmap "&'all_bridges.lto_priv.0'" "struct bridge" "node"
>   (struct bridge *) 0x55ec43069c70
>   (struct bridge *) 0x55ec430428a0
>   (struct bridge *) 0x55ec430a55f0
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
>  utilities/gdb/ovs_gdb.py |   53 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 52 insertions(+), 1 deletion(-)
> 


Applied.  Thanks!

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index 7f63dd0d5..982395dd1 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -30,6 +30,8 @@ 
 #    - ovs_dump_netdev_provider
 #    - ovs_dump_ovs_list <struct ovs_list *> {[<structure>] [<member>] {dump}]}
 #    - ovs_dump_packets <struct dp_packet_batch|dp_packet> [tcpdump options]
+#    - ovs_dump_cmap <struct cmap *> {[<structure>] [<member>] {dump}]}
+#    - ovs_dump_hmap <struct hmap *> <structure> <member> {dump}
 #    - ovs_dump_simap <struct simap *>
 #    - ovs_dump_smap <struct smap *>
 #    - ovs_dump_udpif_keys {<udpif_name>|<udpif_address>} {short}
@@ -876,7 +878,7 @@  class CmdDumpCmap(gdb.Command):
     """
     def __init__(self):
         super(CmdDumpCmap, self).__init__("ovs_dump_cmap",
-                                             gdb.COMMAND_DATA)
+                                          gdb.COMMAND_DATA)
 
     def invoke(self, arg, from_tty):
         arg_list = gdb.string_to_argv(arg)
@@ -914,6 +916,54 @@  class CmdDumpCmap(gdb.Command):
                         member).dereference()))
 
 
+#
+# Implements the GDB "ovs_dump_hmap" command
+#
+class CmdDumpHmap(gdb.Command):
+    """Dump all nodes of a given hmap
+    Usage:
+      ovs_dump_hmap <struct hmap *> <structure> <member> {dump}
+
+    For example dump all the bridges when the all_bridges variable is
+    optimized out due to LTO:
+
+    (gdb) ovs_dump_hmap "&'all_bridges.lto_priv.0'" "struct bridge" "node"
+    (struct bridge *) 0x55ec43069c70
+    (struct bridge *) 0x55ec430428a0
+    (struct bridge *) 0x55ec430a55f0
+
+    The 'dump' option will also include the full structure content in the
+    output.
+    """
+    def __init__(self):
+        super(CmdDumpHmap, self).__init__("ovs_dump_hmap",
+                                          gdb.COMMAND_DATA)
+
+    def invoke(self, arg, from_tty):
+        arg_list = gdb.string_to_argv(arg)
+        typeobj = None
+        member = None
+        dump = False
+
+        if len(arg_list) != 3 and len(arg_list) != 4:
+            print("usage: ovs_dump_hmap <struct hmap *> "
+                  "<structure> <member> {dump}")
+            return
+
+        hmap = gdb.parse_and_eval(arg_list[0]).cast(
+            gdb.lookup_type('struct hmap').pointer())
+
+        typeobj = arg_list[1]
+        member = arg_list[2]
+        if len(arg_list) == 4 and arg_list[3] == "dump":
+            dump = True
+
+        for node in ForEachHMAP(hmap.dereference(), typeobj, member):
+            print("({} *) {} {}".format(typeobj, node, "=" if dump else ""))
+            if dump:
+                print("  {}\n".format(node.dereference()))
+
+
 #
 # Implements the GDB "ovs_dump_simap" command
 #
@@ -1515,6 +1565,7 @@  CmdDumpOfpacts()
 CmdDumpOvsList()
 CmdDumpPackets()
 CmdDumpCmap()
+CmdDumpHmap()
 CmdDumpSimap()
 CmdDumpSmap()
 CmdDumpUdpifKeys()