How is "%p"
implemented in bpf_trace_printk
? It seems very different with printf
.
#include <uapi/linux/ptrace.h>
int print_args(struct pt_regs *ctx) {
void *ptr = (void*)PT_REGS_PARM1(ctx);
bpf_trace_printk("args: %lx %p %ld\n", ptr, ptr, ptr);
return 0;
}
I use this eBPF program to trace argument to one function. The parameter's type is a pointer to some struct.
One output is:
args: 7ffde047d6c4 00000000ec7e9023 140728366257860
We can notice that the output of "%p"
is very strange.
If we use a standard C program to check the output:
#include <stdio.h>
int main() {
void *ptr = (void*)0x7ffde047d6c4;
printf("args: %lx %p %ld\n", ptr, ptr, ptr);
return 0;
}
We will get: args: 7ffde047d6c4 0x7ffde047d6c4 140728366257860