diff mbox series

[ovs-dev] Utilities: Add the ovs_dump_ofpacts command to gdb

Message ID 8ad87b32ffb65b01b8511be1e2c7e409edbe7849.1587127617.git.echaudro@redhat.com
State Accepted
Commit eb8fd61d91866032118fa3f63e022d007d812626
Headers show
Series [ovs-dev] Utilities: Add the ovs_dump_ofpacts command to gdb | expand

Commit Message

Eelco Chaudron April 17, 2020, 12:51 p.m. UTC
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}

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

Comments

William Tu April 19, 2020, 3:58 p.m. UTC | #1
On Fri, Apr 17, 2020 at 02:51:34PM +0200, Eelco Chaudron wrote:
> 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}
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
Hi Eelco,

I'm trying to test this patch. But I hit another problem.
Can you help me with the issue? Sorry this is not related to your patch.

root@osboxes:~/ovs# gdb $(which ovs-vswitchd) $(pidof ovs-vswitchd)
GNU gdb (GDB) 8.0.50.20170501-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/sbin/ovs-vswitchd...done.
Attaching to program: /usr/local/sbin/ovs-vswitchd, process 58469
[New LWP 58473]
[New LWP 58474]
[New LWP 58475]
[New LWP 58484]
[New LWP 58485]
[New LWP 58486]
[New LWP 58487]
[New LWP 58578]
[New LWP 58579]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007fe63d33774d in poll () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) source ./utilities/gdb/ovs_gdb.py
  File "./utilities/gdb/ovs_gdb.py", line 164
    print(self.message, end='')


Is this due to python2/3? My python version:
boxes:~/ovs# python
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

Thanks!
William

>  utilities/gdb/ovs_gdb.py | 74 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
> index befc2b4a4..0b2ecb81b 100644
> --- a/utilities/gdb/ovs_gdb.py
> +++ b/utilities/gdb/ovs_gdb.py
> @@ -413,6 +413,39 @@ class ForEachLIST():
>          return self.__next__()
>  
>  
> +#
> +# 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
>  #
> @@ -1233,6 +1266,46 @@ class CmdShowUpcall(gdb.Command):
>              self.display_udpif_upcall(udpif, 0, "dbg" in arg_list)
>  
>  
> +#
> +# 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
>  #
> @@ -1244,6 +1317,7 @@ CmdDumpDpNetdevPorts()
>  CmdDumpDpProvider()
>  CmdDumpNetdev()
>  CmdDumpNetdevProvider()
> +CmdDumpOfpacts()
>  CmdDumpOvsList()
>  CmdDumpSimap()
>  CmdDumpSmap()
> -- 
> 2.24.0
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Eelco Chaudron April 20, 2020, 8:02 a.m. UTC | #2
On 19 Apr 2020, at 17:58, William Tu wrote:

> On Fri, Apr 17, 2020 at 02:51:34PM +0200, Eelco Chaudron wrote:
>> 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}
>>
>> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
>> ---
> Hi Eelco,
>
> I'm trying to test this patch. But I hit another problem.
> Can you help me with the issue? Sorry this is not related to your 
> patch.
>
> root@osboxes:~/ovs# gdb $(which ovs-vswitchd) $(pidof ovs-vswitchd)
> GNU gdb (GDB) 8.0.50.20170501-git
> Copyright (C) 2017 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later 
> <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show 
> copying"
> and "show warranty" for details.
> This GDB was configured as "x86_64-pc-linux-gnu".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
> <http://www.gnu.org/software/gdb/documentation/>.
> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from /usr/local/sbin/ovs-vswitchd...done.
> Attaching to program: /usr/local/sbin/ovs-vswitchd, process 58469
> [New LWP 58473]
> [New LWP 58474]
> [New LWP 58475]
> [New LWP 58484]
> [New LWP 58485]
> [New LWP 58486]
> [New LWP 58487]
> [New LWP 58578]
> [New LWP 58579]
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library 
> "/lib/x86_64-linux-gnu/libthread_db.so.1".
> 0x00007fe63d33774d in poll () from /lib/x86_64-linux-gnu/libc.so.6
> (gdb) source ./utilities/gdb/ovs_gdb.py
>   File "./utilities/gdb/ovs_gdb.py", line 164
>     print(self.message, end='')

The script should work with both versions of python. Is the above the 
only error you get? Or did you forget to cut/paste the actual error 
message?

