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

strings in predicates failures #198

Closed
brendangregg opened this issue Oct 18, 2018 · 9 comments
Closed

strings in predicates failures #198

brendangregg opened this issue Oct 18, 2018 · 9 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@brendangregg
Copy link
Contributor

There's two invocations here that fail differently, but I think one bug may be responsible.

To start with, this works:

# bpftrace -e 'tracepoint:syscalls:sys_enter_write /pid == 23506/ { printf("hi\n"); }'
Attaching 1 probe...
hi
hi
hi

That's the PID of a bash shell. Matching on the process name, and including -v:

# bpftrace -v -e 'tracepoint:syscalls:sys_enter_write /comm == "bash"/ { printf("hi\n"); }'
Attaching 1 probe...

Error log: 
0: (bf) r6 = r1
1: (b7) r1 = 0
2: (7b) *(u64 *)(r10 -16) = r1
3: (7b) *(u64 *)(r10 -24) = r1
4: (bf) r7 = r10
5: (07) r7 += -24
6: (bf) r1 = r7
7: (b7) r2 = 16
8: (85) call bpf_get_current_comm#16
9: (bf) r1 = r10
10: (07) r1 += -5
11: (b7) r2 = 8
12: (bf) r3 = r7
13: (85) call bpf_probe_read#4
invalid stack type R1 off=-5 access_size=8

Error loading program: tracepoint:syscalls:sys_enter_write

Ok, looks like an alignment issue of the "bash" string.

Now changing the action performed:

# bpftrace -e 'tracepoint:syscalls:sys_enter_write /comm == "bash"/ { printf("%d\n", 123); }'
Attaching 1 probe...
^C

This time it compiles, but no events fire.

@brendangregg brendangregg added the bug Something isn't working label Oct 18, 2018
@mmarchini
Copy link
Contributor

The problem doesn't seem to be restricted to predicates, using if (comm == "bash") doesn't work as well.

@danobi
Copy link
Member

danobi commented Dec 21, 2018

I'm hitting this as well. Another test case (because more is always better):

$ sudo ./build/src/bpftrace -e 'tracepoint:syscalls:sys_enter_read /comm == "a.out"/ { printf("hit\n") }'                                                                                   
chdir(/lib/modules/4.18.9-200.fc28.x86_64/build): No such file or directory
definitions.h:9:3: error: unknown type name 'u64'
definitions.h:11:3: error: unknown type name 'size_t'
Attaching 1 probe...
Error loading program: tracepoint:syscalls:sys_enter_read (try -v)

$ sudo ./build/src/bpftrace -e 'tracepoint:syscalls:sys_enter_read /comm == "a.out"/ { printf("hit %d\n", args->fd) }'
chdir(/lib/modules/4.18.9-200.fc28.x86_64/build): No such file or directory
definitions.h:9:3: error: unknown type name 'u64'
definitions.h:11:3: error: unknown type name 'size_t'
Attaching 1 probe...
^C

@danobi
Copy link
Member

danobi commented Jan 2, 2019

Super annoying bug, working on this now.

@danobi danobi self-assigned this Jan 2, 2019
@mmarchini mmarchini added this to the 1.0 milestone Jan 14, 2019
@brendangregg brendangregg modified the milestones: 1.0, 0.9 Jan 16, 2019
@williangaspar
Copy link
Contributor

@danobi, do you still working on this?

@danobi
Copy link
Member

danobi commented Jan 28, 2019

@williangaspar it's still on my todo list. Feel free to take it from me if you want

@tyroguru
Copy link
Contributor

tyroguru commented Feb 6, 2019

Yes, this is super annoying so a fix would be good to see soon. We do need more than this though for pattern matching in a predicate. I often need to do the equivalent of 't:syscall:whatever/comm == "hhvm*" as I am interested in a range of processes whose name begins with "hhvm". In DTrace you could do something like /strstr(execname, "hhvm") != NULL/ if my memory serves me right.

@williangaspar
Copy link
Contributor

By the error message, it seems comm is trying to do a jump too far.

@williangaspar williangaspar self-assigned this Feb 7, 2019
@mmarchini
Copy link
Contributor

@tyroguru this seems like a useful feature. Do you mind opening another issue for it?

williangaspar added a commit that referenced this issue Feb 8, 2019
navytux pushed a commit to navytux/bpftrace that referenced this issue Feb 8, 2019
navytux pushed a commit to navytux/bpftrace that referenced this issue Feb 8, 2019
@danobi
Copy link
Member

danobi commented Feb 11, 2019

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants