uprobe_example.c 531 B

12345678910111213141516171819202122232425
  1. #include "common.h"
  2. #include "bpf_helpers.h"
  3. char __license[] SEC("license") = "Dual MIT/GPL";
  4. struct event_t {
  5. u32 pid;
  6. char str[80];
  7. };
  8. struct {
  9. __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
  10. } events SEC(".maps");
  11. SEC("uprobe/bash_readline")
  12. int uprobe_bash_readline(struct pt_regs *ctx) {
  13. struct event_t event;
  14. event.pid = bpf_get_current_pid_tgid();
  15. bpf_probe_read(&event.str, sizeof(event.str), (void *)PT_REGS_RC(ctx));
  16. bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &event, sizeof(event));
  17. return 0;
  18. }