Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gadgets/run: Print string representation of enums #2257

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

eiffel-fl
Copy link
Member

Hi.

This PR prints the string representation of enums.
Note that, it works only on named enum.

You can test it with the following patch:

diff --git a/gadgets/snapshot_socket/program.bpf.c b/gadgets/snapshot_socket/program.bpf.c
index cf790793..99ab7af9 100644
--- a/gadgets/snapshot_socket/program.bpf.c
+++ b/gadgets/snapshot_socket/program.bpf.c
@@ -49,7 +49,7 @@
 struct socket_entry {
        struct gadget_l4endpoint_t src;
        struct gadget_l4endpoint_t dst;
-       __u32 state;
+       enum tcp_conntrack state;
        __u32 ino;
 };
$ sudo -E ./ig run sockets -o columns=state,state_raw        francis/enum-string *% u=
INFO[0000] Experimental features enabled                
STATE                                                                STATE_RAW                                                           
TCP_CONNTRACK_TIME_WAIT                                              7                                                                   
TCP_CONNTRACK_TIME_WAIT                                              7                                                                   
TCP_CONNTRACK_MAX                                                    10                                                                  
TCP_CONNTRACK_MAX                                                    10                                                                  
TCP_CONNTRACK_MAX                                                    10                                                                  
TCP_CONNTRACK_MAX                                                    10

Best regards.

pkg/gadgets/run/tracer/run.go Outdated Show resolved Hide resolved
pkg/gadgets/run/tracer/run.go Outdated Show resolved Hide resolved
Print the string representation of enums.

Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for working on this.

@eiffel-fl eiffel-fl merged commit 40ba0b8 into main Dec 6, 2023
50 checks passed
@eiffel-fl eiffel-fl deleted the francis/enum-string branch December 6, 2023 09:16
@eiffel-fl
Copy link
Member Author

Thank you for the initial code and the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants