On 18 Oct 2022, at 15:27, Eelco Chaudron wrote:

> Add a new GDB macro called ovs_dump_cmap, which can be used to dump any
> cmap structure. Some examples:
>
> (gdb) ovs_dump_cmap &subtable->rules
> (struct cmap *) 0x3e02758
>
> (gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node
> (struct dpcls_rule *) 0x3e02758
>
> (gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node dump
> (struct dpcls_rule *) 0x3e02758 =
> {cmap_node = {next = {p = 0x0}}, mask = 0x3dfe100, flow = {hash = ...

Forgot to add my sign-off tag, I’m doing this in the reply. Let me know if it 
needs a new revision instead…

Signed-off-by: Eelco Chaudron <[email protected]>


> ---
>  utilities/gdb/ovs_gdb.py |   66 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 66 insertions(+)
>
> diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
> index 763ece2a7..7f63dd0d5 100644
> --- a/utilities/gdb/ovs_gdb.py
> +++ b/utilities/gdb/ovs_gdb.py
> @@ -849,6 +849,71 @@ class CmdDumpOvsList(gdb.Command):
>                          member).dereference()))
>
>
> +#
> +# Implements the GDB "ovs_dump_cmap" command
> +#
> +class CmdDumpCmap(gdb.Command):
> +    """Dump all nodes of a given cmap
> +    Usage:
> +      ovs_dump_cmap <struct cmap *> {[<structure>] [<member>] {dump}]}
> +
> +    For example dump all the rules in a dpcls_subtable:
> +
> +    (gdb) ovs_dump_cmap &subtable->rules
> +    (struct cmap *) 0x3e02758
> +
> +    This is not very useful, so please use this with the container_of mode:
> +
> +    (gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node
> +    (struct dpcls_rule *) 0x3e02758
> +
> +    Now you can manually use the print command to show the content, or use 
> the
> +    dump option to dump the structure for all nodes:
> +
> +    (gdb) ovs_dump_cmap &subtable->rules "struct dpcls_rule" cmap_node dump
> +    (struct dpcls_rule *) 0x3e02758 =
> +    {cmap_node = {next = {p = 0x0}}, mask = 0x3dfe100, flow = {hash = ...
> +    """
> +    def __init__(self):
> +        super(CmdDumpCmap, self).__init__("ovs_dump_cmap",
> +                                             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) != 1 and len(arg_list) != 3 and len(arg_list) != 4:
> +            print("usage: ovs_dump_cmap <struct cmap *> "
> +                  "{[<structure>] [<member>] {dump}]}")
> +            return
> +
> +        cmap = gdb.parse_and_eval(arg_list[0]).cast(
> +            gdb.lookup_type('struct cmap').pointer())
> +
> +        if len(arg_list) >= 3:
> +            typeobj = arg_list[1]
> +            member = arg_list[2]
> +            if len(arg_list) == 4 and arg_list[3] == "dump":
> +                dump = True
> +
> +        for node in ForEachCMAP(cmap.dereference()):
> +            if typeobj is None or member is None:
> +                print("(struct cmap *) {}".format(node))
> +            else:
> +                print("({} *) {} {}".format(
> +                    typeobj,
> +                    container_of(node,
> +                                 gdb.lookup_type(typeobj).pointer(), member),
> +                    "=" if dump else ""))
> +                if dump:
> +                    print("  {}\n".format(container_of(
> +                        node,
> +                        gdb.lookup_type(typeobj).pointer(),
> +                        member).dereference()))
> +
> +
>  #
>  # Implements the GDB "ovs_dump_simap" command
>  #
> @@ -1449,6 +1514,7 @@ CmdDumpNetdevProvider()
>  CmdDumpOfpacts()
>  CmdDumpOvsList()
>  CmdDumpPackets()
> +CmdDumpCmap()
>  CmdDumpSimap()
>  CmdDumpSmap()
>  CmdDumpUdpifKeys()
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to