mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-04 23:59:07 +08:00
libbpf: Support function name-based attach uprobes
kprobe attach is name-based, using lookups of kallsyms to translate a function name to an address. Currently uprobe attach is done via an offset value as described in [1]. Extend uprobe opts for attach to include a function name which can then be converted into a uprobe-friendly offset. The calcualation is done in several steps: 1. First, determine the symbol address using libelf; this gives us the offset as reported by objdump 2. If the function is a shared library function - and the binary provided is a shared library - no further work is required; the address found is the required address 3. Finally, if the function is local, subtract the base address associated with the object, retrieved from ELF program headers. The resultant value is then added to the func_offset value passed in to specify the uprobe attach address. So specifying a func_offset of 0 along with a function name "printf" will attach to printf entry. The modes of operation supported are then 1. to attach to a local function in a binary; function "foo1" in "/usr/bin/foo" 2. to attach to a shared library function in a shared library - function "malloc" in libc. [1] https://www.kernel.org/doc/html/latest/trace/uprobetracer.html Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/1648654000-21758-3-git-send-email-alan.maguire@oracle.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
4a7fa5b2bc
commit
d112c9ce24
10
src/libbpf.h
10
src/libbpf.h
@@ -459,9 +459,17 @@ struct bpf_uprobe_opts {
|
||||
__u64 bpf_cookie;
|
||||
/* uprobe is return probe, invoked at function return time */
|
||||
bool retprobe;
|
||||
/* Function name to attach to. Could be an unqualified ("abc") or library-qualified
|
||||
* "abc@LIBXYZ" name. To specify function entry, func_name should be set while
|
||||
* func_offset argument to bpf_prog__attach_uprobe_opts() should be 0. To trace an
|
||||
* offset within a function, specify func_name and use func_offset argument to specify
|
||||
* offset within the function. Shared library functions must specify the shared library
|
||||
* binary_path.
|
||||
*/
|
||||
const char *func_name;
|
||||
size_t :0;
|
||||
};
|
||||
#define bpf_uprobe_opts__last_field retprobe
|
||||
#define bpf_uprobe_opts__last_field func_name
|
||||
|
||||
/**
|
||||
* @brief **bpf_program__attach_uprobe()** attaches a BPF program
|
||||
|
||||
Reference in New Issue
Block a user