> Is this due to python2/3? My python version:
> boxes:~/ovs# python
> Python 3.5.2 (default, Oct  8 2019, 13:06:37)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
William Tu April 20, 2020, 1:06 p.m. UTC | #3
On Mon, Apr 20, 2020 at 10:02:15AM +0200, Eelco Chaudron wrote:
> 
> 
> On 19 Apr 2020, at 17:58, William Tu wrote:
> 
> >On Fri, Apr 17, 2020 at 02:51:34PM +0200, Eelco Chaudron wrote:
> >>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}
> >>
> >>Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> >>---
> >Hi Eelco,
> >
> >I'm trying to test this patch. But I hit another problem.
> >Can you help me with the issue? Sorry this is not related to your patch.
> >
> >root@osboxes:~/ovs# gdb $(which ovs-vswitchd) $(pidof ovs-vswitchd)
> >GNU gdb (GDB) 8.0.50.20170501-git
> >Copyright (C) 2017 Free Software Foundation, Inc.
> >License GPLv3+: GNU GPL version 3 or later
> ><http://gnu.org/licenses/gpl.html>
> >This is free software: you are free to change and redistribute it.
> >There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> >and "show warranty" for details.
> >This GDB was configured as "x86_64-pc-linux-gnu".
> >Type "show configuration" for configuration details.
> >For bug reporting instructions, please see:
> ><http://www.gnu.org/software/gdb/bugs/>.
> >Find the GDB manual and other documentation resources online at:
> ><http://www.gnu.org/software/gdb/documentation/>.
> >For help, type "help".
> >Type "apropos word" to search for commands related to "word"...
> >Reading symbols from /usr/local/sbin/ovs-vswitchd...done.
> >Attaching to program: /usr/local/sbin/ovs-vswitchd, process 58469
> >[New LWP 58473]
> >[New LWP 58474]
> >[New LWP 58475]
> >[New LWP 58484]
> >[New LWP 58485]
> >[New LWP 58486]
> >[New LWP 58487]
> >[New LWP 58578]
> >[New LWP 58579]
> >[Thread debugging using libthread_db enabled]
> >Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
> >0x00007fe63d33774d in poll () from /lib/x86_64-linux-gnu/libc.so.6
> >(gdb) source ./utilities/gdb/ovs_gdb.py
> >  File "./utilities/gdb/ovs_gdb.py", line 164
> >    print(self.message, end='')
> 
> The script should work with both versions of python. Is the above the only
> error you get? Or did you forget to cut/paste the actual error message?

> 
> >Is this due to python2/3? My python version:
> >boxes:~/ovs# python
> >Python 3.5.2 (default, Oct  8 2019, 13:06:37)
> >[GCC 5.4.0 20160609] on linux
> >Type "help", "copyright", "credits" or "license" for more information.
> 
Hi Eelco,
That's the only error I got

(gdb) source ./utilities/gdb/ovs_gdb.py
  File "./utilities/gdb/ovs_gdb.py", line 164
    print(self.message, end='')
                           ^
SyntaxError: invalid syntax
(gdb)
Eelco Chaudron April 20, 2020, 1:27 p.m. UTC | #4
On 20 Apr 2020, at 15:06, William Tu wrote:

<SNIP>
>>> Is this due to python2/3? My python version:
>>> boxes:~/ovs# python
>>> Python 3.5.2 (default, Oct  8 2019, 13:06:37)
>>> [GCC 5.4.0 20160609] on linux
>>> Type "help", "copyright", "credits" or "license" for more 
>>> information.
>>
> Hi Eelco,
> That's the only error I got
>
> (gdb) source ./utilities/gdb/ovs_gdb.py
>   File "./utilities/gdb/ovs_gdb.py", line 164
>     print(self.message, end='')
>                            ^
> SyntaxError: invalid syntax

Looks like the end=‘’ option is only supported in later version of 
3.x.
I’ll try to find a way to make this work for all version of Python and 
sent a patch later this week/early next week.

//Eelco
Eelco Chaudron April 20, 2020, 1:37 p.m. UTC | #5
William,

Can you try adding this somewhere at the top after the other import 
section?

from __future__ import print_function

And let me know if it works?

Thanks,

Eelco


On 20 Apr 2020, at 15:27, Eelco Chaudron wrote:

> On 20 Apr 2020, at 15:06, William Tu wrote:
>
> <SNIP>
>>>> Is this due to python2/3? My python version:
>>>> boxes:~/ovs# python
>>>> Python 3.5.2 (default, Oct  8 2019, 13:06:37)
>>>> [GCC 5.4.0 20160609] on linux
>>>> Type "help", "copyright", "credits" or "license" for more 
>>>> information.
>>>
>> Hi Eelco,
>> That's the only error I got
>>
>> (gdb) source ./utilities/gdb/ovs_gdb.py
>>   File "./utilities/gdb/ovs_gdb.py", line 164
>>     print(self.message, end='')
>>                            ^
>> SyntaxError: invalid syntax
>
> Looks like the end=‘’ option is only supported in later version of 
> 3.x.
> I’ll try to find a way to make this work for all version of Python 
> and sent a patch later this week/early next week.
>
> //Eelco
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
William Tu April 20, 2020, 3:57 p.m. UTC | #6
On Mon, Apr 20, 2020 at 03:37:03PM +0200, Eelco Chaudron wrote:
> William,
> 
> Can you try adding this somewhere at the top after the other import section?
> 
> from __future__ import print_function
> 
> And let me know if it works?
> 
> Thanks,
> 
> Eelco

