add debug info module

This commit is contained in:
2025-09-30 14:29:20 +05:30
parent 26f8f769c5
commit eb73001063
8 changed files with 67 additions and 52 deletions

View File

@ -2,38 +2,39 @@
#include <bpf/bpf_helpers.h>
#define u64 unsigned long long
#define u32 unsigned int
// Define the map
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u64);
__type(value, u64);
__type(value, u32);
__uint(max_entries, 4);
} last SEC(".maps");
// Handler for syscall entry
SEC("tracepoint/syscalls/sys_enter_execve")
int hello(void *ctx) {
bpf_printk("entered");
bpf_printk("multi constant support");
return 0;
}
// // Handler for syscall entry
// SEC("tracepoint/syscalls/sys_enter_execve")
// int hello(void *ctx) {
// bpf_printk("entered");
// bpf_printk("multi constant support");
// return 0;
// }
// Handler for syscall exit
SEC("tracepoint/syscalls/sys_exit_execve")
long hello_again(void *ctx) {
bpf_printk("exited");
// // Handler for syscall exit
// SEC("tracepoint/syscalls/sys_exit_execve")
// long hello_again(void *ctx) {
// bpf_printk("exited");
// Create a key for map lookup
u64 key = 0;
// // Create a key for map lookup
// u64 key = 0;
// Simple lookup without conditionals
u64 *tsp = bpf_map_lookup_elem(&last, &key);
// // Simple lookup without conditionals
// u64 *tsp = bpf_map_lookup_elem(&last, &key);
// Get current timestamp
u64 ts = bpf_ktime_get_ns();
// // Get current timestamp
// u64 ts = bpf_ktime_get_ns();
return 0;
}
// return 0;
// }
char LICENSE[] SEC("license") = "GPL";

View File

@ -1,4 +1,4 @@
from pythonbpf.decorators import bpf, map, section, bpfglobal
from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir
from ctypes import c_void_p, c_int64, c_int32, c_uint64
from pythonbpf.helpers import ktime
from pythonbpf.maps import HashMap
@ -10,26 +10,28 @@ def last() -> HashMap:
return HashMap(key=c_uint64, value=c_uint64, max_entries=1)
@bpf
@section("tracepoint/syscalls/sys_enter_execve")
def hello(ctx: c_void_p) -> c_int32:
print("entered")
print("multi constant support")
return c_int32(0)
# @bpf
# @section("tracepoint/syscalls/sys_enter_execve")
# def hello(ctx: c_void_p) -> c_int32:
# print("entered")
# print("multi constant support")
# return c_int32(0)
@bpf
@section("tracepoint/syscalls/sys_exit_execve")
def hello_again(ctx: c_void_p) -> c_int64:
print("exited")
key = 0
tsp = last().lookup(key)
print(tsp)
ts = ktime()
return c_int64(0)
# @bpf
# @section("tracepoint/syscalls/sys_exit_execve")
# def hello_again(ctx: c_void_p) -> c_int64:
# print("exited")
# key = 0
# tsp = last().lookup(key)
# print(tsp)
# ts = ktime()
# return c_int64(0)
@bpf
@bpfglobal
def LICENSE() -> str:
return "GPL"
compile_to_ir("execve2.py", "execve2.ll")