From 79e7756a5d9e10c18343096187744f95a793ccf8 Mon Sep 17 00:00:00 2001 From: Eelco Chaudron Date: Wed, 7 Dec 2022 17:26:39 +0100 Subject: utilities: Add a GDB macro to dump hmap structures. 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 Signed-off-by: Ilya Maximets --- utilities/gdb/ovs_gdb.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) 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 {[] [] {dump}]} # - ovs_dump_packets [tcpdump options] +# - ovs_dump_cmap {[] [] {dump}]} +# - ovs_dump_hmap {dump} # - ovs_dump_simap # - ovs_dump_smap # - ovs_dump_udpif_keys {|} {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 {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 " + " {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() -- cgit v1.2.1