bpftrace icon indicating copy to clipboard operation
bpftrace copied to clipboard

If uprobe coude parse global variable that initialized but not used in the subsequent code

Open Jacob-jiangbo opened this issue 1 year ago • 2 comments

What reproduces the bug? Provide code if possible.

Analyzing uprobe_test.c, found that in the command, corresponding GLOBAL_A and GLOBAL_C were not actually called in the subsequent code and this command can't parse gloable variable that not used.

usr/bin/bpftrace -e 'uprobe:testprogs/uprobe_test:function1 { printf("0x%lx -- 0x%lx\n", *uaddr("GLOBAL_A"), *uaddr("GLOBAL_C")); exit(); }' -c ./testprogs/uprobe_test Attaching 1 probe... 0x0 -- 0x0

I made slight modifications to the original program so that it can be introduced in the actual operation. Then we executed the corresponding program to obtain the corresponding value, which can be obtained normally. image

/usr/bin/bpftrace -e 'uprobe:testprogs/uprobe_test:function1 { printf("0x%lx\n", *uaddr("GLOBAL_A")); exit(); }' -c ./testprogs/uprobe_test image

Want to ask, if the global variable is initialized but not used in the subsequent code, can uprobe not be queried? Is there any corresponding optimization here?

Jacob-jiangbo avatar Jun 13 '24 02:06 Jacob-jiangbo

Can't seem to reproduce this on my machine. Without uprobe_test.c changes:

$ sudo ./build/src/bpftrace -e 'uprobe:./build/tests/testprogs/uprobe_test:uprobeFunction2 { printf("0x%x\n", *uaddr("GLOBAL_A")) }' -c ./build/tests/testprogs/uprobe_test
Attaching 1 probe...
0x55555555

danobi avatar Jun 13 '24 19:06 danobi

Through repeated tests, it was found that global variables were initialized but not used and could not be parsed. This was a problem with the link option pie.

The tests were as follows: Compile with pie, can't be parsed. image

Compile without pie, parse ok. image

If bpftrace project have plans to fix this problem? That is, global variables are initialized but not used, but can still be parsed when the link option is pie?

Jacob-jiangbo avatar Jun 14 '24 06:06 Jacob-jiangbo