uprobetracer.txt 4.2 KB

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