1 Uprobe-tracer: Uprobe-based Event Tracing
2 =========================================
3 Documentation written by Srikar Dronamraju
7 Uprobe based trace events are similar to kprobe based trace events.
8 To enable this feature, build your kernel with CONFIG_UPROBE_EVENT=y.
10 Similar to the kprobe-event tracer, this doesn't need to be activated via
11 current_tracer. Instead of that, add probe points via
12 /sys/kernel/debug/tracing/uprobe_events, and enable it via
13 /sys/kernel/debug/tracing/events/uprobes/<EVENT>/enabled.
15 However unlike kprobe-event tracer, the uprobe event interface expects the
16 user to calculate the offset of the probepoint in the object
18 Synopsis of uprobe_tracer
19 -------------------------
20 p[:[GRP/]EVENT] PATH:SYMBOL[+offs] [FETCHARGS] : Set a probe
22 GRP : Group name. If omitted, use "uprobes" for it.
23 EVENT : Event name. If omitted, the event name is generated
25 PATH : path to an executable or a library.
26 SYMBOL[+offs] : Symbol+offset where the probe is inserted.
28 FETCHARGS : Arguments. Each probe can have up to 128 args.
29 %REG : Fetch register REG
33 You can check the total number of probe hits and probe miss-hits via
34 /sys/kernel/debug/tracing/uprobe_profile.
35 The first column is event name, the second is the number of probe hits,
36 the third is the number of probe miss-hits.
40 To add a probe as a new event, write a new definition to uprobe_events
43 echo 'p: /bin/bash:0x4245c0' > /sys/kernel/debug/tracing/uprobe_events
45 This sets a uprobe at an offset of 0x4245c0 in the executable /bin/bash
47 echo > /sys/kernel/debug/tracing/uprobe_events
49 This clears all probe points.
51 The following example shows how to dump the instruction pointer and %ax
52 a register at the probed text address. Here we are trying to probe
53 function zfree in /bin/zsh
55 # cd /sys/kernel/debug/tracing/
56 # cat /proc/`pgrep zsh`/maps | grep /bin/zsh | grep r-xp
57 00400000-0048a000 r-xp 00000000 08:03 130904 /bin/zsh
58 # objdump -T /bin/zsh | grep -w zfree
59 0000000000446420 g DF .text 0000000000000012 Base zfree
61 0x46420 is the offset of zfree in object /bin/zsh that is loaded at
62 0x00400000. Hence the command to probe would be :
64 # echo 'p /bin/zsh:0x46420 %ip %ax' > uprobe_events
66 Please note: User has to explicitly calculate the offset of the probepoint
67 in the object. We can see the events that are registered by looking at the
71 p:uprobes/p_zsh_0x46420 /bin/zsh:0x00046420 arg1=%ip arg2=%ax
73 The format of events can be seen by viewing the file events/uprobes/p_zsh_0x46420/format
75 # cat events/uprobes/p_zsh_0x46420/format
79 field:unsigned short common_type; offset:0; size:2; signed:0;
80 field:unsigned char common_flags; offset:2; size:1; signed:0;
81 field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
82 field:int common_pid; offset:4; size:4; signed:1;
83 field:int common_padding; offset:8; size:4; signed:1;
85 field:unsigned long __probe_ip; offset:12; size:4; signed:0;
86 field:u32 arg1; offset:16; size:4; signed:0;
87 field:u32 arg2; offset:20; size:4; signed:0;
89 print fmt: "(%lx) arg1=%lx arg2=%lx", REC->__probe_ip, REC->arg1, REC->arg2
91 Right after definition, each event is disabled by default. For tracing these
92 events, you need to enable it by:
94 # echo 1 > events/uprobes/enable
96 Lets disable the event after sleeping for some time.
98 # echo 0 > events/uprobes/enable
100 And you can see the traced information via /sys/kernel/debug/tracing/trace.
105 # TASK-PID CPU# TIMESTAMP FUNCTION
107 zsh-24842 [006] 258544.995456: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
108 zsh-24842 [007] 258545.000270: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
109 zsh-24842 [002] 258545.043929: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
110 zsh-24842 [004] 258547.046129: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
112 Each line shows us probes were triggered for a pid 24842 with ip being
113 0x446421 and contents of ax register being 79.