If uprobe coude parse global variable that initialized but not used in the subsequent code
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.
/usr/bin/bpftrace -e 'uprobe:testprogs/uprobe_test:function1 { printf("0x%lx\n", *uaddr("GLOBAL_A")); exit(); }' -c ./testprogs/uprobe_test
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?
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
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.
Compile without pie, parse ok.
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?