Hi Eelco,

Thanks, it work, but I have to put it "before" other import

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index befc2b4a4b45..3a23df452816 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -55,11 +55,14 @@
 #    ...
 #    ...
 #
+
+from __future__ import print_function
 import gdb
 import sys
 import uuid


Putting it after import below has the issue

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f57c81f774d in poll () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) source utilities/gdb/ovs_gdb.py 
  File "utilities/gdb/ovs_gdb.py", line 62
    from __future__ import print_function
SyntaxError: from __future__ imports must occur at the beginning of the file
(gdb) 


William

> 
> 
> On 20 Apr 2020, at 15:27, Eelco Chaudron wrote:
> 
> >On 20 Apr 2020, at 15:06, William Tu wrote:
> >
> ><SNIP>
> >>>>Is this due to python2/3? My python version:
> >>>>boxes:~/ovs# python
> >>>>Python 3.5.2 (default, Oct  8 2019, 13:06:37)
> >>>>[GCC 5.4.0 20160609] on linux
> >>>>Type "help", "copyright", "credits" or "license" for more
> >>>>information.
> >>>
> >>Hi Eelco,
> >>That's the only error I got
> >>
> >>(gdb) source ./utilities/gdb/ovs_gdb.py
> >>  File "./utilities/gdb/ovs_gdb.py", line 164
> >>    print(self.message, end='')
> >>                           ^
> >>SyntaxError: invalid syntax
> >
> >Looks like the end=‘’ option is only supported in later version of 3.x.
> >I’ll try to find a way to make this work for all version of Python and
> >sent a patch later this week/early next week.
> >
> >//Eelco
> >
> >_______________________________________________
> >dev mailing list
> >dev@openvswitch.org
> >https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Eelco Chaudron April 21, 2020, 11:42 a.m. UTC | #7
On 20 Apr 2020, at 17:57, William Tu wrote:

> On Mon, Apr 20, 2020 at 03:37:03PM +0200, Eelco Chaudron wrote:
>> William,
>>
>> Can you try adding this somewhere at the top after the other import 
>> section?
>>
>> from __future__ import print_function
>>
>> And let me know if it works?
>>
>> Thanks,
>>
>> Eelco
>
> Hi Eelco,
>
> Thanks, it work, but I have to put it "before" other import
>
> diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
> index befc2b4a4b45..3a23df452816 100644
> --- a/utilities/gdb/ovs_gdb.py
> +++ b/utilities/gdb/ovs_gdb.py
> @@ -55,11 +55,14 @@
>  #    ...
>  #    ...
>  #
> +
> +from __future__ import print_function
>  import gdb
>  import sys
>  import uuid
>
>
> Putting it after import below has the issue
>
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library 
> "/lib/x86_64-linux-gnu/libthread_db.so.1".
> 0x00007f57c81f774d in poll () from /lib/x86_64-linux-gnu/libc.so.6
> (gdb) source utilities/gdb/ovs_gdb.py
>   File "utilities/gdb/ovs_gdb.py", line 62
>     from __future__ import print_function
> SyntaxError: from __future__ imports must occur at the beginning of 
> the file
> (gdb)
>

Yes the __future__ should be at the top, thanks for testing. I did some 
more testing on older and newer versions of Python and sent out a patch.

Cheers,

Eelco
William Tu April 25, 2020, 3:11 p.m. UTC | #8
On Fri, Apr 17, 2020 at 02:51:34PM +0200, Eelco Chaudron wrote:
> 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}
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
Applied to master, thanks!
William
diff mbox series

Patch

diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py
index befc2b4a4..0b2ecb81b 100644
--- a/utilities/gdb/ovs_gdb.py
+++ b/utilities/gdb/ovs_gdb.py
@@ -413,6 +413,39 @@  class ForEachLIST():
         return self.__next__()
 
 
+#
+# 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
 #
@@ -1233,6 +1266,46 @@  class CmdShowUpcall(gdb.Command):
             self.display_udpif_upcall(udpif, 0, "dbg" in arg_list)
 
 
+#
+# 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
 #
@@ -1244,6 +1317,7 @@  CmdDumpDpNetdevPorts()
 CmdDumpDpProvider()
 CmdDumpNetdev()
 CmdDumpNetdevProvider()
+CmdDumpOfpacts()
 CmdDumpOvsList()
 CmdDumpSimap()
 CmdDumpSmap()